feat: Standard-Dateiname aus Kanal, Titel und Datum des Videos
- yt_untertitel.default_name(): <Kanal>_<Titel>_<Datum>, z. B. John_Mearsheimer_Offensive_Realism_Episode_1_Origins_of_the_War_In_Ukraine_2026-07-30 - Bindestriche/Punkte im Wort bleiben, Kanal max. 40, Titel max. 60 Zeichen an Wortgrenze; ohne Kanal und Titel die Video-ID - Gilt ohne -o/-n in extract_text.py (statt output.txt), yt_untertitel.py und rede_korrigieren.py -u (statt Video-ID) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb9201b721
commit
3d9a5037c2
3 changed files with 105 additions and 29 deletions
|
|
@ -17,6 +17,8 @@ VTT = (
|
|||
GERMAN_VIDEO = {
|
||||
"id": "abc123",
|
||||
"title": "Eine Rede",
|
||||
"channel": "Kanal",
|
||||
"upload_date": "20260328",
|
||||
"subtitles": {"en": []},
|
||||
"automatic_captions": {"de-orig": [], "de": [], "en": []},
|
||||
}
|
||||
|
|
@ -36,14 +38,14 @@ def test_default_language_is_original_audio(fake_yt_dlp, tmp_path, monkeypatch,
|
|||
monkeypatch.chdir(tmp_path)
|
||||
run_main(monkeypatch, "-u", URL)
|
||||
|
||||
text = (tmp_path / "output.txt").read_text(encoding="utf-8")
|
||||
text = (tmp_path / "Kanal_Eine_Rede_2026-03-28.txt").read_text(encoding="utf-8")
|
||||
assert text == "Guten Abend.\nSchön, dass Sie da sind.\n"
|
||||
assert "de-orig" in run.calls[1]
|
||||
assert "--write-auto-subs" in run.calls[1]
|
||||
out = capsys.readouterr().out
|
||||
assert "output.txt (2 Zeilen, 7 Wörter)" in out
|
||||
assert "Kanal_Eine_Rede_2026-03-28.txt (2 Zeilen, 7 Wörter)" in out
|
||||
# Only the text file remains, no VTT
|
||||
assert [p.name for p in tmp_path.iterdir()] == ["output.txt"]
|
||||
assert [p.name for p in tmp_path.iterdir()] == ["Kanal_Eine_Rede_2026-03-28.txt"]
|
||||
|
||||
|
||||
def test_default_language_ignores_dubbed_tracks(fake_yt_dlp, tmp_path, monkeypatch):
|
||||
|
|
|
|||
|
|
@ -378,7 +378,10 @@ def test_correct_chunk_sends_model(monkeypatch):
|
|||
|
||||
|
||||
URL = "https://www.youtube.com/watch?v=abc123"
|
||||
VIDEO = {"id": "abc123", "title": "Rede", "subtitles": {}, "automatic_captions": {"de-orig": []}}
|
||||
VIDEO = {
|
||||
"id": "abc123", "title": "Rede", "channel": "Kanal", "upload_date": "20260328",
|
||||
"subtitles": {}, "automatic_captions": {"de-orig": []},
|
||||
}
|
||||
VTT = (
|
||||
"WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nDer Kremmel ist in Moskau.\n\n"
|
||||
"00:00:02.000 --> 00:00:03.000\nDer Kremmel ist in Moskau.\nDas ist bekannt.\n"
|
||||
|
|
@ -397,11 +400,11 @@ def test_main_url_default_names(from_url, tmp_path, monkeypatch):
|
|||
monkeypatch.chdir(tmp_path)
|
||||
run_main(monkeypatch, "-u", URL, "-g", SHARED_GLOSSARY)
|
||||
|
||||
raw = (tmp_path / "abc123.txt").read_text(encoding="utf-8")
|
||||
raw = (tmp_path / "Kanal_Rede_2026-03-28.txt").read_text(encoding="utf-8")
|
||||
assert raw == "Der Kremmel ist in Moskau.\nDas ist bekannt.\n"
|
||||
result = (tmp_path / "abc123.korrigiert.txt").read_text(encoding="utf-8")
|
||||
result = (tmp_path / "Kanal_Rede_2026-03-28.korrigiert.txt").read_text(encoding="utf-8")
|
||||
assert result == "Der Kreml ist in Moskau. Das ist bekannt.\n"
|
||||
assert (tmp_path / "abc123.aenderungen.html").is_file()
|
||||
assert (tmp_path / "Kanal_Rede_2026-03-28.aenderungen.html").is_file()
|
||||
|
||||
|
||||
def test_main_url_output_option_and_kept_raw_text(from_url, tmp_path, monkeypatch, capsys):
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ URL = "https://www.youtube.com/watch?v=abc123"
|
|||
AUTO_ONLY = {
|
||||
"id": "abc123",
|
||||
"title": "Eine Rede",
|
||||
"channel": "Kanal",
|
||||
"upload_date": "20260328",
|
||||
"subtitles": {},
|
||||
"automatic_captions": {"de-orig": [], "de": [], "en": []},
|
||||
}
|
||||
|
|
@ -86,6 +88,24 @@ def test_original_language_with_dubbed_audio(info, expected):
|
|||
assert yt.original_language(info) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("info, expected", [
|
||||
({"channel": "John Mearsheimer - Offensive Realism",
|
||||
"title": "Episode 1: Origins of the War In Ukraine", "upload_date": "20260730"},
|
||||
"John_Mearsheimer_Offensive_Realism_Episode_1_Origins_of_the_War_In_Ukraine_2026-07-30"),
|
||||
# Title cut at a word boundary after 60 characters; hyphens and dots in words stay
|
||||
({"channel": "GGBLahnstein", "upload_date": "20260730",
|
||||
"title": "Prof. Gabriele Krone-Schmalz – Respekt geht anders – "
|
||||
"GGB-Gesundheitstage, Lahnstein 28.03.2026"},
|
||||
"GGBLahnstein_Prof_Gabriele_Krone-Schmalz_Respekt_geht_anders_2026-07-30"),
|
||||
({"uploader": "Ein Kanal", "title": "A/B: Krieg & Frieden 🎤?"}, "Ein_Kanal_A_B_Krieg_Frieden"),
|
||||
({"title": "Nur Titel", "upload_date": "kaputt"}, "Nur_Titel"),
|
||||
({"id": "abc123", "title": "🎤 – …"}, "abc123"),
|
||||
({"title": "x" * 80}, "x" * 60),
|
||||
])
|
||||
def test_default_name(info, expected):
|
||||
assert yt.default_name(info) == expected
|
||||
|
||||
|
||||
def test_available_tracks_hides_dubs():
|
||||
assert yt.available_tracks(DUBBED) == (["en-US"], ["en"])
|
||||
|
||||
|
|
@ -124,13 +144,13 @@ def test_yt_dlp_runs_in_temporary_directory(fake_yt_dlp, tmp_path, monkeypatch):
|
|||
assert (tmp_path / "Rede.de-orig.vtt").is_file()
|
||||
|
||||
|
||||
def test_main_prefers_manual_and_defaults_to_video_id(fake_yt_dlp, tmp_path, monkeypatch):
|
||||
def test_main_prefers_manual_and_default_name(fake_yt_dlp, tmp_path, monkeypatch):
|
||||
info = dict(AUTO_ONLY, subtitles={"de": []})
|
||||
run = fake_yt_dlp(info)
|
||||
monkeypatch.setattr(yt.subprocess, "run", run)
|
||||
run_main(monkeypatch, "-u", URL, "-d", tmp_path)
|
||||
|
||||
assert (tmp_path / "abc123.de.vtt").is_file()
|
||||
assert (tmp_path / "Kanal_Eine_Rede_2026-03-28.de.vtt").is_file()
|
||||
assert "--write-subs" in run.calls[1]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue