fix(hls): refuse key tags the DRM of the track cannot decrypt

This commit is contained in:
imSp4rky
2026-11-29 22:07:43 -07:00
parent ba2911056d
commit f0163439d4
5 changed files with 123 additions and 26 deletions
+51
View File
@@ -6,6 +6,8 @@ copy raised "Duplicate track ID" and failed the whole title.
from __future__ import annotations
import pytest
from unshackle.core.manifests.hls import HLS
URL = "https://example.test/master.m3u8"
@@ -39,3 +41,52 @@ 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
PLAIN = '#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=3840x2160,CODECS="hvc1.2.4.L153.B0",VIDEO-RANGE=PQ'
COMPOSITE = PLAIN + ',SUPPLEMENTAL-CODECS="dvh1.08.06/db1p"'
def test_variants_of_one_link_with_another_video_range_stay_apart() -> None:
result = tracks(f"{PLAIN}\nuhd.m3u8\n" + f"{PLAIN.replace('=PQ', '=SDR')}\nuhd.m3u8\n")
assert len(result.videos) == 2
def test_variants_with_other_supplemental_codecs_and_other_links_stay_apart() -> None:
result = tracks(f"{PLAIN}\nhdr10.m3u8\n{COMPOSITE}\ndv.m3u8\n")
flags = {str(video.url).rsplit("/", 1)[-1]: video.dv_compatible_bitstream for video in result.videos}
assert flags == {"hdr10.m3u8": False, "dv.m3u8": True}
@pytest.mark.parametrize("first, second", [(PLAIN, COMPOSITE), (COMPOSITE, PLAIN)], ids=["plain", "composite"])
def test_one_link_listed_with_and_without_supplemental_codecs_keeps_the_dv_flag(first: str, second: str) -> None:
"""python-m3u8 drops SUPPLEMENTAL-CODECS, so the two entries count as one; the flag goes by link, not by entry."""
result = tracks(f"{first}\nuhd.m3u8\n{second}\nuhd.m3u8\n")
assert [video.dv_compatible_bitstream for video in result.videos] == [True]
def test_a_media_entry_listed_twice_with_other_channel_counts_keeps_both() -> None:
result = tracks(
AUDIO.replace('CHANNELS="2"', 'CHANNELS="6"')
+ "\n"
+ AUDIO.replace('CHANNELS="2"', 'CHANNELS="5.1"')
+ "\n"
+ variant(5_000_000, "video/uhd.m3u8")
)
assert len(result.audio) == 2
CC = '#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID="cc",NAME="CC1",INSTREAM-ID="CC1"'
CC_VARIANT = variant(5_000_000, "video/uhd.m3u8").replace('AUDIO="en"', 'AUDIO="en",CLOSED-CAPTIONS="cc"')
def test_a_closed_caption_entry_listed_twice_is_carried_once() -> None:
result = tracks(CC + "\n" + CC + "\n" + CC_VARIANT)
assert result.videos[0].closed_captions == [
{"language": None, "name": "CC1", "instream_id": "CC1", "characteristics": None}
]