feat(dl): add --proxy-download for a separate download proxy

Manifest, licence and auth stay on --proxy; track, subtitle and attachment downloads use the second proxy. Also exposed as proxy_download on the REST download job with the same server_proxy gate. The download session now ignores HTTP(S)_PROXY and copies rnet cookies set by name.
This commit is contained in:
imSp4rky
2026-09-13 14:41:01 -06:00
parent e40421a855
commit a0515f8d57
12 changed files with 156 additions and 15 deletions
+57
View File
@@ -57,3 +57,60 @@ def test_download_with_flag_bypasses_proxy(tmp_path, monkeypatch) -> None:
assert not proxied.got
assert direct.got == [URL]
assert attachment.path is not None and attachment.path.read_bytes() == b"jpegdata"
def test_download_with_proxy_download_uses_only_that_proxy(tmp_path, monkeypatch) -> None:
monkeypatch.setattr(config.directories, "temp", tmp_path)
seen: dict = {}
def fake_direct(session, proxy=None):
seen["proxy"] = proxy
return FakeSession(proxies={"all": proxy})
monkeypatch.setattr(track_module, "direct_session", fake_direct)
proxied = FakeSession(proxies={"https": "http://manifest-proxy:1"})
attachment = Attachment.from_url(URL, name="thumbnail", session=proxied)
attachment.download(proxied, proxy_download="http://dl-proxy:2")
assert not proxied.got
assert seen["proxy"] == "http://dl-proxy:2"
assert proxied.proxies == {"https": "http://manifest-proxy:1"}
def test_no_proxy_download_wins_over_proxy_download(tmp_path, monkeypatch) -> None:
monkeypatch.setattr(config.directories, "temp", tmp_path)
seen: dict = {}
monkeypatch.setattr(
track_module, "direct_session", lambda s, proxy=None: seen.setdefault("p", proxy) or FakeSession()
)
plain = FakeSession()
Attachment.from_url(URL, name="t", session=plain).download(
plain, no_proxy_download=True, proxy_download="http://dl-proxy:2"
)
assert "p" not in seen and plain.got == [URL]
def test_direct_session_routes_through_the_given_proxy() -> None:
base = requests.Session()
base.headers["X-Test"] = "1"
new = track_module.direct_session(base, "http://dl-proxy:2")
assert new.headers["X-Test"] == "1"
assert new.proxies == {"http": "http://dl-proxy:2", "https": "http://dl-proxy:2"}
assert requests.utils.select_proxy("https://cdn.example.com/a", new.proxies) == "http://dl-proxy:2"
def test_direct_session_proxy_beats_environment(monkeypatch) -> None:
monkeypatch.setenv("HTTPS_PROXY", "http://env-proxy:9")
new = track_module.direct_session(requests.Session(), "http://dl-proxy:2")
settings = new.merge_environment_settings("https://cdn.example.com/a", {}, None, None, None)
assert settings["proxies"]["https"] == "http://dl-proxy:2"
def test_direct_session_copies_rnet_cookies_set_by_name() -> None:
from unshackle.core.session import RnetSession
rs = RnetSession()
rs.cookies.set("via_set", "1", domain="cdn.example.com")
rs.cookies["via_item"] = "3"
new = track_module.direct_session(rs, "http://dl-proxy:2")
assert new.cookies.get("via_set") == "1"
assert new.cookies.get("via_item") == "3"