feat: -z -00:20 als Kurzform für 0-00:20 (vom Anfang bis)

Wörter hinter -z, die mit - und einer Ziffer beginnen, werden vor argparse
zu 0-… umgeschrieben; parse_ranges nimmt -B auch in Anführungszeichen an.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-10-11 20:29:34 +02:00
commit 955bdc2659
2 changed files with 74 additions and 22 deletions

View file

@ -532,6 +532,13 @@ def test_main_url_time_range_default_names(from_url, tmp_path, monkeypatch):
assert result == "[00:00:02 - 00:00:03]\n\nDas ist bekannt.\n"
def test_main_url_range_from_beginning(from_url, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
run_main(monkeypatch, "-u", URL, "-z", "-0:00:02")
raw = (tmp_path / "Kanal_Rede_2026-03-28_bis_00-00-02.txt").read_text(encoding="utf-8")
assert raw == "[00:00:01 - 00:00:02]\nDer Kremmel ist in Moskau.\n"
def test_main_url_time_range_without_text(from_url, tmp_path, monkeypatch):
with pytest.raises(SystemExit, match="im gewählten Zeitraum keinen Text"):
run_main(monkeypatch, "-u", URL, "-z", "1:00", "-o", tmp_path / "x.korrigiert.txt")

View file

@ -190,6 +190,8 @@ def test_parse_cue_time_keeps_minutes_seconds(text, seconds):
@pytest.mark.parametrize("text, ranges", [
("00:5:00-00:6:00 00:10-00:12:00 00:25", [(300, 360), (600, 720), (1500, None)]),
("0-00:20", [(None, 1200)]),
("-00:20", [(None, 1200)]),
("-00:05 00:10-00:12", [(None, 300), (600, 720)]),
("0:00:00-0:01", [(None, 60)]),
("00:25- 00:10-00:12 0-00:05", [(None, 300), (600, 720), (1500, None)]),
("00:05-00:06 00:06-00:07", [(300, 360), (360, 420)]),
@ -200,8 +202,9 @@ def test_parse_ranges(text, ranges):
@pytest.mark.parametrize("text, message", [
("", "keine Bereiche"),
("-", "vom Anfang: 0-B"),
("-00:20", "vom Anfang: 0-B"),
("-", "ungültiger Bereich"),
("-0", "Start muss vor Ende"),
("-00:05 -00:10", "überschneiden"),
("0", "das ganze Video"),
("0-", "das ganze Video"),
("00:06-00:05", "Start muss vor Ende"),
@ -384,6 +387,26 @@ def test_main_ranges_with_or_without_quotes(sample_copy, monkeypatch, ranges):
assert target.is_file()
@pytest.mark.parametrize("argv, expected", [
(["-i", "x", "-z", "-00:20"], ["-i", "x", "-z", "0-00:20"]),
(["-z", "00:05-00:06", "-00:20", "-o", "f"], ["-z", "00:05-00:06", "0-00:20", "-o", "f"]),
(["--zeitraeume", "-0:01:30"], ["--zeitraeume", "0-0:01:30"]),
(["-z", "0:05", "--exakt", "-1"], ["-z", "0:05", "--exakt", "-1"]),
(["-i", "-5.vtt"], ["-i", "-5.vtt"]),
(["-z=-00:20"], ["-z=-00:20"]),
])
def test_range_argv(argv, expected):
assert vtt2txt.range_argv(argv) == expected
@pytest.mark.parametrize("ranges", [["-0:01"], ["0-0:01"], ["-z=-0:01"]])
def test_main_range_from_beginning(sample_copy, monkeypatch, ranges):
args = ranges if ranges[0].startswith("-z") else ["-z", *ranges]
run_main(monkeypatch, "-i", sample_copy, *args)
target = sample_copy.with_name("ramstein.de_bis_00-01-00.txt")
assert target.read_text(encoding="utf-8").startswith("[00:00:09 - ")
def test_main_time_range_without_captions(sample_copy, monkeypatch, capsys):
with pytest.raises(SystemExit) as exc:
run_main(monkeypatch, "-i", sample_copy, "-z", "99:00:00")
@ -396,7 +419,7 @@ def test_main_time_range_without_captions(sample_copy, monkeypatch, capsys):
(["-z", "1:00-0:30"], "Start muss vor Ende"),
(["-z", "0:05 0:10"], "überschneiden"),
(["-z", "0:05", "0:10"], "überschneiden"),
(["-z=-0:20"], "vom Anfang: 0-B"),
(["-z", "-"], "ungültiger Bereich"),
(["-z", "0"], "das ganze Video"),
(["-s", "0:01"], "unrecognized arguments: -s"),
])