fix: normalize blank separators before WebVTT metadata classification
This commit is contained in:
@@ -86,7 +86,7 @@ def parse_srt(content: str) -> SrtParseResult:
|
||||
# example timestamp inside a NOTE/STYLE/REGION cannot become speech.
|
||||
blocks = []
|
||||
for block in re.split(r"\n[^\S\n]*\n", text):
|
||||
lines = block.strip("\n").split("\n")
|
||||
lines = block.strip().split("\n")
|
||||
first = lines[0].strip()
|
||||
# WebVTT's block parser gives a timing line in position two
|
||||
# precedence over the identifier (including STYLE/REGION/NOTE).
|
||||
|
||||
@@ -374,8 +374,9 @@ def test_numeric_only_cue_after_invalid_cue_is_not_discarded():
|
||||
|
||||
|
||||
@pytest.mark.parametrize('header', ['NOTE', 'NOTE translator notes', 'NOTE\ttranslator notes', 'STYLE', 'REGION'])
|
||||
def test_webvtt_metadata_timestamps_never_become_dialogue(header):
|
||||
text = f'WEBVTT\n\n{header}\nMetadata content\n00:00.000 --> 00:02.000\nMetadata only\n\ncue\n00:03.000 --> 00:04.000\nReal dialogue\n'
|
||||
@pytest.mark.parametrize('separator', ['\n\n', '\n\n \n', '\n \n\n'])
|
||||
def test_webvtt_metadata_timestamps_never_become_dialogue(header, separator):
|
||||
text = f'WEBVTT{separator}{header}\nMetadata content\n00:00.000 --> 00:02.000\nMetadata only\n\ncue\n00:03.000 --> 00:04.000\nReal dialogue\n'
|
||||
result = parse_srt(text)
|
||||
assert [cue['text'] for cue in result.segments] == ['Real dialogue']
|
||||
assert result.segments[0]['start'] == 3
|
||||
|
||||
Reference in New Issue
Block a user