feat(hls): license a FairPlay-only SAMPLE-AES playlist through a PlayReady or Widevine CDM

This commit is contained in:
imSp4rky
2026-11-30 19:36:01 -07:00
parent c41d8ec3cf
commit b826eccb86
9 changed files with 449 additions and 98 deletions
+20
View File
@@ -101,6 +101,26 @@ def init_kid(init_data: bytes) -> UUID | None:
return None
def init_pssh_kid(init_data: bytes) -> UUID | None:
"""The one real KID that every pssh box of an init segment with a tenc names, or None for none or several."""
from unshackle.core.drm.playready import PlayReady
from unshackle.core.drm.widevine import Widevine
if not any(get_boxes(init_data, b"tenc")):
return None
drm_classes: dict[UUID, type[CencDrm]] = {WIDEVINE_ID: Widevine, PLAYREADY_ID: PlayReady}
kids: set[UUID] = set()
for box in get_boxes(init_data, b"pssh"):
kids.update(box.key_IDs or [])
if drm_class := drm_classes.get(box.system_ID):
try:
kids.update(drm_class.from_pssh_box(box, None).kids)
except drm_class.Exceptions.KIDNotFound:
continue
kids -= PLACEHOLDER_KIDS
return kids.pop() if len(kids) == 1 else None
def hls_key_drm(key: Any, kid: UUID | None = None) -> Widevine | PlayReady | None:
"""The Widevine or PlayReady DRM of an EXT-X-KEY, or None for another KEYFORMAT.