From 271b701e07782eae96b7cb5681f23b0b3ceb8e6f Mon Sep 17 00:00:00 2001 From: Nirvana Date: Sat, 20 Dec 2025 14:55:15 +0100 Subject: [PATCH] Add web config --- .../providers/auth_context.py | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/streaming_providers/providers/auth_context.py b/lib/streaming_providers/providers/auth_context.py index 54475e8..5f38c00 100644 --- a/lib/streaming_providers/providers/auth_context.py +++ b/lib/streaming_providers/providers/auth_context.py @@ -21,14 +21,47 @@ class AuthContext: def get_token(self, provider_name: str, scope: str = None, country: str = None) -> Optional[Dict[str, Any]]: - """Get token for provider (scoped or root-level)""" + """ + Get token for provider (scoped or root-level). + + Now with fallback: tries with country first, then without country + for backward compatibility with tokens stored without country nesting. + + Args: + provider_name: Provider name + scope: Optional token scope + country: Optional country code + + Returns: + Token data dictionary or None + """ if not self.session: return None + # Try with country first (new format) + if country: + if scope: + token = self.session.load_scoped_token(provider_name, scope, country) + else: + token = self.session.load_token_data(provider_name, country) + + if token: + return token + + # Fallback: try without country (legacy format) + # This handles tokens stored as {"provider": {...}} instead of {"provider": {"country": {...}}} + if scope: + token = self.session.load_scoped_token(provider_name, scope, None) + else: + token = self.session.load_token_data(provider_name, None) + + return token + + # No country specified - direct lookup if scope: - return self.session.load_scoped_token(provider_name, scope, country) + return self.session.load_scoped_token(provider_name, scope, None) else: - return self.session.load_token_data(provider_name, country) + return self.session.load_token_data(provider_name, None) def get_all_scopes(self, provider_name: str, country: str = None) -> List[str]: """Get all token scopes for provider"""