mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-04 06:55:09 +00:00
feat(drm)!: load DRM systems beyond the built-ins from plugins in directories.plugins
This commit is contained in:
@@ -15,7 +15,7 @@ import pytest
|
||||
from tests.core.test_all_drm import playready, widevine
|
||||
from unshackle.core import temp
|
||||
from unshackle.core.constants import DOWNLOAD_CANCELLED
|
||||
from unshackle.core.drm import ClearKey, ClearKeyCENC, ClearKeyCTR, MonaLisa, verify
|
||||
from unshackle.core.drm import ClearKey, ClearKeyCENC, ClearKeyCTR, CustomDRM, verify
|
||||
from unshackle.core.events import events
|
||||
from unshackle.core.manifests import segment_pipeline
|
||||
from unshackle.core.manifests.segment_pipeline import (
|
||||
@@ -222,13 +222,14 @@ def test_a_short_rolling_merge_raises_and_removes_the_output(tmp_path):
|
||||
check_merged(merger, 0, SimpleNamespace(id="EXAMPLE"), ctx, "EXAMPLE") # type: ignore[arg-type]
|
||||
|
||||
|
||||
WV, PR, CKC, ML, AES, CTR = "Widevine", "PlayReady", "ClearKeyCENC", "MonaLisa", "ClearKey", "ClearKeyCTR"
|
||||
WV, PR, CKC, AES, CTR = "Widevine", "PlayReady", "ClearKeyCENC", "ClearKey", "ClearKeyCTR"
|
||||
LOCAL, HELD = "example", "other"
|
||||
PSSH_KID = UUID(hex="22222222222222222222222222222222")
|
||||
PROBED_KID = UUID(hex="33333333333333333333333333333333")
|
||||
URL, DASH_, HLS_, ISM_ = (Track.Descriptor.URL, Track.Descriptor.DASH, Track.Descriptor.HLS, Track.Descriptor.ISM)
|
||||
|
||||
|
||||
def make_drm(system: str, monkeypatch: pytest.MonkeyPatch) -> Any:
|
||||
def make_drm(system: str) -> Any:
|
||||
"""One DRM of each system; every one that names a KID names PSSH_KID."""
|
||||
if system == WV:
|
||||
return widevine(PSSH_KID)
|
||||
@@ -236,9 +237,8 @@ def make_drm(system: str, monkeypatch: pytest.MonkeyPatch) -> Any:
|
||||
return playready(PSSH_KID)
|
||||
if system == CKC:
|
||||
return ClearKeyCENC(kids=[PSSH_KID])
|
||||
if system == ML:
|
||||
monkeypatch.setattr(MonaLisa, "extract_keys", lambda self: None)
|
||||
return MonaLisa("EXAMPLE", Path("unused.mld"))
|
||||
if system in (LOCAL, HELD):
|
||||
return CustomDRM(system, data={"key": bytes(16).hex()})
|
||||
if system == CTR:
|
||||
return ClearKeyCTR(None, bytes(16), b"OggS")
|
||||
return ClearKey(key=bytes(16))
|
||||
@@ -249,14 +249,16 @@ def licence_calls(tmp_path: Path) -> tuple[DownloadContext, list[tuple[Any, Any]
|
||||
return make_ctx(tmp_path, license_widevine=lambda drm, track_kid: calls.append((drm, track_kid))), calls
|
||||
|
||||
|
||||
LICENSED = {URL: {WV, PR, CKC, CTR}, DASH_: {WV, PR, CKC}, HLS_: {WV, PR, ML}, ISM_: {WV, PR}}
|
||||
LICENSED = {URL: {WV, PR, CKC, CTR}, DASH_: {WV, PR, CKC}, HLS_: {WV, PR, LOCAL}, ISM_: {WV, PR}}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("descriptor", list(LICENSED), ids=lambda d: d.name)
|
||||
@pytest.mark.parametrize("system", [WV, PR, CKC, ML, AES, CTR])
|
||||
def test_the_licence_step_licenses_the_systems_each_manifest_kind_licensed(tmp_path, monkeypatch, descriptor, system):
|
||||
@pytest.mark.parametrize("system", [WV, PR, CKC, LOCAL, HELD, AES, CTR])
|
||||
def test_the_licence_step_licenses_the_systems_each_manifest_kind_licensed(
|
||||
tmp_path, example_plugins, descriptor, system
|
||||
):
|
||||
ctx, calls = licence_calls(tmp_path)
|
||||
drm = make_drm(system, monkeypatch)
|
||||
drm = make_drm(system)
|
||||
|
||||
license_drm(SimpleNamespace(descriptor=descriptor, id="EXAMPLE"), drm, ctx) # type: ignore[arg-type]
|
||||
|
||||
@@ -281,7 +283,7 @@ def test_the_licence_step_skips_a_track_with_no_drm(tmp_path):
|
||||
(HLS_, WV, KID, "no probe", KID),
|
||||
(HLS_, PR, None, "no probe", PSSH_KID),
|
||||
(HLS_, WV, None, None, PSSH_KID),
|
||||
(HLS_, ML, KID, PROBED_KID, None),
|
||||
(HLS_, LOCAL, KID, PROBED_KID, None),
|
||||
(ISM_, PR, None, "no probe", PSSH_KID),
|
||||
],
|
||||
ids=[
|
||||
@@ -292,11 +294,11 @@ def test_the_licence_step_skips_a_track_with_no_drm(tmp_path):
|
||||
"hls-init-kid",
|
||||
"hls-drm-kid",
|
||||
"hls-probe-misses",
|
||||
"monalisa-no-kid",
|
||||
"plugin-own-media-no-kid",
|
||||
"ism-drm-kid",
|
||||
],
|
||||
)
|
||||
def test_the_licence_step_finds_the_track_kid(tmp_path, monkeypatch, descriptor, system, kid, probed, expected):
|
||||
def test_the_licence_step_finds_the_track_kid(tmp_path, example_plugins, descriptor, system, kid, probed, expected):
|
||||
ctx, calls = licence_calls(tmp_path)
|
||||
probes: list[bool] = []
|
||||
|
||||
@@ -305,7 +307,7 @@ def test_the_licence_step_finds_the_track_kid(tmp_path, monkeypatch, descriptor,
|
||||
return probed
|
||||
|
||||
track = SimpleNamespace(descriptor=descriptor, id="EXAMPLE")
|
||||
license_drm(track, make_drm(system, monkeypatch), ctx, kid, None if probed == "no probe" else probe) # type: ignore[arg-type]
|
||||
license_drm(track, make_drm(system), ctx, kid, None if probed == "no probe" else probe) # type: ignore[arg-type]
|
||||
|
||||
assert [c[1] for c in calls] == [expected]
|
||||
assert not (kid and probes), "a KID the caller holds needs no probe"
|
||||
|
||||
Reference in New Issue
Block a user