From 393167b6ce37b4f9dac92ce3787162e737b8838a Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Wed, 13 Oct 2021 07:27:02 -0700 Subject: [PATCH] SRT writer: support timestamp over 100 hours (#346) --- src/main/python/ttconv/srt/reader.py | 2 +- src/test/python/test_srt_reader.py | 40 ++++++++++++++++------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/python/ttconv/srt/reader.py b/src/main/python/ttconv/srt/reader.py index e68d2f02..a8ddfa42 100644 --- a/src/main/python/ttconv/srt/reader.py +++ b/src/main/python/ttconv/srt/reader.py @@ -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[0-9]{2}):(?P[0-9]{2}):(?P[0-9]{2}),(?P[0-9]{3})\s+-->\s+(?P[0-9]{2}):(?P[0-9]{2}):(?P[0-9]{2}),(?P[0-9]{3})") +_TIMECODE_RE = re.compile(r"(?P[0-9]{2,3}):(?P[0-9]{2}):(?P[0-9]{2}),(?P[0-9]{3})\s+-->\s+(?P[0-9]{2,3}):(?P[0-9]{2}):(?P[0-9]{2}),(?P[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) diff --git a/src/test/python/test_srt_reader.py b/src/test/python/test_srt_reader.py index 370c9949..7ac887f1 100644 --- a/src/test/python/test_srt_reader.py +++ b/src/test/python/test_srt_reader.py @@ -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 my name is Bob """) @@ -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 my 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 @@ -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 my name is Bob """) @@ -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 my name is Bob """) @@ -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 my name is Bob """) @@ -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 my name is Bob @@ -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 my 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()