Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added full list of media files (and associated data) from the HEADER section #39

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions speach/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
__issue__ = "https://github.com/neocl/speach/issues/"
__maintainer__ = "Le Tuan Anh"
__version_major__ = "0.1" # follow PEP-0440
__version__ = "{}a15.post1".format(__version_major__)
__version_long__ = "{} - Alpha 15.post1".format(__version_major__)
__version__ = "{}a15.post1+geintra".format(__version_major__)
__version_long__ = "{} - Alpha 15.post1+geintra".format(__version_major__)
__status__ = "3 - Alpha"
30 changes: 30 additions & 0 deletions speach/elan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ class Doc(DataObject):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.properties = OrderedDict()
self.media_descriptors = [] # JMG added this
self.time_order = OrderedDict()
self.__tiers = []
self.__tier_map = OrderedDict() # internal - map tierIDs to tier objects
Expand Down Expand Up @@ -1523,31 +1524,56 @@ def time_units(self, value):

@property
def media_url(self):
# TODO JMG: Generalize this to allow for multiple media descriptors
print(f'Use of @property media_url is deprecated as there may be more than one in a general ELAN file.') # JMG added this
return self._xml_media_node.get('MEDIA_URL')

@media_url.setter
def media_url(self, value):
# TODO: what if __xml_header_node is None?
# TODO JMG: Generalize this to allow for multiple media descriptors
print(f'Use of @media_url.setter is deprecated as there may be more than one in a general ELAN file.') # JMG added this
self._xml_media_node.set('MEDIA_URL', value)

@property
def mime_type(self):
# TODO JMG: Generalize this to allow for multiple media descriptors
print(f'Use of @property mime_type is deprecated as there may be more than one in a general ELAN file.') # JMG added this
return self._xml_media_node.get('MIME_TYPE')

@mime_type.setter
def mime_type(self, value):
# TODO: what if __xml_header_node is None?
# TODO JMG: Generalize this to allow for multiple media descriptors
print(f'Use of @media_type.setter is deprecated as there may be more than one in a general ELAN file.') # JMG added this
self._xml_media_node.set('MIME_TYPE', value)

@property
def relative_media_url(self):
# TODO JMG: Generalize this to allow for multiple media descriptors
print(f'Use of @property relative_media_url is deprecated as there may be more than one in a general ELAN file.') # JMG added this
return self._xml_media_node.get('RELATIVE_MEDIA_URL')

@relative_media_url.setter
def relative_media_url(self, value):
# TODO: what if __xml_header_node is None?
# TODO JMG: Generalize this to allow for multiple media descriptors
print(f'Use of @relative_media_url.setter is deprecated as there may be more than one in a general ELAN file.') # JMG added this
self._xml_media_node.set('RELATIVE_MEDIA_URL', value)

@property
def time_origin(self):
# TODO JMG: Generalize this to allow for multiple media descriptors
print(f'Use of @property time_origin is deprecated as there may be more than one in a general ELAN file.') # JMG added this
return self._xml_media_node.get('TIME_ORIGIN')

@time_origin.setter
def time_origin(self, value):
# TODO: what if __xml_header_node is None?
# TODO JMG: Generalize this to allow for multiple media descriptors
print(f'Use of @time_origin.setter is deprecated as there may be more than one in a general ELAN file.') # JMG added this
self._xml_media_node.set('TIME_ORIGIN', value)

def _update_header_xml(self, node):
""" [Internal function] Read ELAN doc information from a HEADER XML node

Expand All @@ -1557,6 +1583,8 @@ def _update_header_xml(self, node):
# extract extra properties
for prop_node in node.findall('PROPERTY'):
self.properties[prop_node.get('NAME')] = prop_node.text
for media_node in node.findall('MEDIA_DESCRIPTOR'):
self.media_descriptors.append(media_node.attrib)

def _add_tier_xml(self, tier_node) -> Tier:
""" [Internal function] Parse a TIER XML node, create an ELANTier object and link it to this ELAN Doc
Expand Down Expand Up @@ -1834,6 +1862,7 @@ def read_eaf(cls, eaf_path, encoding='utf-8', *args, **kwargs):
def create(cls, media_file='audio.wav',
media_url=None,
relative_media_url=None,
time_origin=0,
author="",
*args, **kwargs):
""" Create a new blank ELAN doc
Expand All @@ -1854,6 +1883,7 @@ def create(cls, media_file='audio.wav',
eaf.media_file = media_file
eaf.media_url = media_url
eaf.relative_media_url = relative_media_url
eaf.time_origin = time_origin
eaf.date = datetime.now()
if author:
eaf.author = author
Expand Down