Improve EPG

This commit is contained in:
Nirvana
2025-12-08 15:26:54 +01:00
parent d8429595d2
commit aa95901c51
5 changed files with 38 additions and 55 deletions
+3 -6
View File
@@ -633,17 +633,14 @@ class ProviderManager:
provider_name: str,
channel_id: Optional[str] = None) -> int:
"""
Get catchup window in days for a provider or specific channel.
Get catchup window in HOURS for a provider or specific channel.
Args:
provider_name: Name of the provider
channel_id: Optional channel identifier for channel-specific window
Returns:
Catchup window in days (0 = no catchup support)
Raises:
ValueError: If provider not found
Catchup window in hours (0 = no catchup support)
"""
provider = self.get_provider(provider_name)
@@ -690,7 +687,7 @@ class ProviderManager:
{
'provider_name': {
'supports_catchup': bool,
'catchup_window': int,
'catchup_window': int, # IN HOURS
'catchup_enabled': bool
}
}
+20 -34
View File
@@ -429,13 +429,10 @@ class StreamingProvider(ABC):
@property
def catchup_window(self) -> int:
"""
Return the catchup window in days for this provider.
Return the catchup window in HOURS for this provider.
Returns:
int: Number of days of catchup available (0 = no catchup support)
Override in subclass to provide provider-specific catchup window.
Default is 0 (no catchup).
int: Number of hours of catchup available (0 = no catchup support)
"""
return 0
@@ -559,9 +556,19 @@ class StreamingProvider(ABC):
# CATCHUP HELPER METHODS
# ============================================================================
def validate_catchup_request(self,
start_time: int,
end_time: int) -> tuple[bool, Optional[str]]:
def get_catchup_window_for_channel(self, channel_id: str) -> int:
"""
Get catchup window for a specific channel in HOURS.
Args:
channel_id: Channel identifier
Returns:
int: Catchup window in hours for this channel
"""
return self.catchup_window
def validate_catchup_request(self, start_time: int, end_time: int) -> tuple[bool, Optional[str]]:
"""
Validate a catchup request against provider's capabilities.
@@ -571,52 +578,31 @@ class StreamingProvider(ABC):
Returns:
Tuple of (is_valid, error_message)
If valid: (True, None)
If invalid: (False, "error description")
"""
import time
# Check if catchup is supported
if not self.supports_catchup:
return False, f"Provider '{self.provider_name}' does not support catchup"
# Validate timestamps
if start_time >= end_time:
return False, "Invalid time range: start_time must be before end_time"
# Check if request is in the future
now = int(time.time())
if start_time > now:
return False, "Cannot request future content"
# Check if content is within catchup window
max_age_seconds = self.catchup_window * 86400 # days to seconds
# CHANGE FROM DAYS TO HOURS HERE
max_age_seconds = self.catchup_window * 3600 # hours to seconds
content_age = now - start_time
if content_age > max_age_seconds:
hours_ago = content_age // 3600
return False, (f"Content is outside catchup window "
f"(requested: {content_age // 86400} days ago, "
f"max: {self.catchup_window} days)")
f"(requested: {hours_ago} hours ago, "
f"max: {self.catchup_window} hours)")
return True, None
def get_catchup_window_for_channel(self, channel_id: str) -> int:
"""
Get catchup window for a specific channel.
Some providers might have different catchup windows for different channels.
Default implementation returns the provider-wide catchup window.
Args:
channel_id: Channel identifier
Returns:
int: Catchup window in days for this channel
Override in subclass if channels have different catchup windows.
"""
return self.catchup_window
def format_catchup_time_params(self,
start_time: int,
end_time: int,
@@ -402,8 +402,8 @@ class Magenta2Provider(StreamingProvider):
@property
def catchup_window(self) -> int:
# This provider offers 7 days of catchup
return 7
# This provider offers 4 hours of catchup
return 4
def get_discovery_status(self) -> Dict[str, Any]:
"""Get discovery and configuration status"""
@@ -129,8 +129,8 @@ class MagentaProvider(StreamingProvider):
@property
def catchup_window(self) -> int:
# This provider offers 7 days of catchup
return 7
# This provider offers 168 hours (7 days) of catchup
return 168
def authenticate(self, **kwargs) -> str:
logger.info(f"=== MagentaProvider.authenticate() CALLED with kwargs: {kwargs} ===")
+11 -11
View File
@@ -479,25 +479,25 @@ class UltimateService:
# Get provider instance to check catchup support
provider_instance = self.manager.get_provider(provider)
provider_catchup_days = getattr(provider_instance, 'catchup_window', 0)
provider_catchup_hours = getattr(provider_instance, 'catchup_window', 0) # CHANGE
# Build channel list with catchup info
channels_data = []
for c in channels:
channel_dict = c.to_dict()
# Add catchup days - use channel-specific if available, else provider default
if hasattr(c, 'catchup_days'):
channel_dict['CatchupDays'] = c.catchup_days
# Add catchup hours - use channel-specific if available, else provider default
if hasattr(c, 'catchup_hours'): # CHANGE
channel_dict['CatchupHours'] = c.catchup_hours # CHANGE
else:
channel_dict['CatchupDays'] = provider_catchup_days
channel_dict['CatchupHours'] = provider_catchup_hours # CHANGE
channels_data.append(channel_dict)
return {
'provider': provider,
'country': provider_instance.country if provider_instance else 'DE',
'catchup_window_days': provider_catchup_days,
'catchup_window_hours': provider_catchup_hours, # CHANGE
'channels': channels_data
}
except Exception as api_err:
@@ -565,20 +565,20 @@ class UltimateService:
# Validate catchup is supported
provider_instance = self.manager.get_provider(provider)
catchup_window = getattr(provider_instance, 'catchup_window', 0)
catchup_hours = getattr(provider_instance, 'catchup_window', 0) # Now in hours
if catchup_window == 0:
if catchup_hours == 0:
response.status = 400
return {'error': f'Catchup not supported for provider "{provider}"'}
# Validate time is within catchup window
# Validate time is within catchup window (in HOURS)
import time
now = int(time.time())
max_age_seconds = catchup_window * 86400
max_age_seconds = catchup_hours * 3600 # Hours to seconds
if (now - start_time_int) > max_age_seconds:
response.status = 400
return {'error': f'Content outside catchup window (max {catchup_window} days)'}
return {'error': f'Content outside catchup window (max {catchup_hours} hours)'}
# Check if provider needs proxy for catchup
if self.manager.needs_proxy(provider):