fix(hls): give a variant or media entry listed twice one track

This commit is contained in:
imSp4rky
2026-11-29 20:32:24 -07:00
parent 4bcc15dfc4
commit 30ed17054d
2 changed files with 51 additions and 2 deletions
+10 -2
View File
@@ -192,6 +192,7 @@ class HLS:
All Track objects' URL will be to another M3U(8) document. However, these documents
will be Invariant Playlists and contain the list of segments URIs among other metadata.
A variant or a media entry that the master lists twice gets one track.
"""
session_keys = list(self.manifest.session_keys or [])
if not session_keys:
@@ -236,7 +237,12 @@ class HLS:
(raw.get("stream_info") or {}).get("req_video_layout")
for raw in (getattr(self.manifest, "data", None) or {}).get("playlists", [])
]
variants: set[str] = set()
for playlist, video_layout in zip(self.manifest.playlists, video_layouts, strict=False):
variant = str(playlist)
if variant in variants:
continue
variants.add(variant)
video_codec: Video.Codec | None = None
audio_codec: Audio.Codec | None = None
primary_track_type: type[Audio] | type[Video]
@@ -273,7 +279,7 @@ class HLS:
tracks.add(
primary_track_type(
id_=hex(crc32(str(playlist).encode()))[2:],
id_=hex(crc32(variant.encode()))[2:],
url=urljoin(playlist.base_uri, playlist.uri),
codec=cast(Any, video_codec or audio_codec),
language=language, # HLS manifests do not seem to have language info
@@ -302,9 +308,11 @@ class HLS:
)
)
entries: set[str] = set()
for media in self.manifest.media:
if not media.uri:
if not media.uri or str(media) in entries:
continue
entries.add(str(media))
joc = 0
track_type: type[Audio] | type[Subtitle]