diff --git a/tests/test_dolby.py b/tests/test_dolby.py index 8ae3209..f879cb2 100644 --- a/tests/test_dolby.py +++ b/tests/test_dolby.py @@ -33,7 +33,6 @@ class TestDolby(TestCase): self.assertTrue(seg[1]) def test_ddp(self): - t1 = wavinfo.WavInfoReader(self.test_file) d = t1.dolby @@ -42,7 +41,6 @@ class TestDolby(TestCase): self.assertTrue( ddp[0].audio_coding_mode, DolbyDigitalPlusMetadata.AudioCodingMode.CH_ORD_3_2 ) self.assertTrue( ddp[0].lfe_on) - def test_atmos(self): t1 = wavinfo.WavInfoReader(self.test_file) d = t1.dolby diff --git a/wavinfo/__main__.py b/wavinfo/__main__.py index 73cb991..7fa08bf 100644 --- a/wavinfo/__main__.py +++ b/wavinfo/__main__.py @@ -3,7 +3,14 @@ import datetime from . import WavInfoReader import sys import json +from enum import Enum +class MyJSONEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, Enum): + return dict(name=o._name_, value=o._value_) + else: + return super().default(o) def main(): parser = OptionParser() @@ -25,7 +32,7 @@ def main(): ret_dict['scopes'][scope][name] = value - json.dump(ret_dict, fp=sys.stdout, indent=2) + json.dump(ret_dict, cls=MyJSONEncoder, fp=sys.stdout, indent=2) except Exception as e: print(e) diff --git a/wavinfo/wave_dbmd_reader.py b/wavinfo/wave_dbmd_reader.py index f0b2320..4c7030a 100644 --- a/wavinfo/wave_dbmd_reader.py +++ b/wavinfo/wave_dbmd_reader.py @@ -9,7 +9,7 @@ Unless otherwise stated, all ยง references here are to from enum import IntEnum, Enum from struct import unpack -from dataclasses import dataclass +from dataclasses import dataclass, asdict from typing import List, Optional, Tuple, Any, Union from io import BytesIO @@ -255,10 +255,6 @@ class DolbyDigitalPlusMetadata: RESERVED = 3 - class DataRate(int): - pass - - class RFCompressionProfile(Enum): """ `compr1` RF compression profile @@ -419,7 +415,7 @@ class DolbyDigitalPlusMetadata: pass def datarate(b) -> int: - return b + return unpack(" dict: + + ddp = map(lambda x: asdict(x), self.dolby_digital_plus()) + atmos = map(lambda x: asdict(x), self.dolby_atmos()) + atmos_sup = [] #map(lambda x: asdict(x), self.dolby_atmos_supplemental()) + + return dict(dolby_digital_plus=list(ddp), + dolby_atmos=list(atmos), + dolby_atmos_supplemental=list(atmos_sup)) diff --git a/wavinfo/wave_reader.py b/wavinfo/wave_reader.py index 426f7c5..2bb18c3 100644 --- a/wavinfo/wave_reader.py +++ b/wavinfo/wave_reader.py @@ -169,10 +169,10 @@ class WavInfoReader: :yields: tuples of the *scope*, *key*, and *value* of each metadatum. The *scope* value will be one of - "fmt", "data", "ixml", "bext", "info" or "adm". + "fmt", "data", "ixml", "bext", "info", "dolby", or "adm". """ - scopes = ('fmt', 'data', 'ixml', 'bext', 'info', 'adm') + scopes = ('fmt', 'data', 'ixml', 'bext', 'info', 'adm', 'dolby') for scope in scopes: if scope in ['fmt', 'data']: