From c15f26b31c3a2e1ab3907f7955b8638386fe6a98 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Tue, 14 Jul 2026 13:17:53 +0200 Subject: [PATCH] fix: use residential proxy for the yt-dlp duration probe too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The metering duration probe (probe_url_minutes) ran yt-dlp without the proxy or anti-bot extractor args, so it got IP-blocked on the server before the download step. Now it mirrors main.py: PROXY_URL + player_client fallbacks. Verified E2E — YouTube download completes through the DataImpulse residential proxy. --- cloud/metering.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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: