mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-27 03:15:08 +00:00
fix(drm): load a bare PlayReady WRMHEADER from DASH, HLS and ISM manifests
PlayReady.from_pssh_b64 wraps a bare UTF-16LE WRMHEADER in a PlayReady Object and keeps that as pssh_b64. DASH and ISM log and skip a PlayReady entry they cannot parse.
This commit is contained in:
@@ -15,6 +15,7 @@ import m3u8
|
||||
from construct import Container
|
||||
from pymp4.parser import Box
|
||||
from pyplayready.cdm import Cdm as PlayReadyCdm
|
||||
from pyplayready.misc.exceptions import InvalidPssh
|
||||
from pyplayready.system.pssh import PSSH
|
||||
from pyplayready.system.wrmheader import WRMHeader
|
||||
from requests import Session
|
||||
@@ -170,6 +171,26 @@ class PlayReady:
|
||||
|
||||
return []
|
||||
|
||||
@classmethod
|
||||
def from_pssh_b64(cls, pssh_b64: str, kid: Optional[UUID] = None) -> PlayReady:
|
||||
"""Load a base64 PSSH box or PlayReady Object, or a bare UTF-16LE WRMHEADER that some packagers emit.
|
||||
|
||||
It wraps a bare WRMHEADER in a PlayReady Object and keeps that as `pssh_b64`, so remote CDMs and
|
||||
the REST API can parse it again.
|
||||
"""
|
||||
try:
|
||||
pssh = PSSH(pssh_b64)
|
||||
except InvalidPssh:
|
||||
try:
|
||||
raw = base64.b64decode(pssh_b64)
|
||||
except ValueError:
|
||||
raw = b""
|
||||
if not raw.startswith(b"<\x00"):
|
||||
raise
|
||||
pssh_b64 = cls.pro_b64_for(WRMHeader(raw))
|
||||
pssh = PSSH(pssh_b64)
|
||||
return cls(pssh=pssh, kid=kid, pssh_b64=pssh_b64)
|
||||
|
||||
@classmethod
|
||||
def from_track(cls, track: AnyTrack, session: Optional[Session] = None) -> PlayReady:
|
||||
if not session:
|
||||
|
||||
@@ -20,7 +20,6 @@ from zlib import crc32
|
||||
import requests
|
||||
from langcodes import Language, tag_is_valid
|
||||
from lxml.etree import Element, ElementTree, XMLSyntaxError
|
||||
from pyplayready.system.pssh import PSSH as PR_PSSH
|
||||
from pywidevine.cdm import Cdm as WidevineCdm
|
||||
from pywidevine.pssh import PSSH
|
||||
from requests import Session
|
||||
@@ -1355,7 +1354,6 @@ class DASH:
|
||||
)
|
||||
if not pr_pssh_b64:
|
||||
continue
|
||||
pr_pssh = PR_PSSH(pr_pssh_b64)
|
||||
kid_b64 = protection.findtext("kid")
|
||||
kid = None
|
||||
if kid_b64:
|
||||
@@ -1364,7 +1362,10 @@ class DASH:
|
||||
except ValueError:
|
||||
kid = None
|
||||
|
||||
drm.append(PlayReady(pssh=pr_pssh, kid=kid, pssh_b64=pr_pssh_b64))
|
||||
try:
|
||||
drm.append(PlayReady.from_pssh_b64(pr_pssh_b64, kid=kid))
|
||||
except Exception as e:
|
||||
logging.getLogger("DASH").warning(f"Skipping unparseable PlayReady ContentProtection: {e!r}")
|
||||
|
||||
elif urn == ClearKeyCENC.urn:
|
||||
# W3C EME ClearKey (org.w3.clearkey): match the scheme UUID alone,
|
||||
|
||||
@@ -1578,10 +1578,7 @@ class HLS:
|
||||
**extra_params,
|
||||
)
|
||||
elif key.keyformat and key.keyformat.lower() in {f"urn:uuid:{PR_PSSH.SYSTEM_ID}", "com.microsoft.playready"}:
|
||||
drm = PlayReady(
|
||||
pssh=PR_PSSH(key.uri.split(",")[-1]),
|
||||
pssh_b64=key.uri.split(",")[-1],
|
||||
)
|
||||
drm = PlayReady.from_pssh_b64(key.uri.split(",")[-1])
|
||||
else:
|
||||
raise NotImplementedError(f"The key system is not supported: {key}")
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ from typing import Any, BinaryIO, Optional, Union
|
||||
import requests
|
||||
from langcodes import Language, tag_is_valid
|
||||
from lxml.etree import Element
|
||||
from pyplayready.system.pssh import PSSH as PR_PSSH
|
||||
from pywidevine.pssh import PSSH
|
||||
from requests import Session
|
||||
|
||||
@@ -104,11 +103,9 @@ class ISM:
|
||||
drm.append(Widevine(pssh=pssh, kid=kid))
|
||||
elif system_id == "9a04f079-9840-4286-ab92-e65be0885f95":
|
||||
try:
|
||||
pr_pssh = PR_PSSH(data)
|
||||
drm.append(PlayReady.from_pssh_b64(data))
|
||||
except Exception as e:
|
||||
logging.getLogger("ISM").warning(f"Skipping unparseable PlayReady ProtectionHeader: {e!r}")
|
||||
continue
|
||||
drm.append(PlayReady(pssh=pr_pssh, pssh_b64=data))
|
||||
return drm
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -1174,7 +1174,7 @@ class Track:
|
||||
drm_list.append(drm)
|
||||
elif fmt in {f"urn:uuid:{PR_PSSH.SYSTEM_ID}", "com.microsoft.playready"}:
|
||||
pssh_b64 = key.uri.split(",")[-1]
|
||||
drm = PlayReady(pssh=PR_PSSH(pssh_b64), pssh_b64=pssh_b64)
|
||||
drm = PlayReady.from_pssh_b64(pssh_b64)
|
||||
drm_list.append(drm)
|
||||
|
||||
if drm_list:
|
||||
|
||||
Reference in New Issue
Block a user