mirror of
https://github.com/iluvcapra/wavinfo.git
synced 2026-01-02 01:40:42 +00:00
Version 1.5
Added command-line entrypoint, more UMID implementation
This commit is contained in:
@@ -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 <jamiehardt@gmail.com>'
|
||||
__license__ = "MIT"
|
||||
32
wavinfo/__main__.py
Normal file
32
wavinfo/__main__.py
Normal file
@@ -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()
|
||||
@@ -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('<I', self.raw_umid[13:4])[0] & 0x00ffffff
|
||||
def instance_number(self) -> 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]:
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user