From 8439a38fa941090975d258721c272dc1b539ef9b Mon Sep 17 00:00:00 2001 From: Nirvana Date: Fri, 6 Mar 2026 11:50:08 +0100 Subject: [PATCH] Add discovery --- .../base/utils/mpd_rewriter.py | 57 +++++++------------ 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/lib/streaming_providers/base/utils/mpd_rewriter.py b/lib/streaming_providers/base/utils/mpd_rewriter.py index fe1ecda..8d83d44 100644 --- a/lib/streaming_providers/base/utils/mpd_rewriter.py +++ b/lib/streaming_providers/base/utils/mpd_rewriter.py @@ -849,45 +849,24 @@ class MPDRewriter: if current_encrypted and not self.key_config.single_key_mode: current_kid = as_id_to_kid.get(unique_id) + # Handle BaseURL elements at any level + if element.tag.endswith("BaseURL") and element.text: + raw_url = element.text.strip() + if raw_url: + # Resolve the relative BaseURL against the current base + resolved_cdn_url = self._urljoin_preserve_query(base_url, raw_url) + + # Rewrite the BaseURL text to a proxy URL + element.text = self.build_proxy_url( + resolved_cdn_url, None, None, + current_encrypted, current_kid, + representation_id=current_rep_id + ) + # Track representation ID for template substitution. - # For SegmentBase manifests, also handle + - # together here at the Representation level, so both share the same - # resolved CDN URL without risk of double-proxying. if element.tag.endswith("Representation"): current_rep_id = element.get("id", "") - # Detect SegmentBase pattern: a Representation with a child. - # We rewrite the text to a proxy URL here at the Representation - # level so we have control over the resolved CDN URL before recursion - # descends into children. - base_url_child = None - for child in element: - if child.tag.endswith("BaseURL") and child.text: - base_url_child = child - break - - if base_url_child is not None: - raw_url = base_url_child.text.strip() - if raw_url: - # Resolve the relative BaseURL against the current base. - resolved_cdn_url = self._urljoin_preserve_query(base_url, raw_url) - - # Rewrite the text to a proxy URL. - # For SegmentBase manifests the player uses for ALL - # requests (init segment, index, and media), issuing HTTP Range - # requests as directed by indexRange / . - # No sourceURL is needed — the range attribute on - # stays untouched and the player combines it with the proxied - # automatically. - base_url_child.text = self.build_proxy_url( - resolved_cdn_url, None, None, - current_encrypted, current_kid, - representation_id=current_rep_id, - ) - - # Update base_url for any further descendants. - base_url = resolved_cdn_url - # ------------------------------------------------------------------ # Standard SegmentTemplate / SegmentList attribute rewriting. # Handles media/initialization/sourceURL attributes on SegmentTemplate, @@ -932,6 +911,14 @@ class MPDRewriter: representation_id=current_rep_id ) + # Handle any other URL-like attributes that might contain segment URLs + # This catches things like SegmentTemplate@index, etc. + url_attrs = ["index", "range", "indexRange"] + for attr in url_attrs: + if attr in element.attrib and element.attrib[attr] and not attr == "range" and not attr == "indexRange": + # These are usually just range values, not URLs, so skip + continue + # Recurse to children (but skip if we already handled Period children) for child in element: # Skip if this is a Period element - we handle them separately at the top level