fix(drm): preserve original PSSH for content_id-based Widevine manifests

This commit is contained in:
Andy
2026-03-18 11:06:04 -06:00
parent 96911cb626
commit 7fafdf024c
2 changed files with 18 additions and 4 deletions
+17 -3
View File
@@ -27,6 +27,12 @@ from unshackle.core.utils.subprocess import ffprobe
class Widevine: class Widevine:
"""Widevine DRM System.""" """Widevine DRM System."""
PLACEHOLDER_KIDS = {
UUID("00000000-0000-0000-0000-000000000000"), # All zeros (key rotation default)
UUID("00010203-0405-0607-0809-0a0b0c0d0e0f"), # Sequential 0x00-0x0f
UUID("00010203-0405-0607-0809-101112131415"), # Shaka Packager test pattern
}
def __init__(self, pssh: PSSH, kid: Union[UUID, str, bytes, None] = None, **kwargs: Any): def __init__(self, pssh: PSSH, kid: Union[UUID, str, bytes, None] = None, **kwargs: Any):
if not pssh: if not pssh:
raise ValueError("Provided PSSH is empty.") raise ValueError("Provided PSSH is empty.")
@@ -36,6 +42,7 @@ class Widevine:
if pssh.system_id == PSSH.SystemId.PlayReady: if pssh.system_id == PSSH.SystemId.PlayReady:
pssh.to_widevine() pssh.to_widevine()
self._kid: Optional[UUID] = None
if kid: if kid:
if isinstance(kid, str): if isinstance(kid, str):
kid = UUID(hex=kid) kid = UUID(hex=kid)
@@ -43,7 +50,9 @@ class Widevine:
kid = UUID(bytes=kid) kid = UUID(bytes=kid)
if not isinstance(kid, UUID): if not isinstance(kid, UUID):
raise ValueError(f"Expected kid to be a {UUID}, str, or bytes, not {kid!r}") raise ValueError(f"Expected kid to be a {UUID}, str, or bytes, not {kid!r}")
pssh.set_key_ids([kid]) self._kid = kid
if pssh.key_ids and all(k in self.PLACEHOLDER_KIDS for k in pssh.key_ids):
pssh.set_key_ids([kid])
self._pssh = pssh self._pssh = pssh
@@ -161,8 +170,13 @@ class Widevine:
@property @property
def kids(self) -> list[UUID]: def kids(self) -> list[UUID]:
"""Get all Key IDs.""" """Get all Key IDs from PSSH, falling back to the externally provided KID."""
return self._pssh.key_ids pssh_kids = self._pssh.key_ids
if pssh_kids:
return pssh_kids
if self._kid:
return [self._kid]
return []
def get_content_keys(self, cdm: WidevineCdm, certificate: Callable, licence: Callable) -> None: def get_content_keys(self, cdm: WidevineCdm, certificate: Callable, licence: Callable) -> None:
""" """
+1 -1
View File
@@ -924,7 +924,7 @@ class DASH:
None, None,
) )
if kid and (not pssh.key_ids or all(k.int == 0 or k in PLACEHOLDER_KIDS for k in pssh.key_ids)): if kid and pssh.key_ids and all(k.int == 0 or k in PLACEHOLDER_KIDS for k in pssh.key_ids):
pssh.set_key_ids([kid]) pssh.set_key_ids([kid])
drm.append(Widevine(pssh=pssh, kid=kid)) drm.append(Widevine(pssh=pssh, kid=kid))