fix(dash): resolve representations by adaptation set, not id alone

Representation ids are only unique within an AdaptationSet, so re-finding a track by id could download a sibling set's stream (audio description in place of dialog). Applies to download_track and extract_dash.
This commit is contained in:
imSp4rky
2026-08-15 14:26:45 -06:00
parent 415a195957
commit e1fbd11678
2 changed files with 66 additions and 24 deletions
+9 -11
View File
@@ -278,24 +278,22 @@ def extract_dash(track: "Track", session: Union[Session, RnetSession]) -> list[S
data = track.data["dash"]
manifest = data["manifest"]
rep_id = data.get("representation_id") or data["representation"].get("id")
adaptation_set = data["adaptation_set"]
representation = data["representation"]
rep_id = data.get("representation_id") or representation.get("id")
filtered_period_ids = data.get("filtered_period_ids", [])
stored_period = data.get("period")
track_url = track.url if isinstance(track.url, str) else track.url[0]
content_periods = [p for p in manifest.findall("Period") if DASH._is_content_period(p, filtered_period_ids)]
raw_segments: list[tuple[str, Optional[str]]] = []
for period in content_periods:
matched_rep = matched_as = None
for as_ in period.findall("AdaptationSet"):
if DASH.is_trick_mode(as_):
continue
for rep in as_.findall("Representation"):
if rep.get("id") == rep_id:
matched_rep, matched_as = rep, as_
break
if matched_rep is not None:
break
# rep ids are only unique within an AdaptationSet, so resolve like DASH.download_track
if period is stored_period:
matched_as, matched_rep = adaptation_set, representation
else:
matched_as, matched_rep = DASH.resolve_representation(period, rep_id, adaptation_set) or (None, None)
if matched_rep is None or matched_as is None:
continue