Merge branch 'fix/review-2077' into fix/community-integration

This commit is contained in:
Palash Debnath
2026-09-17 12:56:48 +05:30
2 changed files with 17 additions and 9 deletions
+9 -9
View File
@@ -106,15 +106,6 @@ def parse_srt(content: str) -> SrtParseResult:
first_marker = head.split("\n")[-1].strip() if head else ""
cue_index = int(first_marker) if _is_index_line(first_marker) and len(first_marker) <= 12 else None
for i, m in enumerate(matches):
try:
start = _ts_to_seconds(m.group(1), m.group(2), m.group(3), m.group(4))
end = _ts_to_seconds(m.group(5), m.group(6), m.group(7), m.group(8))
except (ValueError, IndexError):
skipped += 1
continue
if end <= start:
skipped += 1
continue
body_start = m.end()
has_next = i + 1 < len(matches)
body_end = matches[i + 1].start() if has_next else len(text)
@@ -141,6 +132,15 @@ def parse_srt(content: str) -> SrtParseResult:
body = "\n".join(marker_lines[:-1])
next_index = expected_index
cue_index = next_index
try:
start = _ts_to_seconds(m.group(1), m.group(2), m.group(3), m.group(4))
end = _ts_to_seconds(m.group(5), m.group(6), m.group(7), m.group(8))
except (ValueError, IndexError):
skipped += 1
continue
if end <= start:
skipped += 1
continue
lines = body.strip("\n").split("\n")
cue_text = "\n".join(line.strip() for line in lines if line.strip())
if not cue_text:
+8
View File
@@ -357,3 +357,11 @@ def test_initial_index_does_not_remove_later_numeric_dialogue(gap):
def test_nonsequential_ambiguous_number_is_retained_as_dialogue():
text = "00:00:01,000 --> 00:00:02,000\nFirst\n\n3\n00:00:03,000 --> 00:00:04,000\nNext"
assert parse_srt(text).segments[0]["text"] == "First\n3"
def test_skipped_cue_still_advances_numbering_state():
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\nThird\n\n4\n00:00:07,000 --> 00:00:08,000\nFourth"
result = parse_srt(text)
assert result.skipped_cues == 1
assert [cue["text"] for cue in result.segments] == ["First", "Third", "Fourth"]