fix: Untertitel ohne rollendes Fenster verlieren keine wiederholten Blöcke

vtt2txt.py entfernt Überlappungen nur noch, wenn die Datei ein rollendes
Fenster zeigt: mindestens die Hälfte der Blöcke wiederholt das Ende des
vorigen (YouTube-Auto-Untertitel: 97–99 %). Manuell erstellte Untertitel
werden vollständig übernommen, zwei gleiche Blöcke hintereinander bleiben
zwei.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-10-11 21:36:32 +02:00
commit 3da372a941

View file

@ -75,6 +75,36 @@ def test_vtt_to_lines_without_rolling_window():
assert vtt2txt.vtt_to_lines(vtt) == ["A", "B", "C"]
def test_vtt_to_lines_without_rolling_window_keeps_identical_cues():
# Hand-written captions: the speaker says "Nein." twice, as two cues, and
# a cue may start with the line that ended the previous one
vtt = "WEBVTT\n\n" + "".join([
cue(1, "Er sagt:"),
cue(2, "Nein."),
cue(3, "Nein."),
cue(4, "Ja, wirklich", "Nein."),
cue(5, "Nein.", "Und dann?"),
cue(6, "Dann kam"),
cue(7, "der Rest."),
cue(8, "Ende."),
])
assert vtt2txt.vtt_to_lines(vtt) == [
"Er sagt:", "Nein.", "Nein.", "Ja, wirklich", "Nein.", "Nein.", "Und dann?",
"Dann kam", "der Rest.", "Ende.",
]
@pytest.mark.parametrize("cues, expected", [
([], False),
([["A"]], False),
([["A"], ["A", "B"]], True),
([["A"], ["A", "B"], ["C"]], True), # half of the pairs overlap
([["A"], ["B"], ["C"], ["C", "D"]], False), # one of three
])
def test_is_rolling(cues, expected):
assert vtt2txt.is_rolling(cues) is expected
def test_main_default_output_matches_sample(sample_copy, monkeypatch, capsys):
run_main(monkeypatch, "-i", sample_copy)
target = sample_copy.with_name("ramstein.de.txt")