fix: use residential proxy for the yt-dlp duration probe too
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.
This commit is contained in:
parent
05578c5456
commit
c15f26b31c
1 changed files with 17 additions and 3 deletions
|
|
@ -66,11 +66,25 @@ def probe_file_minutes(path: str) -> float:
|
||||||
def probe_url_minutes(url: str) -> float:
|
def probe_url_minutes(url: str) -> float:
|
||||||
"""Return the video duration in minutes from yt-dlp metadata (no download).
|
"""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
|
Uses the same residential proxy + anti-bot extractor args as the actual
|
||||||
turns that into a 400 for managed users.
|
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
|
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)
|
info = ydl.extract_info(url, download=False)
|
||||||
duration = info.get("duration")
|
duration = info.get("duration")
|
||||||
if not duration:
|
if not duration:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue