diff --git a/srt.py b/srt.py index 86506ad..129cf29 100755 --- a/srt.py +++ b/srt.py @@ -12,7 +12,7 @@ log = logging.getLogger(__name__) SRT_REGEX = re.compile( - r'(\d+)\n(\d+:\d+:\d+,\d+) --> (\d+:\d+:\d+,\d+) ?([^\n]*)\n(.*?)' + r'(\d+)\n(\d+:\d+:\d+[,.]\d+) --> (\d+:\d+:\d+[,.]\d+) ?([^\n]*)\n(.*?)' # Many sub editors don't add a blank line to the end, and many editors # accept it. We allow it in input. r'(?:\n|\Z)(?:\n|\Z)' diff --git a/tests/test_srt.py b/tests/test_srt.py index fae7553..e5f511a 100644 --- a/tests/test_srt.py +++ b/tests/test_srt.py @@ -262,3 +262,21 @@ def test_parser_didnt_match_to_end_raises(subs, fake_idx, fake_hours, garbage): with assert_raises(srt.SRTParseError): list(srt.parse(composed)) + + +@given(st.lists(subtitles())) +def test_parser_can_parse_with_dot_msec_delimiter(subs): + original_srt_blocks = [sub.to_srt() for sub in subs] + dot_srt_blocks = [] + + for srt_block in original_srt_blocks: + srt_lines = srt_block.split('\n') + # We should only do the first two, as it might also be in the + # proprietary metadata, causing this test to fail. + dot_timestamp = srt_lines[1].replace(',', '.', 2) + srt_lines[1] = dot_timestamp + dot_srt_blocks.append('\n'.join(srt_lines)) + + composed_with_dots = ''.join(dot_srt_blocks) + reparsed_subs = srt.parse(composed_with_dots) + subs_eq(reparsed_subs, subs)