From a90d3f4b3892c162fd60e356c430c17686ef9c8f Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Sun, 5 Jan 2020 10:05:54 -0800 Subject: [PATCH] Version 1.5 Added command-line entrypoint, more UMID implementation --- .idea/vcs.xml | 2 +- setup.py | 13 ++++++++++--- wavinfo/__init__.py | 2 +- wavinfo/__main__.py | 32 ++++++++++++++++++++++++++++++++ wavinfo/umid_parser.py | 30 ++++++++++++++++++++---------- wavinfo/wave_reader.py | 6 +++++- 6 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 wavinfo/__main__.py diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/setup.py b/setup.py index 8731cdf..4913c23 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,17 @@ from setuptools import setup +from wavinfo import __author__, __license__, __version__ with open("README.md", "r") as fh: long_description = fh.read() setup(name='wavinfo', - version='1.4.1', - author='Jamie Hardt', + version=__version__, + author=__author__, author_email='jamiehardt@me.com', description='Probe WAVE Files for iXML, Broadcast-WAVE and other metadata.', long_description_content_type="text/markdown", long_description=long_description, + license=__license__, url='https://github.com/iluvcapra/wavinfo', project_urls={ 'Source': @@ -29,5 +31,10 @@ setup(name='wavinfo', "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8"], keywords='waveform metadata audio ebu smpte avi library film tv editing editorial', - install_requires=['lxml'] + install_requires=['lxml'], + entry_points={ + 'console_scripts': [ + 'wavinfo = wavinfo.__main__:main' + ] + } ) diff --git a/wavinfo/__init__.py b/wavinfo/__init__.py index a356ca7..d7d33f0 100644 --- a/wavinfo/__init__.py +++ b/wavinfo/__init__.py @@ -7,6 +7,6 @@ Go to the documentation for wavinfo.WavInfoReader for more information. from .wave_reader import WavInfoReader from .riff_parser import WavInfoEOFError -__version__ = '1.4.1' +__version__ = '1.5' __author__ = 'Jamie Hardt ' __license__ = "MIT" \ No newline at end of file diff --git a/wavinfo/__main__.py b/wavinfo/__main__.py new file mode 100644 index 0000000..f676acd --- /dev/null +++ b/wavinfo/__main__.py @@ -0,0 +1,32 @@ +from optparse import OptionParser, OptionGroup +import datetime +from . import WavInfoReader +import sys +import json + +def main(): + parser = OptionParser() + + parser.usage = 'wavinfo [FILE.wav]*' + + # parser.add_option('-f', dest='output_format', help='Set the output format', + # default='json', + # metavar='FORMAT') + + (options, args) = parser.parse_args(sys.argv) + for arg in args[1:]: + try: + this_file = WavInfoReader(path=arg) + ret_dict = {'file_argument': arg, 'run_date': datetime.datetime.now().isoformat() , 'scopes': {}} + for scope, name, value in this_file.walk(): + if scope not in ret_dict['scopes'].keys(): + ret_dict['scopes'][scope] = {} + + ret_dict['scopes'][scope][name] = value + + json.dump(ret_dict, fp=sys.stdout, indent=2) + except Exception as e: + print(e) + +if __name__ == "__main__": + main() diff --git a/wavinfo/umid_parser.py b/wavinfo/umid_parser.py index 50cb8a5..8a054fd 100644 --- a/wavinfo/umid_parser.py +++ b/wavinfo/umid_parser.py @@ -10,10 +10,27 @@ class UMIDParser: def __init__(self, raw_umid: bytearray): self.raw_umid = raw_umid + @classmethod + def binary_to_string(cls, binary_value): + result_str = '' + for n in range(len(binary_value)): + result_str = f'{binary_value[n]:x}' + result_str + + return result_str + @property def universal_label(self) -> bytearray: return self.raw_umid[0:12] + @property + def basic_umid(self): + return self.raw_umid[0:32] + + def basic_umid_to_str(self): + return "%024x-%06x-%032x" % (self.binary_to_string(self.universal_label), + self.binary_to_string(self.instance_number), + self.binary_to_string(self.material_number)) + @property def universal_label_is_valid(self) -> bool: valid_preamble = b'\x06\x0a\x2b\x34\x01\x01\x01\x05\x01\x01' @@ -95,19 +112,12 @@ class UMIDParser: return 'extended' @property - def instance_number(self) -> int: - return struct.unpack(' bytearray: + return self.raw_umid[13:3] @property def material_number(self) -> bytearray: - return self.raw_umid[14:16] - - @property - def material_number_hex(self) -> str: - result_str = '' - for n in range(16): - result_str = '{:x}'.format(self.material_number[n]) + result_str - return result_str + return self.raw_umid[16:16] @property def source_pack(self) -> Union[bytearray, None]: diff --git a/wavinfo/wave_reader.py b/wavinfo/wave_reader.py index 3185f2d..63e6dda 100644 --- a/wavinfo/wave_reader.py +++ b/wavinfo/wave_reader.py @@ -147,9 +147,13 @@ class WavInfoReader(): metadata field, and the value. """ - scopes = ('fmt','data')#,'bext','ixml','info') + scopes = ('fmt', 'data') #'bext', 'ixml', 'info') for scope in scopes: attr = self.__getattribute__(scope) for field in attr._fields: yield scope, field, attr.__getattribute__(field) + + bext_dict = self.bext.to_dict() + for key in bext_dict.keys(): + yield 'bext', key, bext_dict[key]