From ac6536942f3752e321821ac6a5609f04ab90e0d7 Mon Sep 17 00:00:00 2001 From: Nirvana Date: Thu, 12 Mar 2026 11:38:33 +0100 Subject: [PATCH] Add discovery --- lib/streaming_providers/base/models/vod.py | 5 +++ .../providers/magenta2/vod_manager.py | 34 ++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/streaming_providers/base/models/vod.py b/lib/streaming_providers/base/models/vod.py index 3f64c47..822c654 100644 --- a/lib/streaming_providers/base/models/vod.py +++ b/lib/streaming_providers/base/models/vod.py @@ -110,6 +110,10 @@ class VodCategory: # Hint about how many children this node has (may be None if unknown) child_count: Optional[int] = None + # Full API href this category was derived from (e.g. showAllUrl or details.href). + # Stored for convenience / debugging; the content_id already encodes the path. + details_url: Optional[str] = None + # Cached slug (computed lazily if not set) _slug: Optional[str] = field(default=None, repr=False) @@ -133,6 +137,7 @@ class VodCategory: "logo_url": self.logo_url, "description": self.description, "child_count": self.child_count, + "details_url": self.details_url, } diff --git a/lib/streaming_providers/providers/magenta2/vod_manager.py b/lib/streaming_providers/providers/magenta2/vod_manager.py index 53033d3..69c4b3d 100644 --- a/lib/streaming_providers/providers/magenta2/vod_manager.py +++ b/lib/streaming_providers/providers/magenta2/vod_manager.py @@ -138,10 +138,16 @@ class VodManager: node_id = category_path[-1] - if node_id.startswith("lane:"): - flex_id = node_id[5:] + if node_id.startswith("UnstructuredGrid/"): + flex_id = node_id[len("UnstructuredGrid/"):] return self._fetch_lane_items(flex_id, params, page_size=page_size, offset=offset) + if node_id.startswith("VodDetails/"): + # e.g. "VodDetails/202887/GN_SERIES_9370385" → extract the GN id + parts = node_id.split("/") + gn_id = parts[-1] # last segment is always the GN content id + node_id = gn_id + if node_id.startswith(VOD_PREFIX_SEASON): return self._fetch_season_episodes(node_id, params) @@ -283,12 +289,22 @@ class VodManager: if lane_type != "UnstructuredGrid" or not flex_id or not title: continue + # Prefer showAllUrl as the canonical fetch href; fall back to + # constructing it from the flex_id. + show_all_href = (lane.get("showAllUrl") or {}).get("href") or None + content_id = ( + f"UnstructuredGrid/{show_all_href.rstrip('/').rsplit('/UnstructuredGrid/', 1)[-1]}" + if show_all_href and "/UnstructuredGrid/" in show_all_href + else f"UnstructuredGrid/{flex_id}" + ) + categories.append( VodCategory( name=title, - content_id=f"lane:{flex_id}", + content_id=content_id, provider=self._provider, child_count=lane.get("totalCount"), + details_url=show_all_href, ) ) @@ -354,13 +370,23 @@ class VodManager: return None if vod_type == "Series": + details_href = (item.get("details") or {}).get("href") or None + # Extract the path after the base URL, e.g. + # "https://.../VodDetails/202887/GN_SERIES_9370385" + # → "VodDetails/202887/GN_SERIES_9370385" + series_content_id = ( + details_href.split("/v3/")[1].split("?")[0].split("/", 1)[1] + if details_href and "/v3/" in details_href + else content_id + ) return VodCategory( name=title, - content_id=content_id, + content_id=series_content_id, provider=self._provider, logo_url=image_url, description=description, child_count=seasons_available, + details_url=details_href, ) duration_seconds: Optional[int] = int(duration_raw) * 60 if duration_raw else None