vpn: require an active WireGuard handshake before downloading (refuse a dead tunnel)

This commit is contained in:
Konstantin Passig PC
2026-08-25 17:06:27 +02:00
parent b5d56d4d34
commit 85ae1fb184
4 changed files with 170 additions and 3 deletions
+6
View File
@@ -8,6 +8,8 @@ from typing import Optional
import yt_dlp
from .progress import DownloadProgress
log = logging.getLogger(__name__)
_BASE_OPTS = {
@@ -16,6 +18,7 @@ _BASE_OPTS = {
"noplaylist": True,
"ignoreerrors": True,
"no_color": True,
"noprogress": True, # we draw our own progress bar via progress_hooks
}
# named presets -> yt-dlp format strings. bestvideo+bestaudio requires ffmpeg
@@ -54,17 +57,20 @@ def download_video(
quality: str = "best",
format_override: Optional[str] = None,
extra_opts: dict | None = None,
progress: DownloadProgress | None = None,
) -> Optional[Path]:
"""Download a single video into out_dir. Returns the resulting file path."""
out_dir = out_dir.expanduser()
out_dir.mkdir(parents=True, exist_ok=True)
fmt = _select_format(quality, format_override)
bar = progress or DownloadProgress()
opts = {
**_BASE_OPTS,
**(extra_opts or {}),
"format": fmt,
"outtmpl": str(out_dir / "%(title).150B [%(id)s].%(ext)s"),
"nocheckcertificate": True,
"progress_hooks": [bar.hook],
}
if quality != "audio" and not format_override:
opts["merge_output_format"] = "mp4"