From 9bdaa19145e41d673639c5971a0b559e332bc352 Mon Sep 17 00:00:00 2001 From: Nirvana Date: Fri, 1 May 2026 11:36:08 +0200 Subject: [PATCH] Prepare RTLPlus for new streaming prov --- .../providers/rtlplus/event_manager.py | 2 +- .../providers/rtlplus/provider.py | 26 +------- routes/streams.py | 62 +++++++++---------- 3 files changed, 30 insertions(+), 60 deletions(-) diff --git a/lib/streaming_providers/providers/rtlplus/event_manager.py b/lib/streaming_providers/providers/rtlplus/event_manager.py index 3340e33..bc29644 100644 --- a/lib/streaming_providers/providers/rtlplus/event_manager.py +++ b/lib/streaming_providers/providers/rtlplus/event_manager.py @@ -142,7 +142,7 @@ class RTLPlusEventManager: manifest_url = self._provider.extract_best_manifest_url(assets) if manifest_url: logger.debug(f"Found manifest for event {event_id}: {manifest_url}") - return self._provider.resolve_redirect(manifest_url) + return manifest_url return None diff --git a/lib/streaming_providers/providers/rtlplus/provider.py b/lib/streaming_providers/providers/rtlplus/provider.py index 089690d..f0e99f1 100644 --- a/lib/streaming_providers/providers/rtlplus/provider.py +++ b/lib/streaming_providers/providers/rtlplus/provider.py @@ -342,30 +342,6 @@ class RTLPlusProvider(StreamingProvider): return None - def resolve_redirect(self, url: str) -> str: - """ - Resolve HTTP redirects to get final manifest URL. - """ - if not url: - return url - - try: - response = self.http_manager.head( - url, - headers={"User-Agent": self.rtl_config.user_agent}, - follow_redirects=False, - timeout=10 - ) - if 300 <= response.status_code < 400: - location = response.headers.get("location") - if location: - logger.debug(f"Resolved redirect: {url} -> {location}") - return location - except Exception as e: - logger.debug(f"Redirect resolution failed: {e}") - - return url - def invalidate_layout_cache(self, cache_key: str = None): """Invalidate layout cache for a specific key or all keys.""" if cache_key: @@ -527,7 +503,7 @@ class RTLPlusProvider(StreamingProvider): if manifest_url: logger.info(f"Found manifest URL for {content_id}: {manifest_url[:100]}...") - return self.resolve_redirect(manifest_url) + return manifest_url logger.warning(f"No suitable manifest URL found for {content_id}") return None diff --git a/routes/streams.py b/routes/streams.py index db23e4b..e7c5fe3 100644 --- a/routes/streams.py +++ b/routes/streams.py @@ -865,14 +865,31 @@ def setup_stream_routes(app, manager, service): # /drm → returns raw DRM configs # ========================================================================= + @app.route("/api/providers//vod//stream/index.mpd") + def get_vod_stream(provider, path): + # Extract vod_id as the first segment before any slashes + # Example: "clip_1417600/stream" -> "clip_1417600" + vod_id = path.split("/")[0] + + try: + country = request.query.get("country") + return _resolve_stream( + CONTENT_TYPE_VOD, provider, vod_id, country=country + ) + except HTTPResponse: + raise + except ValueError as e: + logger.error(f"stream error for VOD {provider}/{vod_id}: {e}") + response.status = 404 + return {"error": str(e)} + except Exception as e: + logger.error(f"stream error for VOD {provider}/{vod_id}: {e}") + response.status = 500 + return {"error": f"Internal server error: {str(e)}"} + @app.route("/api/providers//vod//manifest") def get_vod_stream_manifest(provider, path): - """ - Returns JSON with a manifest_url pointing to the VOD stream endpoint. - The last segment of is the vod_id (edit_id / content_id). - Attaches x-kodi-drm-configs header. - """ - vod_id = path.rstrip("/").rsplit("/", 1)[-1] + vod_id = path.split("/")[0] # Fix here too try: country = request.query.get("country") base_url = f"{request.urlparts.scheme}://{request.urlparts.netloc}" @@ -900,46 +917,23 @@ def setup_stream_routes(app, manager, service): response.status = 500 return {"error": f"Internal server error: {str(e)}"} - @app.route("/api/providers//vod//stream/index.mpd") - def get_vod_stream(provider, path): - vod_id = path.rstrip("/").rsplit("/", 1)[-1] - try: - country = request.query.get("country") - return _resolve_stream( - CONTENT_TYPE_VOD, provider, vod_id, country=country - ) - except HTTPResponse: - raise - except ValueError as e: - logger.error(f"stream error for VOD {provider}/{vod_id}: {e}") - response.status = 404 - return {"error": str(e)} - except Exception as e: - logger.error(f"stream error for VOD {provider}/{vod_id}: {e}") - response.status = 500 - return {"error": f"Internal server error: {str(e)}"} - - @app.route( - "/api/providers//vod//stream/decrypted/index.mpd" - ) + @app.route("/api/providers//vod//stream/decrypted/index.mpd") def get_vod_stream_decrypted(provider, path): - vod_id = path.rstrip("/").rsplit("/", 1)[-1] + vod_id = path.split("/")[0] # Fix here too return _resolve_decrypted_stream( CONTENT_TYPE_VOD, provider, vod_id, highest_quality_only=False ) - @app.route( - "/api/providers//vod//stream/decrypted/ffmpeg/index.mpd" - ) + @app.route("/api/providers//vod//stream/decrypted/ffmpeg/index.mpd") def get_vod_stream_decrypted_ffmpeg(provider, path): - vod_id = path.rstrip("/").rsplit("/", 1)[-1] + vod_id = path.split("/")[0] # Fix here too return _resolve_decrypted_stream( CONTENT_TYPE_VOD, provider, vod_id, highest_quality_only=True ) @app.route("/api/providers//vod//drm") def get_vod_drm(provider, path): - vod_id = path.rstrip("/").rsplit("/", 1)[-1] + vod_id = path.split("/")[0] # Fix here too try: country = request.query.get("country") drm_configs = _get_drm_configs(