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
1 changed files with 105 additions and 29 deletions
|
|
@ -9,7 +9,8 @@ import textwrap
|
|||
|
||||
from vtt2txt import vtt_to_lines
|
||||
from yt_untertitel import (
|
||||
YT_DLP, choose_track, download, fetch_info, no_track_message, original_language,
|
||||
YT_DLP, choose_track, default_name, download, fetch_info, no_track_message,
|
||||
original_language,
|
||||
)
|
||||
|
||||
FLOW_WIDTH = 80 # Zeilenbreite für --fliesstext
|
||||
|
|
@ -25,8 +26,8 @@ def parse_args():
|
|||
help="Sprache der Untertitel, z. B. de (Standard: Sprache des Original-Audios)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o", "--output", type=Path, default=Path("output.txt"),
|
||||
help="Ausgabedatei (Standard: output.txt)",
|
||||
"-o", "--output", type=Path,
|
||||
help="Ausgabedatei (Standard: <Kanal>_<Titel>_<Datum>.txt)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f", "--fliesstext", action="store_true",
|
||||
|
|
@ -34,7 +35,7 @@ def parse_args():
|
|||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.output.is_dir():
|
||||
if args.output is not None and args.output.is_dir():
|
||||
parser.error(f"-o/--output ist ein Verzeichnis: {args.output}")
|
||||
if shutil.which(YT_DLP) is None:
|
||||
parser.error(f"{YT_DLP} nicht gefunden (Installation: pip install yt-dlp).")
|
||||
|
|
@ -73,7 +74,8 @@ def fetch_text(url, lang=None):
|
|||
|
||||
def main():
|
||||
args = parse_args()
|
||||
_, lines = fetch_text(args.url, args.lang)
|
||||
info, lines = fetch_text(args.url, args.lang)
|
||||
output = args.output or Path(f"{default_name(info)}.txt")
|
||||
|
||||
if args.fliesstext:
|
||||
# Never split words, not even at hyphens ("EU-Gipfel")
|
||||
|
|
@ -84,10 +86,10 @@ def main():
|
|||
else:
|
||||
text = "\n".join(lines)
|
||||
|
||||
args.output.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.output.write_text(text + "\n", encoding="utf-8")
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
output.write_text(text + "\n", encoding="utf-8")
|
||||
print(
|
||||
f"Gespeichert: {args.output} "
|
||||
f"Gespeichert: {output} "
|
||||
f"({len(text.splitlines())} Zeilen, {len(text.split())} Wörter)"
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue