New STATIC_PROXY_URLS env (comma-separated): dedicated ISP IPs with unlimited traffic, tried after the direct attempt and before the per-GB paid proxy. With it unset the chain is byte-identical to before. - plan_download_attempts: pure, unit-tested attempt ordering. Cheapest bandwidth first: direct -> statics (rotated per job, uncapped 1080p, free bytes) -> paid HD (720p cost cap) -> fallback via paid. - The 720p cap and the PROXY_BYTES monthly counter now apply ONLY to attempts that actually bill per GB — static downloads come in at 1080p and don't count toward the cost alert. - alerts.py watcher generalized to multiple targets: the static pool (down = ingest silently moves to per-GB billing, nag with a cost hint) and the paid proxy (down = ingest at risk), each with its own down/nag/recovered incident state. Context: the server's IPv4 is hard-banned by YouTube (19-aug-2026), so DIRECT_FIRST serves nothing and every download was going through DataImpulse at $1/GB capped to 720p. Verified from prod: all 3 Decodo dedicated IPs pass the bot-check with cookies+bgutil at 1080p.
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Download attempt ordering: cheapest bandwidth first.
|
|
|
|
Direct (server IP) -> flat-rate static ISP proxies (uncapped 1080p, free
|
|
bytes) -> per-GB paid proxy (720p cost cap) -> conservative fallback. The
|
|
``capped`` flag marks the attempts whose bytes are billed per GB (drives the
|
|
720p format cap and the PROXY_BYTES monthly counter).
|
|
"""
|
|
import pytest
|
|
|
|
main = pytest.importorskip("main")
|
|
|
|
plan = main.plan_download_attempts
|
|
|
|
STATICS = ["http://s1", "http://s2", "http://s3"]
|
|
PAID = "http://paid"
|
|
|
|
|
|
class TestOrdering:
|
|
def test_full_chain(self):
|
|
got = plan(True, STATICS, PAID, True)
|
|
assert got == [
|
|
('HD-direct', False, None),
|
|
('HD-static1', False, "http://s1"),
|
|
('HD-static2', False, "http://s2"),
|
|
('HD-static3', False, "http://s3"),
|
|
('HD', True, PAID),
|
|
('fallback', True, PAID),
|
|
]
|
|
|
|
def test_statics_only_fallback_uses_a_static(self):
|
|
got = plan(False, STATICS, None, True)
|
|
assert got[-1] == ('fallback', False, "http://s1")
|
|
assert ('HD', False, None) in got # direct HD still tried, uncapped
|
|
|
|
def test_selfhost_no_proxies_matches_legacy_chain(self):
|
|
assert plan(False, [], None, True) == [
|
|
('HD', False, None),
|
|
('fallback', False, None),
|
|
]
|
|
|
|
def test_no_hd_args_still_has_fallback(self):
|
|
assert plan(False, [], PAID, False) == [('fallback', True, PAID)]
|
|
|
|
def test_paid_attempts_are_the_only_capped_ones(self):
|
|
got = plan(True, STATICS, PAID, True)
|
|
for _label, capped, proxy in got:
|
|
assert capped == (proxy == PAID)
|