mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-02 05:55:08 +00:00
fix(hls): keep the EXT-X-KEY of another KEYFORMAT in force when a playlist renews one key tag
This commit is contained in:
@@ -38,6 +38,9 @@ NONE = "#EXT-X-KEY:METHOD=NONE"
|
||||
MAP = '#EXT-X-MAP:URI="init.mp4"'
|
||||
DISCONTINUITY_SEQUENCE = "#EXT-X-DISCONTINUITY-SEQUENCE:0"
|
||||
SKD = '#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://keys.example/a",KEYFORMAT="com.apple.streamingkeydelivery"'
|
||||
SKD_B = SKD.replace("/a", "/b")
|
||||
ID_A = '#EXT-X-KEY:METHOD=SAMPLE-AES,URI="id-a"'
|
||||
ID_B = '#EXT-X-KEY:METHOD=SAMPLE-AES,URI="id-b",KEYFORMAT="Identity"'
|
||||
KID_A, KID_B = UUID(int=0xA1), UUID(int=0xB2)
|
||||
WV_A, WV_B = key_tag(KID_A), key_tag(KID_B)
|
||||
|
||||
@@ -68,6 +71,40 @@ def playlist(tags: dict[int, list[str]]) -> str:
|
||||
pytest.param({0: [K1], 2: [NONE]}, [0, 1, 4], [(0, ["k1"], None), (2, [None], None)], id="clear-ad-not-tagged"),
|
||||
pytest.param({0: [K1], 2: [K1]}, range(6), [(0, ["k1"], None)], id="same-tag-again"),
|
||||
pytest.param({0: [SKD, WV_A]}, [3], [(0, ["skd", "data"], None)], id="two-systems"),
|
||||
pytest.param(
|
||||
{0: [WV_A, SKD], 3: [SKD_B]},
|
||||
range(6),
|
||||
[(0, ["data", "skd"], None), (3, ["data", "skd"], None)],
|
||||
id="other-system-stays-in-force",
|
||||
),
|
||||
pytest.param(
|
||||
{0: [ID_A, SKD], 3: [ID_B]},
|
||||
range(6),
|
||||
[(0, ["id-a", "skd"], None), (3, ["id-b", "skd"], None)],
|
||||
id="identity-renewed",
|
||||
),
|
||||
pytest.param({0: [WV_A, SKD], 3: [WV_A]}, range(6), [(0, ["data", "skd"], None)], id="first-tag-again"),
|
||||
pytest.param(
|
||||
{0: [ID_A], 1: [SKD]}, range(6), [(0, ["id-a"], None), (1, ["id-a", "skd"], None)], id="tag-on-each"
|
||||
),
|
||||
pytest.param(
|
||||
{0: [SKD, DISCONTINUITY_SEQUENCE, ID_A], 1: [SKD_B]},
|
||||
range(6),
|
||||
[(0, ["skd", "id-a"], None), (1, ["skd", "id-a"], None)],
|
||||
id="lost-tag-beside-a-tag",
|
||||
),
|
||||
pytest.param(
|
||||
{0: [SKD], 2: [K1], 4: [SKD_B]},
|
||||
range(6),
|
||||
[(0, ["skd"], None), (2, ["k1"], None), (4, ["skd"], None)],
|
||||
id="other-method",
|
||||
),
|
||||
pytest.param(
|
||||
{0: [WV_A, SKD], 2: [NONE], 4: [SKD]},
|
||||
range(6),
|
||||
[(0, ["data", "skd"], None), (2, [None], None), (4, ["skd"], None)],
|
||||
id="none-ends-every-system",
|
||||
),
|
||||
pytest.param(
|
||||
{0: [MAP, K1], 3: [MAP.replace("init", "next")]},
|
||||
[1, 4],
|
||||
@@ -427,7 +464,7 @@ def test_the_first_licence_reads_the_init_segment_of_its_own_key(
|
||||
[
|
||||
pytest.param({0: [MAP, SKD]}, id="first-segment"),
|
||||
pytest.param({0: [MAP, SKD, DISCONTINUITY_SEQUENCE]}, id="lost"),
|
||||
pytest.param({0: [MAP, WV_A], 3: [SKD]}, id="second-key"),
|
||||
pytest.param({0: [MAP, WV_A], 2: [NONE], 3: [SKD]}, id="second-key"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("cdm", ["widevine", None])
|
||||
@@ -446,6 +483,25 @@ def test_a_tag_unshackle_cannot_license_is_refused_before_a_segment(
|
||||
assert not [path for path in server.requests if path.endswith(".ts")]
|
||||
|
||||
|
||||
def test_a_tag_of_another_keyformat_keeps_the_licensed_tag_in_force(
|
||||
server: Any, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
DOWNLOAD_LICENCE_ONLY.set()
|
||||
monkeypatch.setattr(Audio, "get_key_id", lambda self, data: KID_A)
|
||||
licensed: list[UUID | None] = []
|
||||
|
||||
download(
|
||||
server,
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
{0: [MAP, WV_A, SKD], 3: [SKD_B]},
|
||||
cdm=cdm_type_stub("widevine"),
|
||||
licence=lambda drm, track_kid=None: licensed.append(track_kid),
|
||||
)
|
||||
|
||||
assert licensed == [KID_A]
|
||||
|
||||
|
||||
def test_a_lost_tag_is_bridged_with_the_first_init_segment(
|
||||
server: Any, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
|
||||
@@ -144,8 +144,14 @@ IDENTITY_KEY = '#EXT-X-KEY:METHOD=SAMPLE-AES,URI="https://keys.example/key"'
|
||||
pytest.param(playlist(f'{IDENTITY_KEY},KEYFORMAT="identity"'), False, id="identity"),
|
||||
pytest.param(playlist(SKD_KEY), True, id="fairplay"),
|
||||
pytest.param(playlist(IDENTITY_KEY, SKD_KEY), True, id="identity-beside-fairplay"),
|
||||
pytest.param(playlist(SKD_KEY).replace("seg0.m4s\n", f"seg0.m4s\n{IDENTITY_KEY}\n"), True, id="identity-later"),
|
||||
pytest.param(
|
||||
playlist(SKD_KEY).replace("seg0.m4s\n", f"seg0.m4s\n{IDENTITY_KEY}\n"), False, id="identity-later"
|
||||
playlist(SKD_KEY).replace("seg0.m4s\n", f"seg0.m4s\n{NONE_KEY}\n{IDENTITY_KEY}\n"),
|
||||
False,
|
||||
id="identity-after-a-clear-tag",
|
||||
),
|
||||
pytest.param(
|
||||
playlist(IDENTITY_KEY).replace("seg0.m4s\n", f"seg0.m4s\n{SKD_KEY}\n"), False, id="fairplay-later"
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user