refactor(drm): build PlayReady from base64 with PlayReady.from_pssh_b64 in server keys and the wire rebuild

This commit is contained in:
imSp4rky
2026-11-29 11:35:37 -07:00
parent 1cbaa2d307
commit 0ba9e6dfed
12 changed files with 182 additions and 55 deletions
+9 -5
View File
@@ -20,20 +20,20 @@ from unshackle.core.drm import PlayReady, Widevine
from unshackle.core.manifests.dash import DASH from unshackle.core.manifests.dash import DASH
from unshackle.core.manifests.hls import HLS from unshackle.core.manifests.hls import HLS
from unshackle.core.manifests.ism import ISM from unshackle.core.manifests.ism import ISM
from unshackle.core.wire import drm_from_dict from unshackle.core.wire import drm_from_dict, pssh_drm
KID = UUID("00112233-4455-6677-8899-aabbccddeeff") KID = UUID("00112233-4455-6677-8899-aabbccddeeff")
KID_B64 = base64.b64encode(KID.bytes_le).decode()
PR_URN = "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95" PR_URN = "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95"
WV_URN = "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed" WV_URN = "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
def bare_header(version: str) -> str: def bare_header(version: str, kid: UUID = KID) -> str:
"""Base64 of a bare WRMHEADER, with the KID where the given header version puts it.""" """Base64 of a bare WRMHEADER, with the KID where the given header version puts it."""
kid_b64 = base64.b64encode(kid.bytes_le).decode()
if version == "4.0.0.0": if version == "4.0.0.0":
data = f"<PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>{KID_B64}</KID>" data = f"<PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>{kid_b64}</KID>"
else: else:
data = f'<PROTECTINFO><KIDS><KID ALGID="AESCTR" VALUE="{KID_B64}"></KID></KIDS></PROTECTINFO>' data = f'<PROTECTINFO><KIDS><KID ALGID="AESCTR" VALUE="{kid_b64}"></KID></KIDS></PROTECTINFO>'
xml = ( xml = (
f'<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="{version}">' f'<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="{version}">'
f"<DATA>{data}<LA_URL>https://example.invalid/pr</LA_URL></DATA></WRMHEADER>" f"<DATA>{data}<LA_URL>https://example.invalid/pr</LA_URL></DATA></WRMHEADER>"
@@ -61,6 +61,10 @@ def test_dash_loads_a_bare_header(child: str, version: str) -> None:
assert KID in drm_from_dict(drm[0].to_dict()).kids assert KID in drm_from_dict(drm[0].to_dict()).kids
def test_the_wire_rebuilds_a_bare_header() -> None:
assert pssh_drm("playready", bare_header("4.0.0.0"), None).kids == [KID]
def test_wrapped_header_bytes_are_unchanged() -> None: def test_wrapped_header_bytes_are_unchanged() -> None:
header = bare_header("4.0.0.0") header = bare_header("4.0.0.0")
drm = PlayReady.from_pssh_b64(header) drm = PlayReady.from_pssh_b64(header)
+2 -6
View File
@@ -1060,12 +1060,8 @@ def test_reconstruct_rest_drm_skips_what_it_cannot_parse(caplog: pytest.LogCaptu
entries = [{"type": "widevine"}, {"type": "playready", "pssh": "!!"}, {"type": "clearkeycenc", "kids": ["x"]}] entries = [{"type": "widevine"}, {"type": "playready", "pssh": "!!"}, {"type": "clearkeycenc", "kids": ["x"]}]
with caplog.at_level(logging.WARNING): with caplog.at_level(logging.WARNING):
assert reconstruct_drm(entries) == [] assert reconstruct_drm(entries) == []
assert [(r.name, r.getMessage()) for r in caplog.records] == [ assert [r.name for r in caplog.records] == ["remote_service"]
( assert caplog.messages[0].startswith("Skipping unparseable playready DRM entry from server: InvalidPssh(")
"remote_service",
"Skipping unparseable playready DRM entry from server: InvalidPssh('Data must not be empty')",
)
]
def test_export_drm_decode() -> None: def test_export_drm_decode() -> None:
@@ -14,7 +14,6 @@ from types import SimpleNamespace
from typing import Any from typing import Any
from uuid import UUID from uuid import UUID
import pyplayready.system.pssh as pr_pssh_mod
import pytest import pytest
import pywidevine.pssh as wv_pssh_mod import pywidevine.pssh as wv_pssh_mod
@@ -113,6 +112,10 @@ class StubPlayReady(PlayReady):
self._refused_headers: set[str] = set() self._refused_headers: set[str] = set()
self.content_keys: dict[UUID, str] = {} self.content_keys: dict[UUID, str] = {}
@classmethod
def from_pssh_b64(cls, pssh_b64: str, kid: UUID | None = None) -> StubPlayReady:
return cls(pssh_b64=pssh_b64)
def extract_keys_from_cdm(self, cdm: Any, session_id: Any) -> dict[UUID, str]: def extract_keys_from_cdm(self, cdm: Any, session_id: Any) -> dict[UUID, str]:
return {KID: KEY.hex()} return {KID: KEY.hex()}
@@ -166,7 +169,6 @@ def widevine_env(monkeypatch: pytest.MonkeyPatch) -> None:
@pytest.fixture @pytest.fixture
def playready_env(monkeypatch: pytest.MonkeyPatch) -> None: def playready_env(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(pr_pssh_mod, "PSSH", lambda data: SimpleNamespace(data=data))
monkeypatch.setattr(drm_mod, "PlayReady", StubPlayReady) monkeypatch.setattr(drm_mod, "PlayReady", StubPlayReady)
monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: FakePlayReadyCdm()) monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: FakePlayReadyCdm())
monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda cdm: True) monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda cdm: True)
@@ -11,7 +11,6 @@ import json
from types import SimpleNamespace from types import SimpleNamespace
from uuid import UUID from uuid import UUID
import pyplayready.system.pssh as pr_pssh_mod
import pytest import pytest
import unshackle.core.cdm as cdm_mod import unshackle.core.cdm as cdm_mod
@@ -27,11 +26,6 @@ KID_B = UUID("43de497c6d1945f49acc2951696ec628")
KID_C = UUID("75982fac2cd8412a990a59c0ef2d4bb1") KID_C = UUID("75982fac2cd8412a990a59c0ef2d4bb1")
class _FakePRPSSH:
def __init__(self, data):
self.data = data
class _FakePlayReady: class _FakePlayReady:
def __init__(self, pssh=None, pssh_b64=None, kid=None, **kwargs): def __init__(self, pssh=None, pssh_b64=None, kid=None, **kwargs):
self.kids = [kid] if kid else [KID_A] self.kids = [kid] if kid else [KID_A]
@@ -39,6 +33,10 @@ class _FakePlayReady:
self.pssh_b64 = pssh_b64 self.pssh_b64 = pssh_b64
self.data = {"pssh_b64": pssh_b64} if pssh_b64 else {} self.data = {"pssh_b64": pssh_b64} if pssh_b64 else {}
@classmethod
def from_pssh_b64(cls, pssh_b64, kid=None):
return cls(pssh_b64=pssh_b64, kid=kid)
def absorb(self, *others): def absorb(self, *others):
for other in others: for other in others:
if other is self: if other is self:
@@ -53,7 +51,6 @@ class _FakePlayReady:
@pytest.fixture @pytest.fixture
def env(monkeypatch): def env(monkeypatch):
monkeypatch.setattr(pr_pssh_mod, "PSSH", _FakePRPSSH)
monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady) monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady)
monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: object()) monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: object())
monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda cdm: True) monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda cdm: True)
@@ -9,7 +9,6 @@ import base64
from types import SimpleNamespace from types import SimpleNamespace
from uuid import UUID from uuid import UUID
import pyplayready.system.pssh as pr_pssh_mod
import pytest import pytest
import unshackle.core.cdm as cdm_mod import unshackle.core.cdm as cdm_mod
@@ -24,11 +23,6 @@ KID_A = UUID("161219ec3df64e0eadbb3827c0ccc46d")
KID_B = UUID("43de497c6d1945f49acc2951696ec628") KID_B = UUID("43de497c6d1945f49acc2951696ec628")
class _FakePRPSSH:
def __init__(self, data):
self.data = data
class _FakePlayReady: class _FakePlayReady:
"""Only the headers this object knows about yield keys.""" """Only the headers this object knows about yield keys."""
@@ -38,6 +32,10 @@ class _FakePlayReady:
self.pssh_b64 = pssh_b64 self.pssh_b64 = pssh_b64
self.absorbed: list = [] self.absorbed: list = []
@classmethod
def from_pssh_b64(cls, pssh_b64, kid=None):
return cls(pssh_b64=pssh_b64, kid=kid)
def absorb(self, *others): def absorb(self, *others):
for other in others: for other in others:
if other is self: if other is self:
@@ -53,7 +51,6 @@ class _FakePlayReady:
@pytest.fixture @pytest.fixture
def playready_env(monkeypatch): def playready_env(monkeypatch):
monkeypatch.setattr(pr_pssh_mod, "PSSH", _FakePRPSSH)
monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady) monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady)
monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: object()) monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: object())
monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda cdm: True) monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda cdm: True)
@@ -0,0 +1,140 @@
"""A bare UTF-16LE WRMHEADER licenses on both server CDM routes and meets the client PSSH check like its wrapped form."""
import base64
import json
from types import SimpleNamespace
from uuid import UUID
import pytest
from pyplayready.system.pssh import PSSH
from pyplayready.system.wrmheader import WRMHeader
import unshackle.core.cdm as cdm_mod
import unshackle.core.cdm.detect as detect_mod
from tests.core.test_playready_bare_header import bare_header
from tests.remote.sessions import session_entry
from unshackle.core.api import handlers, server_keys
from unshackle.core.api.errors import APIError
from unshackle.core.drm import PlayReady
from unshackle.core.remote_protocol import APIErrorCode
pytestmark = pytest.mark.unit
KID = UUID("161219ec3df64e0eadbb3827c0ccc46d")
OTHER_KID = UUID("43de497c6d1945f49acc2951696ec628")
KEY = "11" * 16
def bare(kid: UUID) -> str:
"""Base64 of a bare v4.0 WRMHEADER that names ``kid``."""
return bare_header("4.0.0.0", kid)
def wrapped(kid: UUID) -> str:
"""The same header in a PlayReady Object."""
return PlayReady.pro_b64_for(WRMHeader(base64.b64decode(bare(kid))))
FORMS = pytest.mark.parametrize("form", [bare, wrapped], ids=["bare", "wrapped"])
@FORMS
def test_pssh_kids_reads_both_forms(form):
assert server_keys.pssh_kids(form(KID), "playready") == {KID}
@FORMS
def test_the_client_pssh_check_passes_and_refuses_both_forms_alike(form):
track = SimpleNamespace(id="vid", drm=[PlayReady.from_pssh_b64(bare(KID))])
server_keys.require_track_pssh(track, form(KID), "playready")
with pytest.raises(APIError) as refused:
server_keys.require_track_pssh(track, form(OTHER_KID), "playready")
assert refused.value.error_code is APIErrorCode.FORBIDDEN
class FakeCdm:
"""A PlayReady CDM that licenses ``KID`` for any header that names it."""
def __init__(self):
self.headers: list[WRMHeader] = []
def open(self):
return b"session"
def get_license_challenge(self, session_id, header):
self.headers.append(header)
return "CHAL"
def parse_license(self, session_id, licence):
pass
def get_keys(self, session_id):
named = any(KID in PlayReady.header_kids(header) for header in self.headers)
return [SimpleNamespace(key_id=KID, key=bytes.fromhex(KEY))] if named else []
def close(self, session_id):
pass
class Service:
"""A service whose PlayReady licence notes the PSSH it was given."""
def __init__(self):
self.pssh: list[str] = []
def get_playready_license(self, *, challenge, title, track, pssh_b64=None):
self.pssh.append(pssh_b64)
return "<License>stand-in</License>"
@pytest.fixture
def licence(monkeypatch):
cdm, service = FakeCdm(), Service()
monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: cdm)
monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda c: c is cdm)
monkeypatch.setattr(handlers, "ensure_track_drm", lambda track, session=None, init_data=None: None)
monkeypatch.setattr(server_keys, "ensure_track_drm", lambda track, session=None, init_data=None: None)
monkeypatch.setattr(server_keys, "resolve_device_name", lambda *a, **k: "dev")
monkeypatch.setattr(server_keys, "check_vaults", lambda kids, name, **_: None)
monkeypatch.setattr(server_keys, "cache_to_vaults", lambda keys, name, **_: None)
monkeypatch.setattr(server_keys, "find_title_for_track", lambda tid, session: SimpleNamespace())
monkeypatch.setattr(server_keys, "detect_cdm_type_for_service", lambda tag, cfg: "playready")
monkeypatch.setattr(server_keys, "fetch_init_segment", lambda track, sess: None)
monkeypatch.setattr(handlers.config, "serve", {"users": {}}, raising=False)
def post(data, track):
session = session_entry(service_tag="EX", service_instance=service, tracks={"vid": track})
async def get_session(sid, req):
return session
monkeypatch.setattr(handlers, "get_validated_session", get_session)
return handlers.session_license_handler({"mode": "server_cdm", "drm_type": "playready", **data}, "sess", None)
return SimpleNamespace(post=post, cdm=cdm, service=service)
def assert_licensed(licence, keys):
assert keys == {KID.hex: KEY}
assert [PlayReady.header_kids(header) for header in licence.cdm.headers] == [[KID]]
assert licence.service.pssh and all(b64 != bare(KID) and PSSH(b64).wrm_headers for b64 in licence.service.pssh)
async def test_the_single_route_licenses_a_bare_client_pssh(licence):
track = SimpleNamespace(id="vid", drm=[PlayReady.from_pssh_b64(bare(KID))])
resp = await licence.post({"track_id": "vid", "pssh": bare(KID)}, track)
assert_licensed(licence, json.loads(resp.body)["keys"])
async def test_the_batch_route_licenses_a_track_that_holds_a_bare_header(licence):
drm = PlayReady.from_pssh_b64(bare(KID))
drm.data["pssh_b64"] = bare(KID)
track = SimpleNamespace(id="vid", drm=[drm])
resp = await licence.post({"track_ids": ["vid"]}, track)
assert_licensed(licence, json.loads(resp.body)["keys"]["vid"])
@@ -13,7 +13,6 @@ import json
from types import SimpleNamespace from types import SimpleNamespace
from uuid import UUID from uuid import UUID
import pyplayready.system.pssh as pr_pssh_mod
import pytest import pytest
from pyplayready.system.pssh import PSSH as RealPSSH from pyplayready.system.pssh import PSSH as RealPSSH
@@ -46,11 +45,6 @@ def _kidless_pro_b64() -> str:
return base64.b64encode(pro).decode() return base64.b64encode(pro).decode()
class _FakePRPSSH:
def __init__(self, data):
self.data = data
class _FakePlayReady: class _FakePlayReady:
def __init__(self, pssh=None, pssh_b64=None, kid=None, **kwargs): def __init__(self, pssh=None, pssh_b64=None, kid=None, **kwargs):
self.kids = [kid] if kid else [KID_A] self.kids = [kid] if kid else [KID_A]
@@ -58,6 +52,10 @@ class _FakePlayReady:
self.pssh_b64 = pssh_b64 self.pssh_b64 = pssh_b64
self.data = {"pssh_b64": pssh_b64} if pssh_b64 else {} self.data = {"pssh_b64": pssh_b64} if pssh_b64 else {}
@classmethod
def from_pssh_b64(cls, pssh_b64, kid=None):
return cls(pssh_b64=pssh_b64, kid=kid)
@property @property
def kid(self): def kid(self):
return self.kids[0] return self.kids[0]
@@ -97,7 +95,6 @@ def server_env(monkeypatch):
@pytest.fixture @pytest.fixture
def fake_playready(monkeypatch): def fake_playready(monkeypatch):
monkeypatch.setattr(pr_pssh_mod, "PSSH", _FakePRPSSH)
monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady) monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady)
@@ -7,7 +7,6 @@ from types import SimpleNamespace
from uuid import UUID from uuid import UUID
import click import click
import pyplayready.system.pssh as pr_pssh_mod
import pytest import pytest
import pywidevine.pssh as wv_pssh_mod import pywidevine.pssh as wv_pssh_mod
@@ -287,7 +286,10 @@ def playready_env(monkeypatch):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.kids = [] self.kids = []
monkeypatch.setattr(pr_pssh_mod, "PSSH", lambda data: data) @classmethod
def from_pssh_b64(cls, pssh_b64, kid=None):
return cls()
monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady) monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady)
monkeypatch.setattr(handlers, "ensure_track_drm", lambda track, session=None, init_data=None: None) monkeypatch.setattr(handlers, "ensure_track_drm", lambda track, session=None, init_data=None: None)
monkeypatch.setattr(server_keys, "ensure_track_drm", lambda track, session=None, init_data=None: None) monkeypatch.setattr(server_keys, "ensure_track_drm", lambda track, session=None, init_data=None: None)
@@ -11,7 +11,6 @@ import json
from types import SimpleNamespace from types import SimpleNamespace
from uuid import UUID from uuid import UUID
import pyplayready.system.pssh as pr_pssh_mod
import pytest import pytest
import pywidevine.pssh as wv_pssh_mod import pywidevine.pssh as wv_pssh_mod
@@ -31,11 +30,6 @@ OTHER = UUID("43de497c6d1945f49acc2951696ec628") # a sibling track's KID from t
PSSH_B64 = base64.b64encode(b"pssh").decode() PSSH_B64 = base64.b64encode(b"pssh").decode()
class _FakePRPSSH:
def __init__(self, data):
self.data = data
class _FakePlayReady: class _FakePlayReady:
"""PSSH reports one KID; the license returns the full multi-key bundle.""" """PSSH reports one KID; the license returns the full multi-key bundle."""
@@ -44,13 +38,16 @@ class _FakePlayReady:
self.content_keys: dict = {} self.content_keys: dict = {}
self.pssh_b64 = pssh_b64 self.pssh_b64 = pssh_b64
@classmethod
def from_pssh_b64(cls, pssh_b64, kid=None):
return cls(pssh_b64=pssh_b64)
def get_content_keys(self, cdm, certificate, licence): def get_content_keys(self, cdm, certificate, licence):
self.content_keys = {REAL: "k_real", PSSH_KID: "k_pssh", OTHER: "k_other"} self.content_keys = {REAL: "k_real", PSSH_KID: "k_pssh", OTHER: "k_other"}
@pytest.fixture @pytest.fixture
def playready_env(monkeypatch): def playready_env(monkeypatch):
monkeypatch.setattr(pr_pssh_mod, "PSSH", _FakePRPSSH)
monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady) monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady)
monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: object()) monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda *a, **k: object())
monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda cdm: True) monkeypatch.setattr(detect_mod, "is_playready_cdm", lambda cdm: True)
@@ -13,7 +13,6 @@ import json
from types import SimpleNamespace from types import SimpleNamespace
from uuid import UUID from uuid import UUID
import pyplayready.system.pssh as pr_pssh_mod
import pytest import pytest
import pywidevine.pssh as wv_pssh_mod import pywidevine.pssh as wv_pssh_mod
@@ -51,6 +50,10 @@ class _FakePlayReady:
self.pssh_b64 = pssh_b64 self.pssh_b64 = pssh_b64
self.data = {"pssh_b64": pssh_b64} if pssh_b64 else {} self.data = {"pssh_b64": pssh_b64} if pssh_b64 else {}
@classmethod
def from_pssh_b64(cls, pssh_b64, kid=None):
return cls(pssh_b64=pssh_b64, kid=kid)
def absorb(self, *others): def absorb(self, *others):
pass pass
@@ -86,7 +89,6 @@ def env(monkeypatch):
"""Fake DRM classes and PSSH parsers; the CDM is a namespace that names its device.""" """Fake DRM classes and PSSH parsers; the CDM is a namespace that names its device."""
monkeypatch.setattr(drm_mod, "Widevine", _FakeWidevine) monkeypatch.setattr(drm_mod, "Widevine", _FakeWidevine)
monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady) monkeypatch.setattr(drm_mod, "PlayReady", _FakePlayReady)
monkeypatch.setattr(pr_pssh_mod, "PSSH", lambda data: SimpleNamespace(data=data))
monkeypatch.setattr(wv_pssh_mod, "PSSH", lambda data: SimpleNamespace(data=data)) monkeypatch.setattr(wv_pssh_mod, "PSSH", lambda data: SimpleNamespace(data=data))
monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda name, **k: SimpleNamespace(device=name)) monkeypatch.setitem(cdm_mod.__dict__, "load_cdm", lambda name, **k: SimpleNamespace(device=name))
monkeypatch.setattr(detect_mod, "is_widevine_cdm", lambda cdm: cdm.device.startswith("wv")) monkeypatch.setattr(detect_mod, "is_widevine_cdm", lambda cdm: cdm.device.startswith("wv"))
+2 -8
View File
@@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
import base64
import logging import logging
import uuid import uuid
from collections.abc import Callable, Iterable, Sequence from collections.abc import Callable, Iterable, Sequence
@@ -322,11 +321,9 @@ def client_track_kid(kid_hex: Any, track: Any) -> uuid.UUID | None:
def pssh_kids(pssh_b64: str, drm_type: str) -> set: def pssh_kids(pssh_b64: str, drm_type: str) -> set:
"""The KIDs a base64 PSSH names, for either DRM system.""" """The KIDs a base64 PSSH names, for either DRM system."""
if drm_type == "playready": if drm_type == "playready":
from pyplayready.system.pssh import PSSH as PlayReadyPSSH
from unshackle.core.drm import PlayReady from unshackle.core.drm import PlayReady
return set(PlayReady(pssh=PlayReadyPSSH(base64.b64decode(pssh_b64)), pssh_b64=pssh_b64).kids) return set(PlayReady.from_pssh_b64(pssh_b64).kids)
from pywidevine.pssh import PSSH as WvPSSH from pywidevine.pssh import PSSH as WvPSSH
from unshackle.core.drm import Widevine from unshackle.core.drm import Widevine
@@ -403,14 +400,11 @@ def handle_single_server_cdm(
raise refusal or APIError(APIErrorCode.NO_CONTENT, "The server vault holds no content key for this track") raise refusal or APIError(APIErrorCode.NO_CONTENT, "The server vault holds no content key for this track")
if drm_type == "playready": if drm_type == "playready":
from pyplayready.system.pssh import PSSH as PlayReadyPSSH
from unshackle.core.drm import PlayReady from unshackle.core.drm import PlayReady
pr_pssh = PlayReadyPSSH(base64.b64decode(pssh_b64))
siblings = [d for d in (getattr(track, "drm", None) or []) if isinstance(d, PlayReady)] siblings = [d for d in (getattr(track, "drm", None) or []) if isinstance(d, PlayReady)]
manifest_kid = next((getattr(d, "kid", None) for d in siblings if getattr(d, "kid", None)), None) manifest_kid = next((getattr(d, "kid", None) for d in siblings if getattr(d, "kid", None)), None)
pr_drm = PlayReady(pssh=pr_pssh, pssh_b64=pssh_b64, kid=manifest_kid) pr_drm = PlayReady.from_pssh_b64(pssh_b64, kid=manifest_kid)
if siblings: if siblings:
pr_drm.absorb(*siblings) pr_drm.absorb(*siblings)
+1 -2
View File
@@ -23,7 +23,6 @@ from uuid import UUID
import click import click
from langcodes import Language from langcodes import Language
from pyplayready.system.pssh import PSSH as PlayReadyPSSH
from pywidevine.pssh import PSSH as WidevinePSSH from pywidevine.pssh import PSSH as WidevinePSSH
from unshackle.core.config import config from unshackle.core.config import config
@@ -402,7 +401,7 @@ def pssh_drm(system: str, pssh_b64: str, kids: list[str] | None) -> Widevine | P
kids repeats the PSSH KIDs, so kids[0] is not the track's own KID; only a PSSH without KIDs needs it. kids repeats the PSSH KIDs, so kids[0] is not the track's own KID; only a PSSH without KIDs needs it.
""" """
if system == "playready": if system == "playready":
return PlayReady(pssh=PlayReadyPSSH(base64.b64decode(pssh_b64)), pssh_b64=pssh_b64) return PlayReady.from_pssh_b64(pssh_b64)
wv_pssh = WidevinePSSH(pssh_b64) wv_pssh = WidevinePSSH(pssh_b64)
return Widevine(pssh=wv_pssh, kid=kids[0] if kids and not wv_pssh.key_ids else None) return Widevine(pssh=wv_pssh, kid=kids[0] if kids and not wv_pssh.key_ids else None)