fix: preserve numeric-only subtitle dialogue after skipped cues

This commit is contained in:
Palash Debnath
2026-09-17 13:14:05 +05:30
parent c3137da680
commit 810e5e350b
2 changed files with 9 additions and 2 deletions
+3 -2
View File
@@ -125,10 +125,11 @@ def parse_srt(content: str) -> SrtParseResult:
marker_lines.pop()
marker = marker_lines[-1].strip(" \t") if marker_lines else ""
numeric = bool(marker) and marker.isascii() and marker.isdecimal()
separated = len(marker_lines) > 1 and not marker_lines[-2].strip()
separated = len(marker_lines) > 2 and not marker_lines[-2].strip()
expected_index = cue_index + 1 if cue_index is not None else i + 2
expected = marker.lstrip("0") == str(expected_index)
if numeric and expected and (cue_index is not None or separated):
has_dialogue = any(line.strip() for line in marker_lines[:-1])
if numeric and expected and (has_dialogue or separated) and (cue_index is not None or separated):
body = "\n".join(marker_lines[:-1])
next_index = expected_index
cue_index = next_index
+6
View File
@@ -365,3 +365,9 @@ def test_skipped_cue_still_advances_numbering_state():
result = parse_srt(text)
assert result.skipped_cues == 1
assert [cue["text"] for cue in result.segments] == ["First", "Third", "Fourth"]
def test_numeric_only_cue_after_invalid_cue_is_not_discarded():
text = "1\n00:00:01,000 --> 00:00:02,000\nFirst\n\n2\n00:00:04,000 --> 00:00:03,000\nInvalid\n\n3\n00:00:05,000 --> 00:00:06,000\n4\n00:00:07,000 --> 00:00:08,000\nLast"
assert [cue["text"] for cue in parse_srt(text).segments] == ["First", "4", "Last"]