feat(search): add ANONYMOUS_SEARCH to skip the login for a service

A service that sets the flag gets no cookie load, no authenticate() call and no cookie save on a search, on the CLI and in the REST search handler. /api/services reports it as anonymous_search.
This commit is contained in:
imSp4rky
2026-10-10 13:21:14 -06:00
parent 0cded6427f
commit 0a7c76561c
12 changed files with 121 additions and 13 deletions
+8 -7
View File
@@ -96,12 +96,13 @@ def result(service: Service, profile: Optional[str] = None, **_: Any) -> None:
service_tag = service.__class__.__name__
with console.status("Authenticating with Service...", spinner="dots"):
cookies = dl.get_cookie_jar(service_tag, profile)
credential = dl.get_credentials(service_tag, profile)
service.authenticate(cookies, credential)
if cookies or credential:
log.info("Authenticated with Service")
if not service.ANONYMOUS_SEARCH:
with console.status("Authenticating with Service...", spinner="dots"):
cookies = dl.get_cookie_jar(service_tag, profile)
credential = dl.get_credentials(service_tag, profile)
service.authenticate(cookies, credential)
if cookies or credential:
log.info("Authenticated with Service")
search_results = Tree("Search Results", hide_root=True)
with console.status("Searching...", spinner="dots"):
@@ -116,7 +117,7 @@ def result(service: Service, profile: Optional[str] = None, **_: Any) -> None:
result_text += f"\n[bright_black]id: {result.id}[/]"
search_results.add(result_text + "\n")
cookie_file = dl.get_cookie_path(service_tag, profile)
cookie_file = None if service.ANONYMOUS_SEARCH else dl.get_cookie_path(service_tag, profile)
if cookie_file:
dl.save_cookies(cookie_file, service.session.cookies)
+9 -3
View File
@@ -460,6 +460,8 @@ def run_service_search(
The same preamble as :func:`setup_list_service`, without the service option extras,
plus the search itself. Every step blocks on disk or network, so the caller runs the
whole function in one worker thread and keeps the event loop free for other clients.
The server account check and its cache directory apply to an ``ANONYMOUS_SEARCH`` service too.
"""
profile = client_profile(data)
@@ -473,7 +475,11 @@ def run_service_search(
profile = None if account == "default" else account
cdm = load_full_cdm(normalized_service, profile, data.get("cdm_type"))
cookies, credential = server_login_material(data, normalized_service, account, profile)
service_module = Services.load(normalized_service)
anonymous = getattr(service_module, "ANONYMOUS_SEARCH", False)
cookies, credential = (
(None, None) if anonymous else server_login_material(data, normalized_service, account, profile)
)
parent_ctx = build_parent_ctx(
profile,
@@ -484,7 +490,6 @@ def run_service_search(
service_config,
extra_params={"cookies_supplied": cookies is not None},
)
service_module = Services.load(normalized_service)
from click import ClickException
@@ -505,7 +510,8 @@ def run_service_search(
client_login = cookies is not None or credential is not None
request_cache.attach(service_instance, data, normalized_service, request, client_login)
service_instance._input_bridge = NoUserBridge()
service_instance.authenticate(cookies, credential)
if not anonymous:
service_instance.authenticate(cookies, credential)
results: List[Dict[str, Any]] = []
try:
+2 -1
View File
@@ -388,6 +388,7 @@ async def services(request: web.Request) -> web.Response:
if client_config:
service_data["client_config"] = list(client_config)
service_data["has_search"] = getattr(service_module, "search", None) is not _BaseService.search
service_data["anonymous_search"] = bool(getattr(service_module, "ANONYMOUS_SEARCH", False))
service_data["has_drm"] = (
getattr(service_module, "get_widevine_license", None) is not _BaseService.get_widevine_license
or getattr(service_module, "get_playready_license", None) is not _BaseService.get_playready_license
@@ -435,7 +436,7 @@ async def search(request: web.Request) -> web.Response:
Find titles from a service.
---
summary: Find titles
description: Find titles by query string from a service
description: Find titles by query string from a service. A service that reports anonymous_search does the search with no login, and ignores credentials and cookies.
requestBody:
required: true
content:
+3 -1
View File
@@ -158,6 +158,7 @@ class Service(metaclass=ABCMeta):
GEOBLOCK: tuple[str, ...] = () # ip regions where the service refuses to work; everything else is allowed.
ANIME: bool = False # service catalogue is anime; metadata lookups prefer AniList. Title.anime overrides per title.
DAILY: bool = False # catalog is daily/date-based. episodes are named by air date. Title.daily overrides per title.
ANONYMOUS_SEARCH: bool = False # search() needs no login; a search then skips cookies and authenticate().
# vault namespace override; when set, key vault read/write uses this tag instead of the service's own.
VAULT_TAG: Optional[str] = None
# Auth methods the service accepts ("cookies"/"credentials"); when None the REST /services
@@ -456,7 +457,8 @@ class Service(metaclass=ABCMeta):
This is effectively a login() function. Any API calls or object initializations
needing to be made, should be made here. unshackle operates this method before
any of the following abstract functions.
any of the following abstract functions. The one exception is a search on a
Service that sets ``ANONYMOUS_SEARCH``, which does not operate this method.
You should avoid storing or using the Credential outside this function.
Make any calls you need for any Cookies, Tokens, or such, then use those.
+3
View File
@@ -79,6 +79,9 @@ class EXAMPLE(Service):
# ANIME: this catalogue is anime, so metadata lookups ask AniList first. Set it False (the
# default) on a mixed catalogue and flag the anime titles individually in get_titles().
ANIME = True
# ANONYMOUS_SEARCH: set True only when search() needs no login and no state from
# authenticate(). A search then skips the cookie load, authenticate() and the cookie save.
ANONYMOUS_SEARCH = False
# VAULT_TAG: store/read keys under a different vault namespace than this service's tag.
# Lets sibling services share one key vault. Omit to use the service's own tag.
VAULT_TAG = "DIFFERENT_NAME"