diff --git a/lib/streaming_providers/base/provider.py b/lib/streaming_providers/base/provider.py index 219dc37..3f789e9 100644 --- a/lib/streaming_providers/base/provider.py +++ b/lib/streaming_providers/base/provider.py @@ -27,6 +27,8 @@ class StreamingProvider(ABC): Abstract base class for streaming providers with centralized HTTP and auth management """ + SUPPORTED_COUNTRIES: List[str] = [] + def __init__(self, country: str = 'DE'): self.country = country self.channels: List[StreamingChannel] = [] @@ -697,4 +699,42 @@ class StreamingProvider(ABC): else: # Default to query parameters separator = '&' if '?' in base_url else '?' - return f"{base_url}{separator}start={start_time}&end={end_time}" \ No newline at end of file + return f"{base_url}{separator}start={start_time}&end={end_time}" + + @classmethod + def get_supported_countries(cls) -> List[str]: + """ + Get list of countries supported by this provider. + + Returns: + List of ISO country codes (e.g., ['de', 'at', 'ch']) + Empty list means single-country provider using default country + """ + return cls.SUPPORTED_COUNTRIES.copy() + + @classmethod + def supports_multiple_countries(cls) -> bool: + """ + Check if this provider supports multiple countries. + + Returns: + True if provider supports country-specific instances + """ + return len(cls.SUPPORTED_COUNTRIES) > 0 + + @classmethod + def validate_country(cls, country: str) -> bool: + """ + Validate if a country is supported by this provider. + + Args: + country: ISO country code to validate + + Returns: + True if country is supported or provider is single-country + """ + if not cls.supports_multiple_countries(): + # Single-country providers accept any country (or ignore it) + return True + + return country.lower() in [c.lower() for c in cls.SUPPORTED_COUNTRIES] \ No newline at end of file diff --git a/lib/streaming_providers/providers/joyn/provider.py b/lib/streaming_providers/providers/joyn/provider.py index ea34a3e..44c13b1 100644 --- a/lib/streaming_providers/providers/joyn/provider.py +++ b/lib/streaming_providers/providers/joyn/provider.py @@ -89,6 +89,13 @@ class JoynProvider(StreamingProvider): proxy_config: Optional proxy configuration (highest priority) proxy_url: Optional proxy URL string (medium priority) """ + if not self.validate_country(country): + supported = ', '.join(self.SUPPORTED_COUNTRIES) + raise ValueError( + f"Unsupported country: {country}. " + f"Joyn supports: {supported}" + ) + super().__init__(country=country) if country not in SUPPORTED_COUNTRIES: diff --git a/lib/streaming_providers/providers/magentaeu/provider.py b/lib/streaming_providers/providers/magentaeu/provider.py index 87ffdff..77bfa50 100644 --- a/lib/streaming_providers/providers/magentaeu/provider.py +++ b/lib/streaming_providers/providers/magentaeu/provider.py @@ -39,6 +39,12 @@ class MagentaProvider(StreamingProvider): proxy_url: Optional[str] = None): logger.info(f"=== MagentaProvider.__init__ START for country: {country} ===") + if not self.validate_country(country): + supported = ', '.join(self.SUPPORTED_COUNTRIES) + raise ValueError( + f"Unsupported country: {country}. " + f"MagentaTV EU supports: {supported}" + ) super().__init__(country=country) if country not in SUPPORTED_COUNTRIES: @@ -474,7 +480,7 @@ class MagentaProvider(StreamingProvider): logger.debug(f"Credential validation failed: {e}") return False - @staticmethod - def get_supported_countries() -> List[str]: + @classmethod + def get_supported_countries(cls) -> List[str]: """Get list of supported countries""" - return SUPPORTED_COUNTRIES.copy() \ No newline at end of file + return cls.SUPPORTED_COUNTRIES.copy() \ No newline at end of file