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
+2 -8
View File
@@ -2,7 +2,6 @@
from __future__ import annotations
import base64
import logging
import uuid
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:
"""The KIDs a base64 PSSH names, for either DRM system."""
if drm_type == "playready":
from pyplayready.system.pssh import PSSH as PlayReadyPSSH
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 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")
if drm_type == "playready":
from pyplayready.system.pssh import PSSH as PlayReadyPSSH
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)]
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:
pr_drm.absorb(*siblings)
+1 -2
View File
@@ -23,7 +23,6 @@ from uuid import UUID
import click
from langcodes import Language
from pyplayready.system.pssh import PSSH as PlayReadyPSSH
from pywidevine.pssh import PSSH as WidevinePSSH
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.
"""
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)
return Widevine(pssh=wv_pssh, kid=kids[0] if kids and not wv_pssh.key_ids else None)