From 23fd0c452798700bcbbb366465699fb633d2073b Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 3 Dec 2012 10:49:33 +0100 Subject: [PATCH 01/16] create a setup, init README and MANIFEST --- MANIFEST.in | 5 +++++ README.rst | 6 ++++++ setup.py | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 MANIFEST.in create mode 100644 README.rst create mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..251f44f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include *.xml +global-exclude *.pyc +prune dist +prune build + diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..67b3b17 --- /dev/null +++ b/README.rst @@ -0,0 +1,6 @@ + +EBML (Extensible Binary Meta Language) library for Python + +TODO + + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d1b5718 --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +'''The setup and build script for the library.''' + +from setuptools import setup, find_packages + +setup( + name = "python-ebml", + url = "https://github.com/jspiros/python-ebml", + description = "EBML (Extensible Binary Meta Language) library for Python", + long_description = open('README.rst').read(), + author = "Joseph Spiros", + author_email = "joseph@josephspiros.com", + version = '0.1', + install_requires = [ + 'setuptools', + ], + platforms=['OS Independent'], + license='BSD', + packages = find_packages(), + namespace_packages=['ebml'], + package_data={'': ['*.xml']}, + include_package_data = True, + zip_safe = False, +) From 4f96253e8acb223ea2d6c4b48dd11d73a2ec2fc2 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 5 Dec 2012 09:45:19 +0100 Subject: [PATCH 02/16] add tools --- tools/get_info.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tools/get_info.py diff --git a/tools/get_info.py b/tools/get_info.py new file mode 100644 index 0000000..38b4ecc --- /dev/null +++ b/tools/get_info.py @@ -0,0 +1,53 @@ + +from ebml.schema import EBMLDocument, UnknownElement, CONTAINER, BINARY + + +def fill_video_info(element, offset, video_info): + if element.name == 'Duration': + video_info['duration'] = element.value + + if element.name == 'DisplayWidth': + video_info['width'] = element.value + + if element.name == 'DisplayHeight': + video_info['height'] = element.value + + if element.name == 'Cluster': + video_info['clusters'].append({'offset': offset}) + + if element.name == 'Timecode': + video_info['clusters'][-1]['timecode'] = element.value + + if element.type == CONTAINER: + for sub_el in element.value: + fill_video_info(sub_el, offset + element.head_size, video_info) + offset += sub_el.size + + +if __name__ == '__main__': + import sys + import json + import os + + mod_name, _, cls_name = 'ebml.schema.matroska.MatroskaDocument'.rpartition('.') + try: + doc_mod = __import__(mod_name, fromlist=[cls_name]) + doc_cls = getattr(doc_mod, cls_name) + except ImportError: + parser.error('unable to import module %s' % mod_name) + except AttributeError: + parser.error('unable to import class %s from %s' % (cls_name, mod_name)) + + video_info = {} + video_info['filename'] = sys.argv[1] + video_info['total_size'] = os.stat(sys.argv[1]).st_size + video_info['clusters'] = [] + + with open(sys.argv[1], 'rb') as stream: + doc = doc_cls(stream) + offset = 0 + for el in doc.roots: + fill_video_info(el, offset, video_info) + offset += el.size + + print json.dumps(video_info) From 312c9cb56d20806ac36e9ffde8d4bc4097ca492b Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 5 Dec 2012 09:45:55 +0100 Subject: [PATCH 03/16] update manifest --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 251f44f..3949540 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,4 +2,4 @@ include *.xml global-exclude *.pyc prune dist prune build - +recursive-include tools From 4e5f399d1a49a9aa7eebae05bc073f08285a9f60 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 5 Dec 2012 13:39:43 +0100 Subject: [PATCH 04/16] add tool for first cluster timecode --- tools/get_first_cluster_timecode.py | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tools/get_first_cluster_timecode.py diff --git a/tools/get_first_cluster_timecode.py b/tools/get_first_cluster_timecode.py new file mode 100644 index 0000000..9458458 --- /dev/null +++ b/tools/get_first_cluster_timecode.py @@ -0,0 +1,54 @@ + +from ebml.schema import EBMLDocument, UnknownElement, CONTAINER, BINARY + + +def fill_video_info(element, offset, video_info): + if element.name == 'Duration': + video_info['duration'] = element.value + + if element.name == 'DisplayWidth': + video_info['width'] = element.value + + if element.name == 'DisplayHeight': + video_info['height'] = element.value + + if element.name == 'Cluster': + video_info['clusters'].append({'offset': offset}) + + if element.name == 'Timecode': + video_info['clusters'][-1]['timecode'] = element.value + + if element.type == CONTAINER: + for sub_el in element.value: + fill_video_info(sub_el, offset + element.head_size, video_info) + offset += sub_el.size + + +if __name__ == '__main__': + import sys + import json + import os + + mod_name, _, cls_name = 'ebml.schema.matroska.MatroskaDocument'.rpartition('.') + try: + doc_mod = __import__(mod_name, fromlist=[cls_name]) + doc_cls = getattr(doc_mod, cls_name) + except ImportError: + parser.error('unable to import module %s' % mod_name) + except AttributeError: + parser.error('unable to import class %s from %s' % (cls_name, mod_name)) + + video_info = {} + video_info['filename'] = sys.argv[1] + video_info['total_size'] = os.stat(sys.argv[1]).st_size + video_info['clusters'] = [] + + with open(sys.argv[1], 'rb') as stream: + doc = doc_cls(stream) + offset = 0 + for el in doc.roots: + fill_video_info(el, offset, video_info) + offset += el.size + print offset + + print json.dumps(video_info) From 67a113871704d3bdba671fba404f043a7c9d1b84 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 6 Dec 2012 15:48:22 +0100 Subject: [PATCH 05/16] make a class for EBMLData, tweak to get first cluster timecode --- tools/get_first_cluster_timecode.py | 132 +++++++++++++++++----------- 1 file changed, 81 insertions(+), 51 deletions(-) diff --git a/tools/get_first_cluster_timecode.py b/tools/get_first_cluster_timecode.py index 9458458..ddcda73 100644 --- a/tools/get_first_cluster_timecode.py +++ b/tools/get_first_cluster_timecode.py @@ -1,54 +1,84 @@ from ebml.schema import EBMLDocument, UnknownElement, CONTAINER, BINARY - - -def fill_video_info(element, offset, video_info): - if element.name == 'Duration': - video_info['duration'] = element.value - - if element.name == 'DisplayWidth': - video_info['width'] = element.value - - if element.name == 'DisplayHeight': - video_info['height'] = element.value - - if element.name == 'Cluster': - video_info['clusters'].append({'offset': offset}) - - if element.name == 'Timecode': - video_info['clusters'][-1]['timecode'] = element.value - - if element.type == CONTAINER: - for sub_el in element.value: - fill_video_info(sub_el, offset + element.head_size, video_info) - offset += sub_el.size - - + +import sys +import json +import os +import datetime + +class EBMLData(object): + + def __init__(self, filename, max_count=-1): + self.mod_name, _, self.cls_name = 'ebml.schema.matroska.MatroskaDocument'.rpartition('.') + try: + self.doc_mod = __import__(self.mod_name, fromlist=[self.cls_name]) + self.doc_cls = getattr(self.doc_mod, self.cls_name) + except ImportError: + parser.error('unable to import module %s' % self.mod_name) + except AttributeError: + parser.error('unable to import class %s from %s' % (self.cls_name, self.mod_name)) + + + + self.video_info = {} + self.video_info['filename'] = filename + self.video_info['total_size'] = os.stat(filename).st_size + self.video_info['clusters'] = [] + + self.doc = self.doc_cls(open(filename, 'rb')) + + + def get_data(self): + offset = 0 + for el in self.doc.roots: + self.fill_video_info(el, offset, self.video_info) + offset += el.size + return self.video_info + + def get_full_info(self): + self.max_count = -1 + return self.get_data() + + def get_first_cluster_timecode(self): + self.max_count = 4 + data = self.get_data() + ms = data['clusters'][0]['timecode'] + time = datetime.timedelta(microseconds=ms*1000) + return str(time) + + + def fill_video_info(self, element, offset, video_info): + if element.name == 'Duration': + video_info['duration'] = element.value + + if element.name == 'DisplayWidth': + video_info['width'] = element.value + + if element.name == 'DisplayHeight': + video_info['height'] = element.value + + if element.name == 'Cluster': + video_info['clusters'].append({'offset': offset}) + + if element.name == 'Timecode': + video_info['clusters'][-1]['timecode'] = element.value + + if element.type == CONTAINER: + i = 0 + for sub_el in element.value: + self.fill_video_info(sub_el, offset + element.head_size, video_info) + offset += sub_el.size + if i == self.max_count: + break + i += 1 + + + if __name__ == '__main__': - import sys - import json - import os - - mod_name, _, cls_name = 'ebml.schema.matroska.MatroskaDocument'.rpartition('.') - try: - doc_mod = __import__(mod_name, fromlist=[cls_name]) - doc_cls = getattr(doc_mod, cls_name) - except ImportError: - parser.error('unable to import module %s' % mod_name) - except AttributeError: - parser.error('unable to import class %s from %s' % (cls_name, mod_name)) - - video_info = {} - video_info['filename'] = sys.argv[1] - video_info['total_size'] = os.stat(sys.argv[1]).st_size - video_info['clusters'] = [] - - with open(sys.argv[1], 'rb') as stream: - doc = doc_cls(stream) - offset = 0 - for el in doc.roots: - fill_video_info(el, offset, video_info) - offset += el.size - print offset - - print json.dumps(video_info) + ebml_obj = EBMLData(sys.argv[-1], max_count=4) + print ebml_obj.get_first_cluster_timecode() + + + + + From 0ddea807d6b41390f9aea133f7fa5ef8323af07e Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 6 Dec 2012 15:52:43 +0100 Subject: [PATCH 06/16] mv EBMLData to a module --- tools/get_first_cluster_timecode.py | 73 +---------------------------- 1 file changed, 1 insertion(+), 72 deletions(-) diff --git a/tools/get_first_cluster_timecode.py b/tools/get_first_cluster_timecode.py index ddcda73..1b882df 100644 --- a/tools/get_first_cluster_timecode.py +++ b/tools/get_first_cluster_timecode.py @@ -1,78 +1,7 @@ -from ebml.schema import EBMLDocument, UnknownElement, CONTAINER, BINARY +from ebml.utils.ebml_data import * import sys -import json -import os -import datetime - -class EBMLData(object): - - def __init__(self, filename, max_count=-1): - self.mod_name, _, self.cls_name = 'ebml.schema.matroska.MatroskaDocument'.rpartition('.') - try: - self.doc_mod = __import__(self.mod_name, fromlist=[self.cls_name]) - self.doc_cls = getattr(self.doc_mod, self.cls_name) - except ImportError: - parser.error('unable to import module %s' % self.mod_name) - except AttributeError: - parser.error('unable to import class %s from %s' % (self.cls_name, self.mod_name)) - - - - self.video_info = {} - self.video_info['filename'] = filename - self.video_info['total_size'] = os.stat(filename).st_size - self.video_info['clusters'] = [] - - self.doc = self.doc_cls(open(filename, 'rb')) - - - def get_data(self): - offset = 0 - for el in self.doc.roots: - self.fill_video_info(el, offset, self.video_info) - offset += el.size - return self.video_info - - def get_full_info(self): - self.max_count = -1 - return self.get_data() - - def get_first_cluster_timecode(self): - self.max_count = 4 - data = self.get_data() - ms = data['clusters'][0]['timecode'] - time = datetime.timedelta(microseconds=ms*1000) - return str(time) - - - def fill_video_info(self, element, offset, video_info): - if element.name == 'Duration': - video_info['duration'] = element.value - - if element.name == 'DisplayWidth': - video_info['width'] = element.value - - if element.name == 'DisplayHeight': - video_info['height'] = element.value - - if element.name == 'Cluster': - video_info['clusters'].append({'offset': offset}) - - if element.name == 'Timecode': - video_info['clusters'][-1]['timecode'] = element.value - - if element.type == CONTAINER: - i = 0 - for sub_el in element.value: - self.fill_video_info(sub_el, offset + element.head_size, video_info) - offset += sub_el.size - if i == self.max_count: - break - i += 1 - - if __name__ == '__main__': ebml_obj = EBMLData(sys.argv[-1], max_count=4) From c4f4f482c324b24ed631773e9e4f6fa622492ad6 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 6 Dec 2012 15:55:41 +0100 Subject: [PATCH 07/16] add module --- ebml/utils/ebml_data.py | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 ebml/utils/ebml_data.py diff --git a/ebml/utils/ebml_data.py b/ebml/utils/ebml_data.py new file mode 100644 index 0000000..4a4063b --- /dev/null +++ b/ebml/utils/ebml_data.py @@ -0,0 +1,74 @@ + +from ebml.schema import EBMLDocument, UnknownElement, CONTAINER, BINARY + +import json +import os +import datetime + +class EBMLData(object): + + def __init__(self, filename, max_count=-1): + self.mod_name, _, self.cls_name = 'ebml.schema.matroska.MatroskaDocument'.rpartition('.') + try: + self.doc_mod = __import__(self.mod_name, fromlist=[self.cls_name]) + self.doc_cls = getattr(self.doc_mod, self.cls_name) + except ImportError: + parser.error('unable to import module %s' % self.mod_name) + except AttributeError: + parser.error('unable to import class %s from %s' % (self.cls_name, self.mod_name)) + + + + self.video_info = {} + self.video_info['filename'] = filename + self.video_info['total_size'] = os.stat(filename).st_size + self.video_info['clusters'] = [] + + self.doc = self.doc_cls(open(filename, 'rb')) + + + def get_data(self): + offset = 0 + for el in self.doc.roots: + self.fill_video_info(el, offset, self.video_info) + offset += el.size + return self.video_info + + def get_full_info(self): + self.max_count = -1 + return self.get_data() + + def get_first_cluster_timecode(self): + self.max_count = 4 + data = self.get_data() + ms = data['clusters'][0]['timecode'] + time = datetime.timedelta(microseconds=ms*1000) + return str(time) + + + def fill_video_info(self, element, offset, video_info): + if element.name == 'Duration': + video_info['duration'] = element.value + + if element.name == 'DisplayWidth': + video_info['width'] = element.value + + if element.name == 'DisplayHeight': + video_info['height'] = element.value + + if element.name == 'Cluster': + video_info['clusters'].append({'offset': offset}) + + if element.name == 'Timecode': + video_info['clusters'][-1]['timecode'] = element.value + + if element.type == CONTAINER: + i = 0 + for sub_el in element.value: + self.fill_video_info(sub_el, offset + element.head_size, video_info) + offset += sub_el.size + if i == self.max_count: + break + i += 1 + + From 5559a2ad571da12ab1d68aba7eefe69c41654681 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 6 Dec 2012 16:37:17 +0100 Subject: [PATCH 08/16] cleanup --- ebml/utils/ebml_data.py | 5 +---- tools/get_first_cluster_timecode.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ebml/utils/ebml_data.py b/ebml/utils/ebml_data.py index 4a4063b..d2a9de7 100644 --- a/ebml/utils/ebml_data.py +++ b/ebml/utils/ebml_data.py @@ -7,7 +7,7 @@ class EBMLData(object): - def __init__(self, filename, max_count=-1): + def __init__(self, filename): self.mod_name, _, self.cls_name = 'ebml.schema.matroska.MatroskaDocument'.rpartition('.') try: self.doc_mod = __import__(self.mod_name, fromlist=[self.cls_name]) @@ -26,7 +26,6 @@ def __init__(self, filename, max_count=-1): self.doc = self.doc_cls(open(filename, 'rb')) - def get_data(self): offset = 0 for el in self.doc.roots: @@ -45,7 +44,6 @@ def get_first_cluster_timecode(self): time = datetime.timedelta(microseconds=ms*1000) return str(time) - def fill_video_info(self, element, offset, video_info): if element.name == 'Duration': video_info['duration'] = element.value @@ -71,4 +69,3 @@ def fill_video_info(self, element, offset, video_info): break i += 1 - diff --git a/tools/get_first_cluster_timecode.py b/tools/get_first_cluster_timecode.py index 1b882df..b5ca570 100644 --- a/tools/get_first_cluster_timecode.py +++ b/tools/get_first_cluster_timecode.py @@ -4,7 +4,7 @@ import sys if __name__ == '__main__': - ebml_obj = EBMLData(sys.argv[-1], max_count=4) + ebml_obj = EBMLData(sys.argv[-1]) print ebml_obj.get_first_cluster_timecode() From 51bf3741a7d8920f4c36af182fc5682eaa75558b Mon Sep 17 00:00:00 2001 From: yomguy Date: Thu, 6 Dec 2012 16:39:31 +0100 Subject: [PATCH 09/16] add doc to manifest --- LICENSE => LICENSE.txt | 0 MANIFEST.in | 2 ++ tools/get_info.py | 26 +++++++++++++------------- 3 files changed, 15 insertions(+), 13 deletions(-) rename LICENSE => LICENSE.txt (100%) diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/MANIFEST.in b/MANIFEST.in index 3949540..ac884ab 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,6 @@ include *.xml +include *.rst +include *.txt global-exclude *.pyc prune dist prune build diff --git a/tools/get_info.py b/tools/get_info.py index 38b4ecc..68ec7eb 100644 --- a/tools/get_info.py +++ b/tools/get_info.py @@ -1,34 +1,34 @@ from ebml.schema import EBMLDocument, UnknownElement, CONTAINER, BINARY - - + + def fill_video_info(element, offset, video_info): if element.name == 'Duration': video_info['duration'] = element.value - + if element.name == 'DisplayWidth': video_info['width'] = element.value - + if element.name == 'DisplayHeight': video_info['height'] = element.value - + if element.name == 'Cluster': video_info['clusters'].append({'offset': offset}) - + if element.name == 'Timecode': video_info['clusters'][-1]['timecode'] = element.value - + if element.type == CONTAINER: for sub_el in element.value: fill_video_info(sub_el, offset + element.head_size, video_info) offset += sub_el.size - - + + if __name__ == '__main__': import sys import json import os - + mod_name, _, cls_name = 'ebml.schema.matroska.MatroskaDocument'.rpartition('.') try: doc_mod = __import__(mod_name, fromlist=[cls_name]) @@ -37,17 +37,17 @@ def fill_video_info(element, offset, video_info): parser.error('unable to import module %s' % mod_name) except AttributeError: parser.error('unable to import class %s from %s' % (cls_name, mod_name)) - + video_info = {} video_info['filename'] = sys.argv[1] video_info['total_size'] = os.stat(sys.argv[1]).st_size video_info['clusters'] = [] - + with open(sys.argv[1], 'rb') as stream: doc = doc_cls(stream) offset = 0 for el in doc.roots: fill_video_info(el, offset, video_info) offset += el.size - + print json.dumps(video_info) From 4d2e2d2567243aa0479331fe6c258c964f5b0874 Mon Sep 17 00:00:00 2001 From: yomguy Date: Thu, 6 Dec 2012 16:48:10 +0100 Subject: [PATCH 10/16] add classifiers --- setup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d1b5718..70afb31 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,13 @@ from setuptools import setup, find_packages +CLASSIFIERS = ['Programming Language :: Python', + 'Development Status :: 3 - Alpha', + 'Operating System :: OS Independent', + 'Topic :: Multimedia :: Video', + 'Topic :: Software Development :: Libraries :: Python Modules', + ] + setup( name = "python-ebml", url = "https://github.com/jspiros/python-ebml", @@ -20,7 +27,8 @@ license='BSD', packages = find_packages(), namespace_packages=['ebml'], - package_data={'': ['*.xml']}, + package_data={'': ['*.xml']}, include_package_data = True, zip_safe = False, + classifiers = CLASSIFIERS, ) From 374f62b75073da3c1a29f2cc1aff66f849010881 Mon Sep 17 00:00:00 2001 From: yomguy Date: Thu, 6 Dec 2012 16:49:22 +0100 Subject: [PATCH 11/16] update repo --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 70afb31..c474b62 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name = "python-ebml", - url = "https://github.com/jspiros/python-ebml", + url = "https://github.com/yomguy/python-ebml.git", description = "EBML (Extensible Binary Meta Language) library for Python", long_description = open('README.rst').read(), author = "Joseph Spiros", From 4f69f9f5a77efa07364349eb237c139170193e67 Mon Sep 17 00:00:00 2001 From: yomguy Date: Mon, 4 Feb 2013 18:55:10 +0100 Subject: [PATCH 12/16] fix timedelta for file duration more than 1 day --- MANIFEST.in | 3 ++- ebml/utils/ebml_data.py | 8 ++++++-- setup.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index ac884ab..32f41e4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,4 +4,5 @@ include *.txt global-exclude *.pyc prune dist prune build -recursive-include tools +prune python_ebml.egg-info +recursive-include tools \ No newline at end of file diff --git a/ebml/utils/ebml_data.py b/ebml/utils/ebml_data.py index d2a9de7..cde273a 100644 --- a/ebml/utils/ebml_data.py +++ b/ebml/utils/ebml_data.py @@ -41,8 +41,12 @@ def get_first_cluster_timecode(self): self.max_count = 4 data = self.get_data() ms = data['clusters'][0]['timecode'] - time = datetime.timedelta(microseconds=ms*1000) - return str(time) + d = datetime.timedelta(microseconds=ms*1000) + hours = d.days * 24 + d.seconds / 3600 + minutes = (d.seconds % 3600) / 60 + seconds = d.seconds % 60 + microseconds = d.microseconds + return "%.2d:%.2d:%.2d.%.2d" % (hours, minutes, seconds, microseconds) def fill_video_info(self, element, offset, video_info): if element.name == 'Duration': diff --git a/setup.py b/setup.py index c474b62..99355c9 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ long_description = open('README.rst').read(), author = "Joseph Spiros", author_email = "joseph@josephspiros.com", - version = '0.1', + version = '0.2', install_requires = [ 'setuptools', ], From 8bce341802bada028055b325dbb863d3cf03b80d Mon Sep 17 00:00:00 2001 From: yomguy Date: Tue, 5 Feb 2013 00:00:12 +0100 Subject: [PATCH 13/16] add first cluster time to seconds --- ebml/utils/ebml_data.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ebml/utils/ebml_data.py b/ebml/utils/ebml_data.py index cde273a..c1a4a2a 100644 --- a/ebml/utils/ebml_data.py +++ b/ebml/utils/ebml_data.py @@ -37,7 +37,7 @@ def get_full_info(self): self.max_count = -1 return self.get_data() - def get_first_cluster_timecode(self): + def get_first_cluster_duration(self): self.max_count = 4 data = self.get_data() ms = data['clusters'][0]['timecode'] @@ -48,6 +48,13 @@ def get_first_cluster_timecode(self): microseconds = d.microseconds return "%.2d:%.2d:%.2d.%.2d" % (hours, minutes, seconds, microseconds) + def get_first_cluster_seconds(self): + self.max_count = 4 + data = self.get_data() + ms = data['clusters'][0]['timecode'] + td = datetime.timedelta(microseconds=ms*1000) + return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 + def fill_video_info(self, element, offset, video_info): if element.name == 'Duration': video_info['duration'] = element.value From 3b3b1c615d170407b63ef25be18a0cc06c7bba20 Mon Sep 17 00:00:00 2001 From: yomguy Date: Tue, 5 Feb 2013 00:02:12 +0100 Subject: [PATCH 14/16] fix method name --- ebml/utils/ebml_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebml/utils/ebml_data.py b/ebml/utils/ebml_data.py index c1a4a2a..6aa7ce0 100644 --- a/ebml/utils/ebml_data.py +++ b/ebml/utils/ebml_data.py @@ -37,7 +37,7 @@ def get_full_info(self): self.max_count = -1 return self.get_data() - def get_first_cluster_duration(self): + def get_first_cluster_timecode(self): self.max_count = 4 data = self.get_data() ms = data['clusters'][0]['timecode'] From 095b50af4a5797fea7d435d691c1c456bde8ea06 Mon Sep 17 00:00:00 2001 From: yomguy Date: Tue, 5 Feb 2013 00:08:08 +0100 Subject: [PATCH 15/16] fix microseconds --- ebml/utils/ebml_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebml/utils/ebml_data.py b/ebml/utils/ebml_data.py index 6aa7ce0..9a14cd7 100644 --- a/ebml/utils/ebml_data.py +++ b/ebml/utils/ebml_data.py @@ -53,7 +53,7 @@ def get_first_cluster_seconds(self): data = self.get_data() ms = data['clusters'][0]['timecode'] td = datetime.timedelta(microseconds=ms*1000) - return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 + return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10.0**6 def fill_video_info(self, element, offset, video_info): if element.name == 'Duration': From 5981ca259e9c586411fd3cbce472ba741dc5dd0d Mon Sep 17 00:00:00 2001 From: yomguy Date: Tue, 5 Feb 2013 00:24:48 +0100 Subject: [PATCH 16/16] cleanup --- ebml/utils/ebml_data.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ebml/utils/ebml_data.py b/ebml/utils/ebml_data.py index 9a14cd7..a9d1faf 100644 --- a/ebml/utils/ebml_data.py +++ b/ebml/utils/ebml_data.py @@ -37,22 +37,22 @@ def get_full_info(self): self.max_count = -1 return self.get_data() - def get_first_cluster_timecode(self): + def get_first_cluster_timedelta(self): self.max_count = 4 data = self.get_data() ms = data['clusters'][0]['timecode'] - d = datetime.timedelta(microseconds=ms*1000) - hours = d.days * 24 + d.seconds / 3600 - minutes = (d.seconds % 3600) / 60 - seconds = d.seconds % 60 - microseconds = d.microseconds + return datetime.timedelta(microseconds=ms*1000) + + def get_first_cluster_timecode(self): + td = self.get_first_cluster_timedelta() + hours = td.days * 24 + td.seconds / 3600 + minutes = (td.seconds % 3600) / 60 + seconds = td.seconds % 60 + microseconds = td.microseconds return "%.2d:%.2d:%.2d.%.2d" % (hours, minutes, seconds, microseconds) def get_first_cluster_seconds(self): - self.max_count = 4 - data = self.get_data() - ms = data['clusters'][0]['timecode'] - td = datetime.timedelta(microseconds=ms*1000) + td = self.get_first_cluster_timedelta() return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10.0**6 def fill_video_info(self, element, offset, video_info):