From a85a41bb6ae5d6d33ab9ad6831ced855a4cdf223 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Fri, 4 Sep 2026 11:15:08 +0200 Subject: [PATCH] fix(download): free fallback-static attempt before any per-GB proxy Since the static IPs moved to three countries, every remaining paid rescue had the same shape: all three statics answer 'Video unavailable' and the paid fallback then downloads the video fine. Tested on the morning's case (2eCIMQMy0AQ): the video is fine from a residential IP, the HD/web client gets the fake unavailable on all three statics, and the conservative clients (tv_embed/android) pass on those very same IPs. So it is the client, not the IP, and the fix is free: try the fallback strategy through a static before spending a per-GB byte. No quality trade: the paid path was capped at 720p anyway. Claude-Session: https://claude.ai/code/session_014i9z6mLTy978uRCfSsMfBq --- CLAUDE.md | 5 ++++- main.py | 13 +++++++++++-- tests/test_download_plan.py | 12 ++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 25b8614..49e7c55 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -336,7 +336,10 @@ Async job queue with semaphore-based concurrency control. Configure via `MAX_CON Downloads go direct → static ISP proxies (flat rate) → DataImpulse (per GB), and the duration probe (`cloud/metering.probe_url_minutes`) follows the same -order. Two rules keep the per-GB proxy at zero on a normal day: the probe +order, with one extra free step before any per-GB attempt: the conservative +clients (tv_embed/android) through a static (`fallback-static`), because +YouTube serves the HD/web client a fake "Video unavailable" from +datacenter-ISP IPs on some videos while those clients pass on the same IPs. Two rules keep the per-GB proxy at zero on a normal day: the probe reaches it **only** when a static route failed for a reason another IP can fix (`static_failure_warrants_paid`: bot-check, 403/429, proxy/network errors), never for a private/removed/members-only video or a live stream diff --git a/main.py b/main.py index c4b8bd6..9f848db 100644 --- a/main.py +++ b/main.py @@ -707,6 +707,15 @@ def plan_download_attempts(direct_first, statics, paid, have_hd, youtube=True): if have_hd: for i, s in enumerate(statics): plan.append((f'HD-static{i + 1}', False, s)) + if statics and paid: + # The conservative clients (tv_embed/android) through a FREE static, + # before any per-GB attempt: YouTube serves a fake "Video unavailable" + # to the web/HD client from datacenter-ISP ranges on some videos while + # the fallback clients pass on the very same IPs (verified 4-sep-2026, + # all three statics, three countries). Costs nothing and the paid path + # was capped to 720p anyway, so there is no quality trade. + plan.append(('fallback-static', False, statics[0])) + if have_hd: plan.append(('HD', bool(paid), paid)) plan.append(('fallback', bool(paid), paid if paid else (statics[0] if statics else None))) @@ -863,8 +872,8 @@ def download_youtube_video(url, output_dir="."): attempts = [ (label, - fallback_args if label == 'fallback' else hd_args, - fallback_fmt if label == 'fallback' else _hd_fmt_for(capped), + fallback_args if label.startswith('fallback') else hd_args, + fallback_fmt if label.startswith('fallback') else _hd_fmt_for(capped), proxy) for label, capped, proxy in plan_download_attempts( _direct_first, _statics, _proxy, bool(hd_args), youtube=is_youtube_url(url)) diff --git a/tests/test_download_plan.py b/tests/test_download_plan.py index 0eb084b..cbda196 100644 --- a/tests/test_download_plan.py +++ b/tests/test_download_plan.py @@ -23,6 +23,10 @@ class TestOrdering: ('HD-static1', False, "http://s1"), ('HD-static2', False, "http://s2"), ('HD-static3', False, "http://s3"), + # Free rescue for the fake "Video unavailable" the HD client gets + # from datacenter-ISP IPs (4-sep-2026): conservative clients + # through a static BEFORE any per-GB attempt. + ('fallback-static', False, "http://s1"), ('HD', True, PAID), ('fallback', True, PAID), ] @@ -47,6 +51,14 @@ class TestOrdering: assert capped == (proxy == PAID) +def test_fallback_static_only_exists_when_paid_is_configured(): + # Without a paid proxy the final fallback already runs through a static; + # a fallback-static before it would be the same attempt twice. + got = plan(False, STATICS, None, True) + assert ('fallback-static', False, "http://s1") not in got + assert got[-1] == ('fallback', False, "http://s1") + + def test_direct_file_urls_skip_the_proxy_chain(): """A catbox/tmpfiles/CDN mp4 has no YouTube ban to dodge: own IP first, one static as fallback, never the per-GB proxy (prod 27-aug: 9 KB/s