mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-01 21:45:10 +00:00
feat(hls): license a FairPlay-only SAMPLE-AES playlist through a PlayReady or Widevine CDM
This commit is contained in:
@@ -18,6 +18,7 @@ from tests.core.test_kid_windows import box, encv
|
||||
from unshackle.core import binaries
|
||||
from unshackle.core.drm import PlayReady, Widevine, cenc
|
||||
from unshackle.core.drm.verify import PIFF_TENC
|
||||
from unshackle.core.manifests import HLS
|
||||
from unshackle.core.tracks import Video
|
||||
from unshackle.core.utils import subprocess as subprocess_utils
|
||||
|
||||
@@ -76,6 +77,38 @@ def test_init_kid_is_none_without_a_real_kid() -> None:
|
||||
assert cenc.init_kid(init(encv(UUID(int=0)))) is None
|
||||
|
||||
|
||||
def common_box(kid: UUID) -> bytes:
|
||||
body = {"type": b"pssh", "version": 1, "flags": 0, "system_ID": cenc.COMMON_ID, "key_IDs": [kid], "init_data": b""}
|
||||
return Box.build(body)
|
||||
|
||||
|
||||
def widevine_box(*kids: UUID) -> bytes:
|
||||
return PSSH.new(system_id=PSSH.SystemId.Widevine, key_ids=list(kids)).dump()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"boxes, kid",
|
||||
[
|
||||
pytest.param([playready_box(TRACK_KID)], TRACK_KID, id="one-system"),
|
||||
pytest.param([widevine_box(TRACK_KID), playready_box(TRACK_KID)], TRACK_KID, id="both-systems-agree"),
|
||||
pytest.param([widevine_box(TRACK_KID, OTHER_KID)], None, id="several-kids"),
|
||||
pytest.param([widevine_box(OTHER_KID), playready_box(TRACK_KID)], None, id="systems-disagree"),
|
||||
pytest.param([widevine_box(TRACK_KID), widevine_box(OTHER_KID)], None, id="two-boxes-of-one-system"),
|
||||
pytest.param([widevine_box(TRACK_KID), common_box(OTHER_KID)], None, id="common-box-disagrees"),
|
||||
pytest.param([common_box(TRACK_KID)], TRACK_KID, id="common-box"),
|
||||
pytest.param([PSSH(no_kid_pssh()).dump(), playready_box(TRACK_KID)], TRACK_KID, id="one-box-without-a-kid"),
|
||||
pytest.param([widevine_box(UUID(int=0))], None, id="placeholder"),
|
||||
pytest.param([], None, id="no-pssh"),
|
||||
],
|
||||
)
|
||||
def test_init_pssh_kid_is_the_one_real_kid_the_pssh_boxes_name(boxes: list[bytes], kid: UUID | None) -> None:
|
||||
assert cenc.init_pssh_kid(init(*boxes, encv(UUID(int=0)))) == kid
|
||||
|
||||
|
||||
def test_init_pssh_kid_needs_a_tenc() -> None:
|
||||
assert cenc.init_pssh_kid(init(widevine_box(TRACK_KID))) is None
|
||||
|
||||
|
||||
def test_widevine_from_init_data_takes_the_piff_kid_when_the_pssh_names_none() -> None:
|
||||
pssh = PSSH(no_kid_pssh()).dump()
|
||||
drm = Widevine.from_init_data(init(pssh, encv(TRACK_KID, piff=True)))
|
||||
@@ -249,3 +282,15 @@ def test_from_track_reads_the_playlist_pssh_and_the_init_kid() -> None:
|
||||
assert drm.kids == [OTHER_KID, TRACK_KID]
|
||||
with pytest.raises(Widevine.Exceptions.PSSHNotFound):
|
||||
Widevine.from_track(track, track.session)
|
||||
|
||||
|
||||
def test_the_hls_probe_reads_the_pssh_kid_only_when_asked() -> None:
|
||||
manifest = cenc.m3u8.loads('#EXTM3U\n#EXT-X-MAP:URI="init.mp4"\n#EXTINF:6.0,\nseg0.m4s\n#EXT-X-ENDLIST\n')
|
||||
content = init(playready_box(TRACK_KID), encv(UUID(int=0)))
|
||||
session: Any = SimpleNamespace(get=lambda url, headers=None: SimpleNamespace(ok=True, content=content))
|
||||
track = playlist_track("")
|
||||
|
||||
track.get_key_id = lambda data: cenc.init_kid(data) # type: ignore[method-assign]
|
||||
|
||||
assert HLS.get_track_kid_from_init(manifest, track, session) is None
|
||||
assert HLS.get_track_kid_from_init(manifest, track, session, pssh=True) == TRACK_KID
|
||||
|
||||
Reference in New Issue
Block a user