diff --git a/cloud/metering.py b/cloud/metering.py index 6238b40..965336a 100644 --- a/cloud/metering.py +++ b/cloud/metering.py @@ -66,11 +66,25 @@ def probe_file_minutes(path: str) -> float: def probe_url_minutes(url: str) -> float: """Return the video duration in minutes from yt-dlp metadata (no download). - Raises ValueError if the duration is unknown (e.g. live streams) — the caller - turns that into a 400 for managed users. + Uses the same residential proxy + anti-bot extractor args as the actual + download (main.py), so the metadata probe doesn't get IP-blocked on the + server before we even reach the download step. Metadata only — negligible + bandwidth. Raises ValueError if the duration is unknown (e.g. live streams). """ import yt_dlp - with yt_dlp.YoutubeDL({"skip_download": True, "quiet": True, "no_warnings": True}) as ydl: + opts = { + "skip_download": True, "quiet": True, "no_warnings": True, + "extractor_args": { + "youtube": { + "player_client": ["tv_embed", "android", "mweb", "web"], + "player_skip": ["webpage", "configs"], + } + }, + } + proxy = os.environ.get("PROXY_URL", "").strip() + if proxy: + opts["proxy"] = proxy + with yt_dlp.YoutubeDL(opts) as ydl: info = ydl.extract_info(url, download=False) duration = info.get("duration") if not duration: