forked from kenzuya/unshackle
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:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user