fix: yt-dlp im temporären Verzeichnis ausführen (Streudatei „3“)
yt-dlp ruft zur Prüfung „ffmpeg -bsfs“ auf; das System-ffmpeg 6.1.1 (Ubuntu) legt dabei eine leere Datei „3“ im Arbeitsverzeichnis an. yt-dlp läuft jetzt in einem temporären Verzeichnis mit absolutem Zielpfad, die Datei verschwindet mit dem Verzeichnis. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
60c7c10abb
commit
7e6ffa5899
1 changed files with 40 additions and 13 deletions
|
|
@ -6,16 +6,26 @@ import argparse
|
|||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
YT_DLP = "yt-dlp"
|
||||
|
||||
|
||||
def run_yt_dlp(arguments):
|
||||
"""Run yt-dlp in a temporary working directory.
|
||||
|
||||
yt-dlp calls "ffmpeg -bsfs" to check ffmpeg; some ffmpeg builds (Ubuntu
|
||||
6.1.1) then leave an empty file "3" in the working directory.
|
||||
"""
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
return subprocess.run(
|
||||
[YT_DLP, *arguments], capture_output=True, text=True, cwd=tmp
|
||||
)
|
||||
|
||||
|
||||
def fetch_info(url):
|
||||
"""Return the video metadata from yt-dlp, without downloading anything."""
|
||||
result = subprocess.run(
|
||||
[YT_DLP, "--dump-single-json", "--skip-download", "--no-playlist", url],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
result = run_yt_dlp(["--dump-single-json", "--skip-download", "--no-playlist", url])
|
||||
if result.returncode != 0:
|
||||
raise SystemExit(f"yt-dlp konnte das Video nicht abrufen:\n{result.stderr.strip()}")
|
||||
return json.loads(result.stdout)
|
||||
|
|
@ -70,14 +80,14 @@ def no_track_message(info, lang):
|
|||
|
||||
def download(url, track, is_auto, target_base):
|
||||
"""Download one subtitle track; yt-dlp writes <target_base>.<track>.vtt."""
|
||||
command = [
|
||||
YT_DLP, "--skip-download", "--no-playlist", "--force-overwrites",
|
||||
result = run_yt_dlp([
|
||||
"--skip-download", "--no-playlist", "--force-overwrites",
|
||||
"--write-auto-subs" if is_auto else "--write-subs",
|
||||
"--sub-langs", track, "--sub-format", "vtt",
|
||||
"-o", f"{target_base}.%(ext)s",
|
||||
# Absolute, because yt-dlp runs in a temporary directory
|
||||
"-o", f"{Path(target_base).resolve()}.%(ext)s",
|
||||
url,
|
||||
]
|
||||
result = subprocess.run(command, capture_output=True, text=True)
|
||||
])
|
||||
if result.returncode != 0:
|
||||
raise SystemExit(f"Download fehlgeschlagen:\n{result.stderr.strip()}")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue