feat(api): forward exact_lang to the service context

The remote-dl client sends exact_lang in dl_params, and REST download jobs set it in the service ctx, so a service can skip the manifests of close-match languages.
This commit is contained in:
imSp4rky
2026-10-13 15:07:01 -06:00
parent 3e64a7d684
commit 4fbaf2a61a
9 changed files with 38 additions and 17 deletions
+12 -4
View File
@@ -192,10 +192,17 @@ class _CapturedCtx(Exception):
@pytest.mark.parametrize(
("params", "expected"),
[
({}, (["orig"], [], [], [], False)),
({}, (["orig"], [], [], [], False, False)),
(
{"lang": ["es-419"], "v_lang": ["en"], "a_lang": ["ja"], "acodec": "AAC,EC3", "forced_subs": True},
(["es-419"], ["en"], ["ja"], ["AAC", "EC3"], True),
{
"lang": ["es-419"],
"v_lang": ["en"],
"a_lang": ["ja"],
"acodec": "AAC,EC3",
"forced_subs": True,
"exact_lang": True,
},
(["es-419"], ["en"], ["ja"], ["AAC", "EC3"], True, True),
),
],
)
@@ -224,7 +231,8 @@ def test_perform_download_puts_the_lang_selection_in_the_service_ctx(
ctx = exc.value.args[0]
p = ctx.params
assert (p["lang"], p["v_lang"], p["a_lang"], [c.name for c in p["acodec"]], p["forced_subs"]) == expected
selection = (p["lang"], p["v_lang"], p["a_lang"], [c.name for c in p["acodec"]], p["forced_subs"], p["exact_lang"])
assert selection == expected
def test_perform_download_passes_latest_episodes_to_dl_result(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -616,6 +616,7 @@ def test_dl_selection_travels_nested_and_a_service_option_cannot_override_it() -
"a_lang": [],
"acodec": [Audio.Codec.EC3],
"forced_subs": True,
"exact_lang": True,
}
data = _sent_create_data(parent_params, {"lang": 3, "a_lang": "x"})
assert data["dl_params"] == {
@@ -624,6 +625,7 @@ def test_dl_selection_travels_nested_and_a_service_option_cannot_override_it() -
"a_lang": [],
"acodec": ["EC3"],
"forced_subs": True,
"exact_lang": True,
}
assert data["lang"] == 3
assert data["service_params"] == {"lang": 3, "a_lang": "x"}
+11 -6
View File
@@ -162,6 +162,9 @@ def _create_with_real_ctx(monkeypatch, data):
return svc
DL_DEFAULTS = {"lang": ["orig"], "v_lang": [], "a_lang": [], "acodec": [], "forced_subs": False, "exact_lang": False}
def test_nested_dl_params_reach_the_parent_ctx(monkeypatch):
from unshackle.core.tracks import Audio
@@ -172,6 +175,7 @@ def test_nested_dl_params_reach_the_parent_ctx(monkeypatch):
"a_lang": ["es-419"],
"acodec": ["EC3", "NOPE", "AAC"],
"forced_subs": True,
"exact_lang": True,
}
}
svc = _create_with_real_ctx(monkeypatch, data)
@@ -180,12 +184,13 @@ def test_nested_dl_params_reach_the_parent_ctx(monkeypatch):
assert svc.parent_params["a_lang"] == ["es-419"]
assert svc.parent_params["acodec"] == [Audio.Codec.EC3, Audio.Codec.AAC]
assert svc.parent_params["forced_subs"] is True
assert svc.parent_params["exact_lang"] is True
def test_absent_dl_params_fall_back_to_the_dl_defaults(monkeypatch):
svc = _create_with_real_ctx(monkeypatch, {})
selection = {k: svc.parent_params[k] for k in ("lang", "v_lang", "a_lang", "acodec", "forced_subs")}
assert selection == {"lang": ["orig"], "v_lang": [], "a_lang": [], "acodec": [], "forced_subs": False}
selection = {k: svc.parent_params[k] for k in (*DL_DEFAULTS,)}
assert selection == DL_DEFAULTS
def test_an_empty_lang_list_is_kept(monkeypatch):
@@ -204,14 +209,14 @@ def test_a_service_lang_option_never_gets_the_dl_lang(monkeypatch):
"dl_params",
[
"en",
{"lang": "en", "v_lang": "ja", "a_lang": {"x": 1}, "acodec": "EC3", "forced_subs": "yes"},
{"lang": [1], "v_lang": [None], "a_lang": ["en", None], "acodec": [3], "forced_subs": 1},
{"lang": "en", "v_lang": "ja", "a_lang": {"x": 1}, "acodec": "EC3", "forced_subs": "yes", "exact_lang": "yes"},
{"lang": [1], "v_lang": [None], "a_lang": ["en", None], "acodec": [3], "forced_subs": 1, "exact_lang": 1},
],
)
def test_malformed_dl_params_are_ignored(monkeypatch, dl_params):
svc = _create_with_real_ctx(monkeypatch, {"dl_params": dl_params})
selection = {k: svc.parent_params[k] for k in ("lang", "v_lang", "a_lang", "acodec", "forced_subs")}
assert selection == {"lang": ["orig"], "v_lang": [], "a_lang": [], "acodec": [], "forced_subs": False}
selection = {k: svc.parent_params[k] for k in (*DL_DEFAULTS,)}
assert selection == DL_DEFAULTS
def test_profile_reaches_the_parent_ctx_params(monkeypatch):