mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-02 05:55:08 +00:00
fix(dash): license a track whose only key system is the W3C common PSSH as ClearKey
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user