fix(services): route a service remote from services.<TAG>.dl.remote

Click picks the subcommand before the dl callback applies the service config, so Services.resolve_command now applies remote and server first. A REST API job routes from its request only.
This commit is contained in:
imSp4rky
2026-10-19 14:19:07 -06:00
parent 4728ac593c
commit 3aaf9c4107
8 changed files with 208 additions and 21 deletions
+9 -5
View File
@@ -70,7 +70,7 @@ from unshackle.core.proxies.resolve import (
split_proxy_query,
)
from unshackle.core.service import Service, grow_session_pool
from unshackle.core.services import Services
from unshackle.core.services import ROUTING_PARAMS, Services
from unshackle.core.temp import with_task_temp
from unshackle.core.title_cacher import get_account_hash
from unshackle.core.titles import Movie, Movies, Series, Song, Title_T
@@ -461,9 +461,13 @@ def cut_music_sample(title: Any, window: tuple[int, int], log: logging.Logger) -
def apply_service_dl_overrides(ctx: click.Context, service_dl_config: dict[str, Any], log: logging.Logger) -> None:
"""Apply ``services.<TAG>.dl`` config onto ``ctx.params``. Explicit CLI/env values win.
The config replaces defaults and global ``dl:`` default_map values."""
The config replaces defaults and global ``dl:`` default_map values.
``remote`` and ``server`` are skipped: they pick the code that runs, so ``Services.resolve_command`` sets
them before the service loads, and an API job takes them from its request."""
params_by_name = {param.name: param for param in ctx.command.params if param.name}
for name, value in normalize_dl_config(service_dl_config).items():
if name in ROUTING_PARAMS:
continue
param = params_by_name.get(name)
if param is None:
log.warning(f"Ignoring unknown dl option '{name}' in service config")
@@ -1280,7 +1284,7 @@ class dl:
self.service = Services.get_tag(ctx.invoked_subcommand)
self.vault_service = Services.get_vault_tag(self.service)
apply_service_dl_overrides(ctx, config.services.get(self.service, {}).get("dl", {}), self.log)
apply_service_dl_overrides(ctx, (ci_get(config.services, self.service) or {}).get("dl") or {}, self.log)
# Refresh locals Click bound before the overrides ran.
no_proxy = ctx.params.get("no_proxy", no_proxy)
@@ -1458,9 +1462,9 @@ class dl:
)
except KeyError:
pass
merge_dict(config.services.get(self.service), self.service_config)
merge_dict(ci_get(config.services, self.service), self.service_config)
service_config = config.services.get(self.service, {})
service_config = ci_get(config.services, self.service, {})
if service_config:
reserved_keys = {
"profiles",