feat(cdm): stamp remote CDM DRM type at load for reliable detection

This commit is contained in:
imSp4rky
2026-07-14 17:32:00 -06:00
parent c6ecdb605c
commit 2ccae1a0ee
5 changed files with 265 additions and 16 deletions
+3 -1
View File
@@ -152,7 +152,9 @@ class CustomRemoteCDM:
self.security_level = device.get("security_level", 3)
# Determine if this is a PlayReady CDM
self._is_playready = self.device_type_str.upper() == "PLAYREADY" or self.device_name in ["SL2", "SL3"]
self._is_playready = self.device_type_str.upper() == "PLAYREADY" or (
bool(self.device_name) and self.device_name.upper().startswith("SL")
)
# Get device type enum for compatibility
if self.device_type_str:
@@ -134,7 +134,9 @@ class DecryptLabsRemoteCDM:
if device_type:
self.device_type = self._get_device_type_enum(device_type)
self._is_playready = (device_type and device_type.upper() == "PLAYREADY") or (device_name in ["SL2", "SL3"])
self._is_playready = (device_type and device_type.upper() == "PLAYREADY") or (
bool(device_name) and device_name.upper().startswith("SL")
)
if self._is_playready:
self.system_id = system_id or 0
+20
View File
@@ -112,6 +112,10 @@ def is_playready_cdm(cdm: Any) -> bool:
if cdm is None:
return False
drm = getattr(cdm, "drm", None)
if drm:
return str(drm).lower() == "playready"
if hasattr(cdm, "is_playready"):
try:
return bool(getattr(cdm, "is_playready"))
@@ -144,6 +148,18 @@ def is_playready_cdm(cdm: Any) -> bool:
return "pyplayready" in mod
def is_remote_playready_cdm(cdm: Any) -> bool:
"""Return True if the CDM is a remote PlayReady CDM (as opposed to a local .prd)."""
return is_playready_cdm(cdm) and is_remote_cdm(cdm)
def is_remote_widevine_cdm(cdm: Any) -> bool:
"""Return True if the CDM is a remote Widevine CDM (as opposed to a local .wvd)."""
return is_widevine_cdm(cdm) and is_remote_cdm(cdm)
def is_widevine_cdm(cdm: Any) -> bool:
"""
Return True if the given CDM should be treated as Widevine.
@@ -155,6 +171,10 @@ def is_widevine_cdm(cdm: Any) -> bool:
if cdm is None:
return False
drm = getattr(cdm, "drm", None)
if drm:
return str(drm).lower() == "widevine"
if hasattr(cdm, "is_playready"):
try:
return not bool(getattr(cdm, "is_playready"))
+38 -14
View File
@@ -13,6 +13,22 @@ from typing import Any, Optional
log = logging.getLogger("cdm")
def _stamp_remote(cdm: Any, drm: str) -> Any:
"""Record a remote CDM's DRM type and mark it as remote.
The loader knows the DRM type from config, so it sets it here as the value
`detect.py` reads before it falls back to class or module checks. Setting the
attributes is best effort: a third-party CDM object that rejects them still
works, since detect.py keeps its existing checks.
"""
try:
cdm.drm = drm
cdm.is_remote_cdm = True
except (AttributeError, TypeError):
pass
return cdm
def load_cdm(
cdm_name: str,
*,
@@ -63,35 +79,43 @@ def _load_remote_cdm(
f"No secret provided for DecryptLabs CDM '{cdm_name}' and no global decrypt_labs_api_key configured"
)
return DecryptLabsRemoteCDM(service_name=service_name, vaults=vaults, **cdm_api)
cdm: Any = DecryptLabsRemoteCDM(service_name=service_name, vaults=vaults, **cdm_api)
return _stamp_remote(cdm, "playready" if cdm.is_playready else "widevine")
if cdm_type == "custom_api":
from unshackle.core.cdm.custom_remote_cdm import CustomRemoteCDM
del cdm_api["name"]
del cdm_api["type"]
return CustomRemoteCDM(service_name=service_name, vaults=vaults, **cdm_api)
cdm = CustomRemoteCDM(service_name=service_name, vaults=vaults, **cdm_api)
return _stamp_remote(cdm, "playready" if cdm.is_playready else "widevine")
device_type = cdm_api.get("Device Type", cdm_api.get("device_type", ""))
if str(device_type).upper() == "PLAYREADY":
from pyplayready.remote.remotecdm import RemoteCdm as PlayReadyRemoteCdm
return PlayReadyRemoteCdm(
security_level=cdm_api.get("Security Level", cdm_api.get("security_level", 3000)),
host=cdm_api.get("Host", cdm_api.get("host")),
secret=cdm_api.get("Secret", cdm_api.get("secret")),
device_name=cdm_api.get("Device Name", cdm_api.get("device_name")),
return _stamp_remote(
PlayReadyRemoteCdm(
security_level=cdm_api.get("Security Level", cdm_api.get("security_level", 3000)),
host=cdm_api.get("Host", cdm_api.get("host")),
secret=cdm_api.get("Secret", cdm_api.get("secret")),
device_name=cdm_api.get("Device Name", cdm_api.get("device_name")),
),
"playready",
)
from pywidevine.remotecdm import RemoteCdm
return RemoteCdm(
device_type=cdm_api.get("Device Type", cdm_api.get("device_type", "")),
system_id=cdm_api.get("System ID", cdm_api.get("system_id", "")),
security_level=cdm_api.get("Security Level", cdm_api.get("security_level", 3000)),
host=cdm_api.get("Host", cdm_api.get("host")),
secret=cdm_api.get("Secret", cdm_api.get("secret")),
device_name=cdm_api.get("Device Name", cdm_api.get("device_name")),
return _stamp_remote(
RemoteCdm(
device_type=cdm_api.get("Device Type", cdm_api.get("device_type", "")),
system_id=cdm_api.get("System ID", cdm_api.get("system_id", "")),
security_level=cdm_api.get("Security Level", cdm_api.get("security_level", 3000)),
host=cdm_api.get("Host", cdm_api.get("host")),
secret=cdm_api.get("Secret", cdm_api.get("secret")),
device_name=cdm_api.get("Device Name", cdm_api.get("device_name")),
),
"widevine",
)