docs: apply simplified technical english across docs and docstrings.

This commit is contained in:
imSp4rky
2026-08-19 16:31:06 -06:00
parent 4177cb2267
commit 66971230c3
135 changed files with 2651 additions and 2570 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ CDM helpers and implementations.
Keep this module import-light: downstream code frequently imports helpers from
`unshackle.core.cdm.detect`, which requires importing this package first.
Some CDM implementations pull in optional/heavy dependencies, so we lazily
import them via `__getattr__` (PEP 562).
import them through `__getattr__` (PEP 562).
"""
from __future__ import annotations
+43 -43
View File
@@ -25,7 +25,7 @@ class MockCertificateChain:
class Key:
"""Key object compatible with pywidevine."""
"""`Key` object compatible with pywidevine."""
def __init__(self, kid: str, key: str, type_: str = "CONTENT"):
if isinstance(kid, str):
@@ -52,7 +52,7 @@ class CustomRemoteCDMExceptions:
"""Raised when session ID is invalid."""
class TooManySessions(Exception):
"""Raised when session limit is reached."""
"""Raised when the CDM sessions reach the limit."""
class InvalidInitData(Exception):
"""Raised when PSSH/init data is invalid."""
@@ -64,7 +64,7 @@ class CustomRemoteCDMExceptions:
"""Raised when license message is invalid."""
class InvalidContext(Exception):
"""Raised when session has no context data."""
"""Raised when the CDM session has no context data."""
class SignatureMismatch(Exception):
"""Raised when signature verification fails."""
@@ -75,19 +75,19 @@ class CustomRemoteCDM:
Highly Configurable Custom Remote CDM implementation.
This class provides a maximally flexible CDM interface that can adapt to
ANY CDM API format through YAML configuration alone. It's designed to support
both current and future CDM providers without requiring code changes.
ANY CDM API format through YAML configuration alone. It can hold both current
and future CDM providers without code changes.
Key Features:
- Fully configuration-driven behavior (all logic controlled via YAML)
Main Features:
- Fully configuration-driven behaviour (all logic controlled through YAML)
- Pluggable authentication strategies (header, body, bearer, basic, custom)
- Flexible endpoint configuration (custom paths, methods, timeouts)
- Advanced parameter mapping (rename, add static, conditional, nested)
- Powerful response parsing (deep field access, type detection, transforms)
- Transform engine (base64, hex, JSON, custom key formats)
- Response parsing (deep field access, type detection, transforms)
- Transform engine (base64, hex, JSON, custom content key formats)
- Condition evaluation (response type detection, success validation)
- Compatible with both Widevine and PlayReady DRM schemes
- Vault integration for intelligent key caching
- Vault integration for intelligent content key caching
Configuration Philosophy:
- 90% of new CDM providers: YAML config only
@@ -95,12 +95,12 @@ class CustomRemoteCDM:
- 1% of cases: Add new auth strategy (minimal code)
- 0% need to modify core request/response logic
The class is designed to handle diverse API patterns including:
The class adapts to these diverse API patterns:
- Different authentication mechanisms (headers vs body vs tokens)
- Custom endpoint paths and HTTP methods
- Parameter name variations (scheme vs device, init_data vs pssh)
- Nested JSON structures in requests/responses
- Various key formats (JSON objects, colon-separated strings, etc.)
- Various content key formats (JSON objects, colon-separated strings, and other forms)
- Different response success indicators and error messages
- Conditional parameters based on device type or other factors
"""
@@ -123,18 +123,18 @@ class CustomRemoteCDM:
**kwargs,
):
"""
Initialize Custom Remote CDM with highly configurable options.
Initialise Custom Remote CDM with highly configurable options.
Args:
host: Base URL for the CDM API
service_name: Service name for key caching and vault operations
vaults: Vaults instance for local key caching
service_name: Service tag for content key caching and vault operations
vaults: Vaults instance for local content key caching
device: Device configuration (name, type, system_id, security_level)
auth: Authentication configuration (type, credentials, headers)
endpoints: Endpoint configuration (paths, methods, timeouts)
request_mapping: Request transformation rules (param names, static params, transforms)
response_mapping: Response parsing rules (field locations, type detection, success conditions)
caching: Caching configuration (enabled, use_vaults, etc.)
caching: Caching configuration (enabled, use_vaults, and the other caching keys)
legacy: Legacy mode configuration
timeout: Default request timeout in seconds
**kwargs: Additional configuration options for future extensibility
@@ -229,7 +229,7 @@ class CustomRemoteCDM:
@property
def is_playready(self) -> bool:
"""Check if this CDM is in PlayReady mode."""
"""Return True if this CDM is in PlayReady mode."""
return self._is_playready
@property
@@ -246,7 +246,7 @@ class CustomRemoteCDM:
Set the required Key IDs for intelligent caching decisions.
This method enables the CDM to make smart decisions about when to request
additional keys via license challenges. When cached keys are available,
additional keys through license challenges. When cached keys are available,
the CDM will compare them against the required KIDs to determine if a
license request is still needed for missing keys.
@@ -254,8 +254,8 @@ class CustomRemoteCDM:
kids: List of required Key IDs as UUIDs or hex strings
Note:
Should be called by DRM classes (PlayReady/Widevine) before making
license challenge requests to enable optimal caching behavior.
Call this method from the DRM classes (PlayReady/Widevine) before a
license challenge request, to enable optimal caching behaviour.
"""
self._required_kids = []
for kid in kids:
@@ -265,7 +265,7 @@ class CustomRemoteCDM:
self._required_kids.append(str(kid).replace("-", "").lower())
def generate_session_id(self) -> bytes:
"""Generate a unique session ID."""
"""Make a unique session ID."""
return secrets.token_bytes(16)
def get_init_data_from_pssh(self, pssh: Any) -> str:
@@ -407,11 +407,11 @@ class CustomRemoteCDM:
Args:
condition: Condition string (e.g., "message == 'success'")
context: Context dictionary with values to check
context: Context dictionary with the values to examine
Returns:
True if condition is met, False otherwise. A condition that matches none of the supported
forms is treated as unmet and returns False.
forms counts as unmet, so the method returns False.
Supported conditions:
- "field == value": Equality check
@@ -454,12 +454,12 @@ class CustomRemoteCDM:
self, endpoint_name: str, base_params: Dict[str, Any], session: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
"""
Build request parameters with mapping and transformations.
Assemble request parameters with mapping and transformations.
Args:
endpoint_name: Name of the endpoint (e.g., "get_request", "decrypt_response")
base_params: Base parameters to transform
session: Optional session data for context
session: Optional CDM session data for context
Returns:
Transformed parameters dictionary
@@ -469,7 +469,7 @@ class CustomRemoteCDM:
2. Static parameters (add fixed values)
3. Conditional parameters (add based on conditions)
4. Parameter transforms (apply data transformations)
5. Nested parameter structure (create nested objects)
5. Nested parameter structure (make nested objects)
6. Parameter exclusions (remove unwanted params)
"""
mapping_config = self.request_mapping.get(endpoint_name, {})
@@ -530,14 +530,14 @@ class CustomRemoteCDM:
Apply authentication to the HTTP session based on auth configuration.
Args:
session: requests.Session to apply authentication to
session: `requests.Session` to apply authentication to
Supported auth types:
- header: Add authentication header (e.g., x-api-key, Authorization)
- body: Authentication will be added to request body (handled in request building)
- body: the request body carries the authentication (not applied here)
- bearer: Add Bearer token to Authorization header
- basic: Add HTTP Basic authentication
- query: Authentication will be added to query string (handled in request)
- query: the query string carries the authentication (not applied here)
"""
auth_type = self.auth_config.get("type", "header")
@@ -617,14 +617,14 @@ class CustomRemoteCDM:
def parse_keys_from_response(self, endpoint_name: str, response_data: Dict[str, Any]) -> List[Dict[str, Any]]:
"""
Parse keys from response data using key field mapping.
Parse content keys from response data with the key field mapping.
Args:
endpoint_name: Name of the endpoint
response_data: Parsed response data
Returns:
List of key dictionaries with standardized format
List of content key dictionaries with standardized format
"""
mapping_config = self.response_mapping.get(endpoint_name, {})
key_fields = mapping_config.get("key_fields", {"kid": "kid", "key": "key", "type": "type"})
@@ -668,7 +668,7 @@ class CustomRemoteCDM:
def close(self, session_id: bytes) -> None:
"""
Close a CDM session and perform comprehensive cleanup.
Close a CDM session and do comprehensive cleanup.
Args:
session_id: Session identifier
@@ -685,7 +685,7 @@ class CustomRemoteCDM:
def get_service_certificate(self, session_id: bytes) -> Optional[bytes]:
"""
Get the service certificate for a session.
Get the service certificate for a CDM session.
Args:
session_id: Session identifier
@@ -703,7 +703,7 @@ class CustomRemoteCDM:
def set_service_certificate(self, session_id: bytes, certificate: Optional[Union[bytes, str]]) -> str:
"""
Set the service certificate for a session.
Set the service certificate for a CDM session.
Args:
session_id: Session identifier
@@ -735,7 +735,7 @@ class CustomRemoteCDM:
def has_cached_keys(self, session_id: bytes) -> bool:
"""
Check if cached keys are available for the session.
Return True if cached keys are available for the CDM session.
Args:
session_id: Session identifier
@@ -757,7 +757,7 @@ class CustomRemoteCDM:
self, session_id: bytes, pssh_or_wrm: Any, license_type: str = "STREAMING", privacy_mode: bool = True
) -> bytes:
"""
Generate a license challenge using the custom CDM API.
Make a license challenge with the custom CDM API.
This method implements intelligent caching logic that checks vaults first,
then attempts to retrieve cached keys from the API, and only makes a
@@ -895,10 +895,10 @@ class CustomRemoteCDM:
"""
Parse license response using the custom CDM API.
Vault keys and cached keys are collected first, then any license key whose key ID is not
already present is appended. Key IDs are matched with dashes stripped and case ignored, so
an existing key wins over a license key for the same ID. If the session already holds final
keys and has no cached keys left to combine, the call is a no-op.
The method collects vault keys and cached keys first, then appends any license key whose
key ID is not already present. It matches key IDs with dashes stripped and case ignored, so
an existing content key wins over a license key for the same ID. If the CDM session already
holds final keys and has no cached keys left to combine, the call is a no-op.
Args:
session_id: Session identifier
@@ -1007,14 +1007,14 @@ class CustomRemoteCDM:
def get_keys(self, session_id: bytes, type_: Optional[str] = None) -> List[Key]:
"""
Get keys from the session.
Get keys from the CDM session.
Args:
session_id: Session identifier
type_: Optional key type filter (CONTENT, SIGNING, etc.)
type_: Optional type filter (CONTENT, SIGNING, and the other types)
Returns:
List of Key objects
List of `Key` objects
Raises:
InvalidSession: If session ID is invalid
+32 -32
View File
@@ -25,7 +25,7 @@ class MockCertificateChain:
class Key:
"""Key object compatible with pywidevine."""
"""`Key` object compatible with pywidevine."""
def __init__(self, kid: str, key: str, type_: str = "CONTENT"):
if isinstance(kid, str):
@@ -52,7 +52,7 @@ class DecryptLabsRemoteCDMExceptions:
"""Raised when session ID is invalid."""
class TooManySessions(Exception):
"""Raised when session limit is reached."""
"""Raised when the CDM sessions reach the limit."""
class InvalidInitData(Exception):
"""Raised when PSSH/init data is invalid."""
@@ -64,7 +64,7 @@ class DecryptLabsRemoteCDMExceptions:
"""Raised when license message is invalid."""
class InvalidContext(Exception):
"""Raised when session has no context data."""
"""Raised when the CDM session has no context data."""
class SignatureMismatch(Exception):
"""Raised when signature verification fails."""
@@ -78,15 +78,15 @@ class DecryptLabsRemoteCDM:
Decrypt Labs' KeyXtractor API service, enhanced with smart caching logic
that minimizes unnecessary license requests.
Key Features:
Main Features:
- Compatible with both Widevine and PlayReady DRM schemes
- Intelligent caching that compares required vs. available keys
- Optimized caching for L1/L2 devices (leverages API auto-optimization)
- Automatic key combination for mixed cache/license scenarios
- Seamless fallback to license requests when keys are missing
- Automatic content key combination for mixed cache/license scenarios
- Fallback to license requests when keys are missing
Intelligent Caching System:
1. DRM classes (PlayReady/Widevine) provide required KIDs via set_required_kids()
1. DRM classes (PlayReady/Widevine) give the required KIDs through set_required_kids()
2. get_license_challenge() first checks for cached keys
3. For L1/L2 devices, always attempts cached keys first (API optimized)
4. If cached keys satisfy requirements, returns empty challenge (no license needed)
@@ -109,14 +109,14 @@ class DecryptLabsRemoteCDM:
**kwargs,
):
"""
Initialize Decrypt Labs Remote CDM for Widevine and PlayReady schemes.
Initialise Decrypt Labs Remote CDM for Widevine and PlayReady schemes.
Args:
secret: Decrypt Labs API key (matches config format)
host: Decrypt Labs API host URL (matches config format)
device_name: DRM scheme (ChromeCDM, L1, L2 for Widevine; SL2, SL3 for PlayReady)
service_name: Service name for key caching and vault operations
vaults: Vaults instance for local key caching
device_name: DRM system device name. Widevine takes ChromeCDM, L1 or L2, and PlayReady takes SL2 or SL3
service_name: Service tag for content key caching and vault operations
vaults: Vaults instance for local content key caching
device_type: Device type (CHROME, ANDROID, PLAYREADY) - for compatibility
system_id: System ID - for compatibility
security_level: Security level - for compatibility
@@ -169,7 +169,7 @@ class DecryptLabsRemoteCDM:
@property
def is_playready(self) -> bool:
"""Check if this CDM is in PlayReady mode."""
"""Return True if this CDM is in PlayReady mode."""
return self._is_playready
@property
@@ -186,7 +186,7 @@ class DecryptLabsRemoteCDM:
Set the required Key IDs for intelligent caching decisions.
This method enables the CDM to make smart decisions about when to request
additional keys via license challenges. When cached keys are available,
additional keys through license challenges. When cached keys are available,
the CDM will compare them against the required KIDs to determine if a
license request is still needed for missing keys.
@@ -194,8 +194,8 @@ class DecryptLabsRemoteCDM:
kids: List of required Key IDs as UUIDs or hex strings
Note:
Should be called by DRM classes (PlayReady/Widevine) before making
license challenge requests to enable optimal caching behavior.
Call this method from the DRM classes (PlayReady/Widevine) before a
license challenge request, to enable optimal caching behaviour.
"""
self._required_kids = []
for kid in kids:
@@ -205,7 +205,7 @@ class DecryptLabsRemoteCDM:
self._required_kids.append(str(kid).replace("-", "").lower())
def generate_session_id(self) -> bytes:
"""Generate a unique session ID."""
"""Make a unique session ID."""
return secrets.token_bytes(16)
def get_init_data_from_pssh(self, pssh: Any) -> str:
@@ -263,7 +263,7 @@ class DecryptLabsRemoteCDM:
def close(self, session_id: bytes) -> None:
"""
Close a CDM session and perform comprehensive cleanup.
Close a CDM session and do comprehensive cleanup.
Args:
session_id: Session identifier
@@ -280,7 +280,7 @@ class DecryptLabsRemoteCDM:
def get_service_certificate(self, session_id: bytes) -> Optional[bytes]:
"""
Get the service certificate for a session.
Get the service certificate for a CDM session.
Args:
session_id: Session identifier
@@ -298,7 +298,7 @@ class DecryptLabsRemoteCDM:
def set_service_certificate(self, session_id: bytes, certificate: Optional[Union[bytes, str]]) -> str:
"""
Set the service certificate for a session.
Set the service certificate for a CDM session.
Args:
session_id: Session identifier
@@ -330,7 +330,7 @@ class DecryptLabsRemoteCDM:
def has_cached_keys(self, session_id: bytes) -> bool:
"""
Check if cached keys are available for the session.
Return True if cached keys are available for the CDM session.
Args:
session_id: Session identifier
@@ -352,7 +352,7 @@ class DecryptLabsRemoteCDM:
self, session_id: bytes, pssh_or_wrm: Any, license_type: str = "STREAMING", privacy_mode: bool = True
) -> bytes:
"""
Generate a license challenge using Decrypt Labs API with intelligent caching.
Make a license challenge with the Decrypt Labs API and intelligent caching.
This method implements smart caching logic that:
1. First checks local vaults for required keys
@@ -364,7 +364,7 @@ class DecryptLabsRemoteCDM:
The intelligent caching works as follows:
- Local vaults: Always checked first if available
- For L1/L2 devices: Always prioritizes cached keys (API automatically optimizes)
- For other devices: Uses cache retry logic based on session state
- For other devices: Uses cache retry logic based on CDM session state
- With required KIDs set: Only requests license for missing keys
- Without required KIDs: Returns any available cached keys
- For PlayReady: Combines vault, cached, and license keys seamlessly
@@ -383,7 +383,7 @@ class DecryptLabsRemoteCDM:
requests.RequestException: If API request fails
Note:
Call set_required_kids() before this method for optimal caching behavior.
Call set_required_kids() before this method for optimal caching behaviour.
L1/L2 devices automatically use cached keys when available per API design.
Local vault keys are always checked first when vaults are available.
"""
@@ -546,17 +546,17 @@ class DecryptLabsRemoteCDM:
def parse_license(self, session_id: bytes, license_message: Union[bytes, str]) -> None:
"""
Parse license response using Decrypt Labs API with intelligent key combination.
Parse license response with the Decrypt Labs API and intelligent content key combination.
For PlayReady content with partial cached keys, this method intelligently
For PlayReady titles with partial cached keys, this method intelligently
combines the cached keys with newly obtained license keys, avoiding
duplicates while ensuring all required keys are available.
The key combination process:
The content key combination process:
1. Extracts keys from the license response
2. If cached keys exist (PlayReady), combines them with license keys
3. Removes duplicate keys by comparing normalized KIDs
4. Updates the session with the complete key set
4. Updates the CDM session with the complete content key set
Args:
session_id: Session identifier
@@ -679,14 +679,14 @@ class DecryptLabsRemoteCDM:
def get_keys(self, session_id: bytes, type_: Optional[str] = None) -> List[Key]:
"""
Get keys from the session.
Get keys from the CDM session.
Args:
session_id: Session identifier
type_: Optional key type filter (CONTENT, SIGNING, etc.)
type_: Optional type filter (CONTENT, SIGNING, and the other types)
Returns:
List of Key objects
List of `Key` objects
Raises:
InvalidSession: If session ID is invalid
@@ -706,10 +706,10 @@ class DecryptLabsRemoteCDM:
"""Parse cached keys from API response.
Args:
cached_keys_data: List of cached key objects from API
cached_keys_data: List of cached content key objects from API
Returns:
List of key dictionaries
List of content key dictionaries
"""
keys = []
+6 -6
View File
@@ -5,7 +5,7 @@ from typing import Any
def is_remote_cdm(cdm: Any) -> bool:
"""
Return True if the CDM instance is backed by a remote/service CDM.
Return True if a remote CDM or a service CDM backs the CDM instance.
This is useful for service logic that needs to know whether the CDM runs
locally (in-process) vs over HTTP/RPC (remote).
@@ -102,11 +102,11 @@ def cdm_location(cdm: Any) -> str:
def is_playready_cdm(cdm: Any) -> bool:
"""
Return True if the given CDM should be treated as PlayReady.
Return True if unshackle treats the given CDM as PlayReady.
This intentionally supports both:
- Local PlayReady CDMs (pyplayready.cdm.Cdm)
- Remote/wrapper CDMs (e.g. DecryptLabsRemoteCDM) that expose `is_playready`
- Remote/wrapper CDMs (for example DecryptLabsRemoteCDM) that have `is_playready`
"""
if cdm is None:
@@ -162,10 +162,10 @@ def is_remote_widevine_cdm(cdm: Any) -> bool:
def is_widevine_cdm(cdm: Any) -> bool:
"""
Return True if the given CDM should be treated as Widevine.
Return True if unshackle treats the given CDM as Widevine.
Note: for remote/wrapper CDMs that expose `is_playready`, Widevine is treated
as the logical opposite.
Note: for remote/wrapper CDMs that have `is_playready`, unshackle treats
Widevine as the logical opposite.
"""
if cdm is None:
+1 -1
View File
@@ -2,7 +2,7 @@
Instantiates a CDM object (local or remote) given a resolved device name.
Name resolution (quality-based, profile-based, DRM-type) is the caller's
responsibility; this module only handles the instantiation step.
responsibility. This module does the instantiation step only.
"""
from __future__ import annotations
+11 -11
View File
@@ -1,8 +1,8 @@
"""
MonaLisa CDM - WASM-based Content Decryption Module wrapper.
This module provides key extraction from MonaLisa-protected content using
a WebAssembly module that runs locally via wasmtime.
This module extracts content keys from MonaLisa-protected titles. It uses a
WebAssembly module that runs locally with wasmtime.
"""
import base64
@@ -25,12 +25,12 @@ logger = logging.getLogger(__name__)
class MonaLisaCDM:
"""
MonaLisa CDM wrapper for WASM-based key extraction.
MonaLisa CDM wrapper for WASM-based content key extraction.
This CDM differs from Widevine/PlayReady in that it does not use a
challenge/response flow with a license server. Instead, the license
(ticket) is provided directly by the service API, and keys are extracted
locally via the WASM module.
challenge/response flow with a license server. Instead, the service API
gives the license (ticket) directly, and the WASM module extracts the
content keys locally.
"""
DYNAMIC_BASE = 6065008
@@ -50,7 +50,7 @@ class MonaLisaCDM:
def __init__(self, device_path: Path):
"""
Initialize the MonaLisa CDM.
Initialise the MonaLisa CDM.
Args:
device_path: Path to the device file (.mld).
@@ -108,7 +108,7 @@ class MonaLisaCDM:
Session ID (always 1 for MonaLisa).
Raises:
RuntimeError: If session initialization fails.
RuntimeError: If CDM session initialization fails.
"""
try:
self.store = wasmtime.Store(self.engine)
@@ -179,7 +179,7 @@ class MonaLisaCDM:
Dictionary with keys: kid (hex), key (hex), type ("CONTENT").
Raises:
RuntimeError: If session not open or license validation fails.
RuntimeError: If the CDM session is not open, or license validation fails.
ValueError: If license_data is empty.
"""
if not self.instance or not self.memory or self.ctx is None:
@@ -233,7 +233,7 @@ class MonaLisaCDM:
return {"kid": kid_bytes.hex(), "key": key_bytes.hex(), "type": "CONTENT"}
def extract_license_key_bytes(self) -> bytes:
"""Extract the 16-byte decryption key from WASM memory."""
"""Extract the 16-byte content key from WASM memory."""
data_ptr = self.memory.data_ptr(self.store)
data_len = self.memory.data_len(self.store)
@@ -318,7 +318,7 @@ class MonaLisaCDM:
mem_ptr[buffer + len(encoded)] = 0
def build_imports(self):
"""Build the WASM import stubs required by the MonaLisa module."""
"""Assemble the WASM import stubs the MonaLisa module needs."""
def sys_fcntl64(a, b, c):
return 0