Skip to content

Commit

Permalink
Fix stuff I missed when rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaphoenix committed Aug 7, 2023
1 parent 09a5b85 commit 73a4ba4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 39 deletions.
13 changes: 4 additions & 9 deletions src/pymp4/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand All @@ -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)),
Expand Down Expand Up @@ -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):
Expand Down
90 changes: 60 additions & 30 deletions tests/test_webvtt_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 73a4ba4

Please sign in to comment.