check.py: apply the channel's status ytdlpCommand to yt-dlp probes; log open decision

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUYdCh2nCVsQYgJAT7gwSi
This commit is contained in:
Simon
2026-10-10 08:36:25 +00:00
parent 765fcb5579
commit 95700c67a5
2 changed files with 39 additions and 3 deletions

View File

@@ -18,6 +18,8 @@ Checks per channel:
- yt-dlp -J on each format.url that is not a direct media file
"""
import os
import shlex
import sys
import json
import subprocess
@@ -178,6 +180,29 @@ def http_ok(url: str, headers: dict | None = None) -> tuple[bool, int]:
return False, -3
# Per-channel yt-dlp options taken from the channel's declared `ytdlpCommand`
# (e.g. "yt-dlp --impersonate chrome-120"), which real clients apply. Probing
# without them reports failures (TLS-fingerprint 403/502) no client sees.
_CHANNEL_YTDLP_ARGS: dict[str, list[str]] = {}
def register_ytdlp_command(channel_id: str, command: Optional[str]) -> None:
if not command:
return
try:
parts = shlex.split(command)
except ValueError:
return
if parts and os.path.basename(parts[0]) in ("yt-dlp", "yt_dlp"):
parts = parts[1:]
if parts:
_CHANNEL_YTDLP_ARGS[channel_id] = parts
def ytdlp_args_for(channel_id: str) -> list[str]:
return list(_CHANNEL_YTDLP_ARGS.get(channel_id, []))
def ytdlp_extract(url: str, extra_args: list[str] | None = None) -> tuple[Optional[dict], str]:
"""Run yt-dlp -j and return (parsed_info_or_None, stderr_text).
@@ -389,7 +414,7 @@ def check_video(video: dict, channel_id: str, results: Results, run_ytdlp: bool)
ytdlp_url = vurl if vurl and "127.0.0.1" not in vurl and "localhost" not in vurl else ""
if not formats and ytdlp_url and is_page_url(ytdlp_url):
results.info(channel_id, f"{label}: yt-dlp extract {ytdlp_url}")
yt, stderr = ytdlp_extract(ytdlp_url)
yt, stderr = ytdlp_extract(ytdlp_url, extra_args=ytdlp_args_for(channel_id))
if yt is None:
if _is_cf_protected(ytdlp_url):
results.warn(
@@ -457,7 +482,7 @@ def check_video(video: dict, channel_id: str, results: Results, run_ytdlp: bool)
for hk, hv in fheaders.items():
extra_args += ["--add-header", f"{hk}:{hv}"]
results.info(channel_id, f"{label} format[{j}]: yt-dlp extract {furl}")
yt, stderr = ytdlp_extract(furl, extra_args=extra_args)
yt, stderr = ytdlp_extract(furl, extra_args=ytdlp_args_for(channel_id) + extra_args)
if yt is None:
resolved = follow_proxy_redirect(furl)
if _is_cf_protected(furl) or _is_cf_protected(resolved):
@@ -581,6 +606,9 @@ def main():
print("ERROR: no channels in /api/status response")
sys.exit(1)
for ch in channels:
register_ytdlp_command(ch["id"], ch.get("ytdlpCommand"))
print(f"status OK — {len(channels)} channels")
# --- per-channel checks ---