Add discovery

This commit is contained in:
Nirvana
2026-03-09 22:42:47 +01:00
parent 8b8ac94489
commit 7996bbafe6
3 changed files with 40 additions and 15 deletions
@@ -111,6 +111,20 @@ class RTLPlusAuthenticator(BaseOAuth2Authenticator):
scope=response_data.get("scope", ""),
)
def get_current_token_level(self) -> "TokenAuthLevel":
"""
Return the auth level of whichever token the base class currently holds.
Walks the common attribute names used by BaseOAuth2Authenticator to
store the active token, classifies it via _classify_token, and returns
UNKNOWN if no token is found.
"""
for attr in ("token", "_token", "current_token", "_current_token", "_access_token"):
tok = getattr(self, attr, None)
if tok is not None:
return self._classify_token(tok)
return TokenAuthLevel.UNKNOWN
def get_fallback_credentials(self):
"""Get fallback credentials (anonymous client credentials)"""
return self._get_default_credentials()
@@ -367,4 +381,4 @@ class RTLPlusAuthenticator(BaseOAuth2Authenticator):
if self.has_user_credentials() and hasattr(self.credentials, "username"):
status["username"] = self.credentials.username
return status
return status
@@ -98,23 +98,13 @@ class RTLPlusProvider(StreamingProvider):
Get headers with authentication and RTL+ specific headers.
Upgrades from anonymous to user token only when user credentials are
configured but a user-level token has not yet been obtained, preventing
redundant re-authentication on every subsequent request.
configured and the current token is not already at user level. This
prevents a full re-authentication round-trip on every single request
once a valid user token is already held.
"""
from ...base.auth.base_auth import TokenAuthLevel
# Determine whether an upgrade attempt is warranted:
# - User credentials are stored → we *want* a user token
# - Current token is not yet at user level → upgrade is needed
# Once a user token is live, _classify_token returns USER_AUTHENTICATED
# and we skip the expensive re-auth entirely.
current_token = getattr(self.authenticator, "token", None) or \
getattr(self.authenticator, "_token", None)
current_level = (
self.authenticator._classify_token(current_token)
if current_token
else TokenAuthLevel.UNKNOWN
)
current_level = self.authenticator.get_current_token_level()
force_upgrade = (
self.authenticator.has_user_credentials()
and current_level != TokenAuthLevel.USER_AUTHENTICATED
@@ -104,7 +104,28 @@ class RTLPlusVodManager:
Depth 2, series-genre → Series VodItems for a genre (OverviewPage SERIES)
Depth 2, topic → Season list for a Format
Depth 3 → Episode list for a Season
Path normalisation
------------------
Callers may pass the watch-path either as a single element
("/video-tv/serien") or pre-split without a leading slash
(["video-tv", "serien"]). We reassemble and re-prefix so that all
downstream checks see a consistent leading-slash watch-path in [0].
"""
# Reassemble paths that were split on "/" without a leading slash,
# e.g. ["video-tv", "serien"] → ["/video-tv/serien"]
# Leave RRNs ("rrn:…") and already-slash-prefixed paths untouched.
if (
category_path
and not category_path[0].startswith("/")
and not category_path[0].startswith("rrn:")
and not category_path[0].startswith("season:")
and not category_path[0].startswith("movies-genre:")
and not category_path[0].startswith("series-genre:")
):
# Rejoin all segments as a single watch-path element
category_path = ["/" + "/".join(category_path)]
depth = len(category_path)
if depth == 0: