diff --git a/src/pymp4/parser.py b/src/pymp4/parser.py index 0d7c943..1dd0143 100644 --- a/src/pymp4/parser.py +++ b/src/pymp4/parser.py @@ -298,7 +298,7 @@ "enca": MP4ASampleEntryBox, "avc1": AVC1SampleEntryBox, "encv": AVC1SampleEntryBox, - "wvtt": Struct("children" / LazyBound(lambda ctx: GreedyRange(Box))) + "wvtt": Struct("children" / LazyBound(lambda: GreedyRange(Box))) }, GreedyBytes) ), includelength=True) @@ -552,7 +552,7 @@ TrackEncryptionBox = Struct( "version" / Default(OneOf(Int8ub, (0, 1)), 0), "flags" / Default(Int24ub, 0), - "_reserved" / Const(Int8ub, 0), + "_reserved" / Const(0, Int8ub), "default_byte_blocks" / Default(IfThenElse( this.version > 0, BitStruct( @@ -561,7 +561,7 @@ # count of unencrypted blocks in the protection pattern "skip" / Nibble ), - Const(Int8ub, 0) + Const(0, Int8ub) ), 0), "is_encrypted" / OneOf(Int8ub, (0, 1)), "iv_size" / OneOf(Int8ub, (0, 8, 16)), @@ -620,31 +620,26 @@ # WebVTT boxes CueIDBox = Struct( - "type" / Const(b"iden"), "cue_id" / GreedyString("utf8") ) CueSettingsBox = Struct( - "type" / Const(b"sttg"), "settings" / GreedyString("utf8") ) CuePayloadBox = Struct( - "type" / Const(b"payl"), "cue_text" / GreedyString("utf8") ) WebVTTConfigurationBox = Struct( - "type" / Const(b"vttC"), "config" / GreedyString("utf8") ) WebVTTSourceLabelBox = Struct( - "type" / Const(b"vlab"), "label" / GreedyString("utf8") ) -ContainerBoxLazy = LazyBound(lambda ctx: ContainerBox) +ContainerBoxLazy = LazyBound(lambda: ContainerBox) class TellMinusSizeOf(Subconstruct): diff --git a/tests/test_webvtt_boxes.py b/tests/test_webvtt_boxes.py index 84f7db3..e322c2c 100644 --- a/tests/test_webvtt_boxes.py +++ b/tests/test_webvtt_boxes.py @@ -12,79 +12,109 @@ class BoxTests(unittest.TestCase): def test_iden_parse(self): self.assertEqual( Box.parse(b'\x00\x00\x00\x27iden2 - this is the second subtitle'), - Container(offset=0) - (type=b"iden") - (cue_id="2 - this is the second subtitle") - (end=39) + Container( + offset=0, + type="iden", + data=Container( + cue_id="2 - this is the second subtitle" + ), + end=39 + ) ) def test_iden_build(self): self.assertEqual( Box.build(dict( - type=b"iden", - cue_id="1 - first subtitle")), + type="iden", + data=dict( + cue_id="1 - first subtitle" + ))), b'\x00\x00\x00\x1aiden1 - first subtitle') def test_sttg_parse(self): self.assertEqual( Box.parse(b'\x00\x00\x003sttgline:10% position:50% size:48% align:center'), - Container(offset=0) - (type=b"sttg") - (settings="line:10% position:50% size:48% align:center") - (end=51) + Container( + offset=0, + type="sttg", + data=Container( + settings="line:10% position:50% size:48% align:center" + ), + end=51 + ) ) def test_sttg_build(self): self.assertEqual( Box.build(dict( - type=b"sttg", - settings="line:75% position:20% size:2em align:right")), + type="sttg", + data=dict( + settings="line:75% position:20% size:2em align:right" + ))), b'\x00\x00\x002sttgline:75% position:20% size:2em align:right') def test_payl_parse(self): self.assertEqual( Box.parse(b'\x00\x00\x00\x13payl[chuckling]'), - Container(offset=0) - (type=b"payl") - (cue_text="[chuckling]") - (end=19) + Container( + offset=0, + type="payl", + data=Container( + cue_text="[chuckling]" + ), + end=19 + ) ) def test_payl_build(self): self.assertEqual( Box.build(dict( - type=b"payl", - cue_text="I have a bad feeling about- [boom]")), + type="payl", + data=dict( + cue_text="I have a bad feeling about- [boom]" + ))), b'\x00\x00\x00*paylI have a bad feeling about- [boom]') def test_vttC_parse(self): self.assertEqual( Box.parse(b'\x00\x00\x00\x0evttCWEBVTT'), - Container(offset=0) - (type=b"vttC") - (config="WEBVTT") - (end=14) + Container( + offset=0, + type="vttC", + data=Container( + config="WEBVTT" + ), + end=14 + ) ) def test_vttC_build(self): self.assertEqual( Box.build(dict( - type=b"vttC", - config="WEBVTT with a text header\n\nSTYLE\n::cue {\ncolor: red;\n}")), + type="vttC", + data=dict( + config="WEBVTT with a text header\n\nSTYLE\n::cue {\ncolor: red;\n}" + ))), b'\x00\x00\x00>vttCWEBVTT with a text header\n\nSTYLE\n::cue {\ncolor: red;\n}') def test_vlab_parse(self): self.assertEqual( Box.parse(b'\x00\x00\x00\x14vlabsource_label'), - Container(offset=0) - (type=b"vlab") - (label="source_label") - (end=20) + Container( + offset=0, + type="vlab", + data=Container( + label="source_label" + ), + end=20 + ) ) def test_vlab_build(self): self.assertEqual( Box.build(dict( - type=b"vlab", - label="1234 \n test_label \n\n")), + type="vlab", + data=dict( + label="1234 \n test_label \n\n" + ))), b'\x00\x00\x00\x1cvlab1234 \n test_label \n\n')