Skip to content

Commit

Permalink
SRT writer: support timestamp over 100 hours (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
palemieux authored Oct 13, 2021
1 parent 8c36c98 commit 393167b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/python/ttconv/srt/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _State(Enum):

_EMPTY_RE = re.compile(r"\s+")
_COUNTER_RE = re.compile(r"\d+")
_TIMECODE_RE = re.compile(r"(?P<begin_h>[0-9]{2}):(?P<begin_m>[0-9]{2}):(?P<begin_s>[0-9]{2}),(?P<begin_ms>[0-9]{3})\s+-->\s+(?P<end_h>[0-9]{2}):(?P<end_m>[0-9]{2}):(?P<end_s>[0-9]{2}),(?P<end_ms>[0-9]{3})")
_TIMECODE_RE = re.compile(r"(?P<begin_h>[0-9]{2,3}):(?P<begin_m>[0-9]{2}):(?P<begin_s>[0-9]{2}),(?P<begin_ms>[0-9]{3})\s+-->\s+(?P<end_h>[0-9]{2,3}):(?P<end_m>[0-9]{2}):(?P<end_s>[0-9]{2}),(?P<end_ms>[0-9]{3})")
_DEFAULT_REGION_ID = "r1"
_DEFAULT_FONT_STACK = ("Verdana", "Arial", "Tiresias", styles.GenericFontFamilyType.sansSerif)
_DEFAULT_FONT_SIZE = styles.LengthType(80, styles.LengthType.Units.pct)
Expand Down
40 changes: 23 additions & 17 deletions src/test/python/test_srt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_sample(self):
self.assertIsNotNone(to_model(f))

def test_bold(self):
f = io.StringIO( """1
f = io.StringIO(r"""1
00:02:16,612 --> 00:02:19,376
Hello <bold>my</bold> name is Bob
""")
Expand Down Expand Up @@ -101,18 +101,6 @@ def test_blank_lines(self):

self.assertIsNotNone(to_model(f))

def test_bold(self):
f = io.StringIO( """1
00:02:16,612 --> 00:02:19,376
Hello <bold>my</bold> name is Bob
""")
doc = to_model(f)
for e in doc.get_body().dfs_iterator():
if e.get_style(styles.StyleProperties.FontWeight) == styles.FontWeightType.bold:
break
else:
self.fail()

def test_bold_alt(self):
f = io.StringIO(r"""1
00:02:16,612 --> 00:02:19,376
Expand All @@ -126,7 +114,7 @@ def test_bold_alt(self):
self.fail()

def test_italic(self):
f = io.StringIO( """1
f = io.StringIO(r"""1
00:02:16,612 --> 00:02:19,376
Hello <italic>my</italic> name is Bob
""")
Expand All @@ -150,7 +138,7 @@ def test_italic_alt(self):
self.fail()

def test_underline(self):
f = io.StringIO( """1
f = io.StringIO(r"""1
00:02:16,612 --> 00:02:19,376
Hello <underline>my</underline> name is Bob
""")
Expand All @@ -176,7 +164,7 @@ def test_underline_alt(self):
self.fail()

def test_blue(self):
f = io.StringIO("""1
f = io.StringIO(r"""1
00:02:16,612 --> 00:02:19,376
Hello <font color='blue'>my</font> name is Bob
""")
Expand All @@ -189,7 +177,7 @@ def test_blue(self):
self.fail()

def test_multiline_tags(self):
f = io.StringIO( """1
f = io.StringIO(r"""1
00:02:16,612 --> 00:02:19,376
Hello <bold>my
</bold> name is Bob
Expand All @@ -201,5 +189,23 @@ def test_multiline_tags(self):
else:
self.fail()

def test_long_hours(self):
f = io.StringIO(r"""1
101:00:00,000 --> 101:00:01,000
Hello <bold>my</bold> name is Bob
""")
doc = to_model(f)

self.assertEqual(
363600,
doc.get_body().first_child().first_child().get_begin()
)

self.assertEqual(
363601,
doc.get_body().first_child().first_child().get_end()
)


if __name__ == '__main__':
unittest.main()

0 comments on commit 393167b

Please sign in to comment.