forked from kenzuya/unshackle
fix(dash): license a track whose only key system is the W3C common PSSH as ClearKey
This commit is contained in:
@@ -10,11 +10,15 @@ decrypt) and asserts the ClearKeyCENC drm is licensed.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
from functools import partial
|
||||
from typing import Any
|
||||
from uuid import UUID
|
||||
|
||||
from pywidevine.pssh import PSSH
|
||||
|
||||
from unshackle.core.constants import DOWNLOAD_LICENCE_ONLY
|
||||
from unshackle.core.drm import Widevine
|
||||
from unshackle.core.drm.clearkey_cenc import ClearKeyCENC
|
||||
from unshackle.core.manifests.dash import DASH
|
||||
from unshackle.core.tracks.track import DownloadContext
|
||||
@@ -101,3 +105,45 @@ def test_download_track_keeps_service_drm_when_manifest_has_none(tmp_path, monke
|
||||
|
||||
assert track.drm == service_drm
|
||||
assert len(licence.calls) == 1
|
||||
|
||||
|
||||
COMMON_MPD = MPD.replace(
|
||||
MPD[MPD.index("<ContentProtection") : MPD.index("</ContentProtection>") + len("</ContentProtection>")],
|
||||
f'<ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" cenc:default_KID="{KID}"/>'
|
||||
'<ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b"/>',
|
||||
)
|
||||
|
||||
|
||||
def with_init(monkeypatch: Any, init_data: bytes | None) -> None:
|
||||
"""Make the period give ``init_data`` as its init segment, offline."""
|
||||
segments = DASH.get_period_segments
|
||||
|
||||
def fake(*args: Any, **kwargs: Any) -> Any:
|
||||
_, *rest = segments(*args, **kwargs)
|
||||
return (init_data, *rest)
|
||||
|
||||
monkeypatch.setattr(DASH, "get_period_segments", staticmethod(fake))
|
||||
|
||||
|
||||
def test_download_track_licenses_a_common_pssh_track_as_clearkey(tmp_path, monkeypatch) -> None:
|
||||
track = DASH.from_text(COMMON_MPD, MANIFEST_URL).to_tracks().videos[0]
|
||||
monkeypatch.setattr(track, "get_key_id", lambda *args, **kwargs: KID)
|
||||
assert track.drm is None
|
||||
|
||||
licence = licence_only(track, tmp_path)
|
||||
|
||||
assert len(licence.calls) == 1
|
||||
drm, _ = licence.calls[0]
|
||||
assert isinstance(drm, ClearKeyCENC)
|
||||
assert drm.kids == [KID]
|
||||
|
||||
|
||||
def test_download_track_prefers_the_init_segment_pssh_over_a_common_pssh(tmp_path, monkeypatch) -> None:
|
||||
track = DASH.from_text(COMMON_MPD, MANIFEST_URL).to_tracks().videos[0]
|
||||
monkeypatch.setattr(track, "get_key_id", lambda *args, **kwargs: KID)
|
||||
with_init(monkeypatch, base64.b64decode(PSSH.new(system_id=PSSH.SystemId.Widevine, key_ids=[KID]).dumps()))
|
||||
|
||||
licence = licence_only(track, tmp_path)
|
||||
|
||||
assert [type(d) for d in track.drm] == [Widevine]
|
||||
assert isinstance(licence.calls[0][0], Widevine)
|
||||
|
||||
Reference in New Issue
Block a user