fix(dash): license a track whose only key system is the W3C common PSSH as ClearKey

This commit is contained in:
imSp4rky
2026-11-28 14:29:36 -07:00
parent b5b34cea02
commit 5f675bd5ff
7 changed files with 222 additions and 60 deletions
+13 -1
View File
@@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Any, Self
from uuid import UUID
import m3u8
from construct import Container
from construct import ConstructError, Container
from pymp4.parser import Box
from pyplayready.system.pssh import PSSH as PR_PSSH
from pywidevine.cdm import Cdm as WidevineCdm
@@ -34,6 +34,7 @@ if TYPE_CHECKING:
WIDEVINE_ID: UUID = WV_PSSH.SystemId.Widevine
PLAYREADY_ID: UUID = PR_PSSH.SYSTEM_ID
COMMON_ID = UUID("1077efec-c0b2-4d02-ace3-3c1e52e2fb4b")
KEYFORMATS = {
WidevineCdm.urn: WIDEVINE_ID,
f"urn:uuid:{PLAYREADY_ID}": PLAYREADY_ID,
@@ -46,6 +47,17 @@ PLACEHOLDER_KIDS = {
}
def common_pssh_kids(pssh_b64: str | None) -> list[UUID]:
"""The real KIDs of a base64 v1 PSSH box of the W3C common system ID, or an empty list for any other data."""
try:
box = Box.parse(base64.b64decode(pssh_b64 or ""))
except (ValueError, ConstructError):
return []
if box.type != b"pssh" or box.system_ID != COMMON_ID or box.version != 1:
return []
return [kid for kid in box.key_IDs if kid not in PLACEHOLDER_KIDS]
def key_system(key: Any) -> UUID | None:
"""The system ID that an EXT-X-KEY's KEYFORMAT names, or None when it names neither Widevine nor PlayReady."""
return KEYFORMATS.get((getattr(key, "keyformat", None) or "").lower())