Files
unshackle/tests/core/test_hls_repeated_entries.py
T

42 lines
1.5 KiB
Python

"""A master playlist that lists one variant or one media entry twice gives one track, not an error.
Some manifest proxies list a rendition twice now and then. The track id is a hash of the entry, so the second
copy raised "Duplicate track ID" and failed the whole title.
"""
from __future__ import annotations
from unshackle.core.manifests.hls import HLS
URL = "https://example.test/master.m3u8"
AUDIO = '#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="en",NAME="English",LANGUAGE="en",CHANNELS="2",URI="audio/en.m3u8"'
def variant(bandwidth: int, path: str) -> str:
return (
f'#EXT-X-STREAM-INF:BANDWIDTH={bandwidth},RESOLUTION=3840x2160,CODECS="hvc1.2.4.L153.B0,mp4a.40.2",AUDIO="en"\n'
f"{path}\n"
)
def tracks(text: str):
return HLS.from_text(f"#EXTM3U\n{text}", URL).to_tracks(language="en")
def test_a_variant_listed_twice_gets_one_track() -> None:
result = tracks(variant(5_000_000, "video/uhd.m3u8") * 2)
assert [str(video.url) for video in result.videos] == ["https://example.test/video/uhd.m3u8"]
def test_a_media_entry_listed_twice_gets_one_track() -> None:
result = tracks(AUDIO + "\n" + AUDIO + "\n" + variant(5_000_000, "video/uhd.m3u8"))
assert [str(audio.url) for audio in result.audio] == ["https://example.test/audio/en.m3u8"]
def test_variants_with_the_same_attributes_and_other_links_stay_apart() -> None:
result = tracks(variant(5_000_000, "video/uhd.m3u8") + variant(5_000_000, "mirror/uhd.m3u8"))
assert len(result.videos) == 2