DRM API¶
Auto-generated reference for the DRM systems: Widevine, PlayReady, ClearKey, and related helpers. For configuring DRM as a user, see DRM & CDM Setup.
ClearKey
¶
AES-128 ClearKey (HLS) DRM system.
Give the IV where possible. If you do not give an IV, unshackle sets it to of the same bit-size as the content key.
warn_clear
¶
Warn once per track that unshackle passed a segment through undecrypted.
decrypt
¶
Decrypt a Track with AES-128 ClearKey (HLS) DRM.
A segment that fails the PKCS7 unpad is kept as decrypted: some streams are block aligned with no padding.
from_m3u_key
classmethod
¶
Load a ClearKey from an M3U(8) Playlist's EXT-X-KEY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m3u_key
|
Key
|
A |
required |
session
|
AnySession | None
|
Optional HTTP session used to request external URIs with. Useful to set headers, proxies, cookies, and so forth. |
None
|
ClearKeyCENC
¶
W3C EME ClearKey (org.w3.clearkey) DRM System over MPEG-CENC tracks.
Distinct from the HLS AES-128 ClearKey class: a license server gives the keys
here as a JWK Set keyed by KID, and the media is standard CENC
(decrypted with shaka-packager/mp4decrypt KID:KEY pairs, same as Widevine).
Exceptions
¶
get_license_challenge
¶
Assemble the W3C EME ClearKey JSON license request for the unkeyed KIDs.
get_content_keys
¶
Get Content Keys for this DRM Instance from a ClearKey license server.
The licence param is a function. unshackle gives it the W3C JSON license
request as challenge. It may return the JWK Set license as a dict, JSON str,
or bytes. If it returns None and the manifest gave a Laurl, unshackle POSTs the
challenge there directly instead.
decrypt
¶
Decrypt the file at path in place with this track's ClearKey (standard CENC) content keys.
mp4decrypt_key_args
¶
Build the mp4decrypt --key arguments for every content key, and by track ID for each track_kids KID.
ClearKeyCTR
¶
AES-128-CTR over a whole file: the service gives the IV and returns the content key through licence.
The key resolver asks licence at the licence step of a download or of a --skip-dl run, so listing tracks costs no request.
A cipher built with key holds its content key from the start.
magic is the signature the decrypted file must start with; a mismatch raises and keeps the input.
skip drops that many decrypted bytes from the start of the file: a header that sits in front of the media.
rewrite_paged rewrites a decrypted file in the paged AAC container (PAGED_AAC).
CustomDRM
¶
The DRM of a track whose system a plugin adds: plain data that can cross the wire and the export.
It holds the plugin id, its label, KIDs, a display id, the content keys and the plugin's own JSON
data; never a callable or a path. A plugin id that no loaded plugin has stops the track. With no kids
given, the plugin reads them from data.
license
¶
Fill kids and content_keys through the plugin's licence with cdm, a device of the plugin.
decrypt
¶
Decrypt path with the plugin into a new file that then replaces it; a failure keeps path.
finish
¶
Run the plugin's fix of a merged file that the plugin decrypted per segment; False when it proves no content key.
PlayReady
¶
Bases: CencDrm
PlayReady DRM System.
from_pssh_b64
classmethod
¶
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.
from_pssh_box
classmethod
¶
Make the DRM from a parsed PlayReady pssh box and the track's own KID.
header_kids
staticmethod
¶
Return the KIDs one WRM header names, in header order.
custom_attribute_kids
staticmethod
¶
Return the KIDs a WRM header lists under CUSTOMATTRIBUTES/KIDS, skipping a value that is not a KID.
absorb
¶
Fold sibling PlayReady objects into this one so their headers and KIDs get licensed too.
A manifest can attach one PlayReady object per WRM header to the same track (ISM shares its Protection list across tracks; HLS emits one per EXT-X-KEY). The caller keeps this object's identity, which the decrypt path and drm_lock depend on.
distinct_headers
¶
Return the WRM headers to license, deduplicated by the KID set each one names.
Two headers naming the same KIDs (a v4.0 header beside its v4.3 twin, or one PRH per rendition for one content key) cost one challenge. A header with no readable KID is kept: it may still be the only route to a content key nothing else names.
pro_b64_for
staticmethod
¶
Build a base64 one-record PlayReady Object holding only this header.
Remote CDMs send the value given to set_pssh_b64 rather than the header passed to get_license_challenge, so a per-header challenge needs a per-header PRO.
extract_keys_from_cdm
¶
Map each licence key to its hex content key: pyplayready names the KID key_id, pywidevine (HttpCdm) kid.
get_content_keys
¶
License every distinct WRM header whose KIDs still lack a content key.
A v4.2+ header may list several KIDs and one response may stack several licences, so one challenge often covers everything. Content that ships several headers (ISM with one ProtectionHeader per track type, HLS with one PRH per playlist) gets one challenge per header that is not yet covered. Headers are sent as-is: Microsoft lets the server ignore the header, so a merged header could ask for keys it never grants.
A header that a round refused, or that yielded nothing, is not sent again by this object: every track of a title runs this method, and a repeat would only repeat the refusal.
detect_revocation
staticmethod
¶
Return the decoded error string if a revocation HRESULT is present, else None.
Reads the code from the raw SOAP body (
Widevine
¶
Bases: CencDrm
Widevine DRM System.
Exceptions
¶
PSSHNotFound
¶
Bases: Exception
PSSH (Protection System Specific Header) was not found.
KIDNotFound
¶
Bases: Exception
KID (Encryption Key ID) was not found.
CEKNotFound
¶
Bases: ClickException
CEK (Content Encryption Key) for KID was not found in License.
EmptyLicense
¶
Bases: ClickException
License returned no Content Encryption Keys.
from_playready
staticmethod
¶
A Widevine PSSH naming a v1 box's own KIDs, then the KIDs the PlayReady class reads from it.
pywidevine's own conversion fails on a bare WRMHEADER and byte-swaps PlayReady KIDs.
from_pssh_box
classmethod
¶
Make the DRM from a parsed Widevine pssh box and the track's own KID.
get_content_keys
¶
Make a CDM Session and get Content Keys for this DRM Instance. The certificate and license params are functions. unshackle gives them the challenge and the session ID.
whole_file_cipher
¶
The whole-file cipher of a track, with or without a content key.
is_null_key
¶
True for a blank or all-zero content key, the null key that no vault stores.
own_cipher
¶
True for a cipher that is not CENC: it has no KID to probe and no fragment to check.
device_licensed
¶
True for a plugin DRM that a plugin device licenses, which the server may license and the decode check judges.
held_key
¶
True for a plugin DRM that holds its content key from the start, so no licence step and no server key apply.
drop_null_keys
¶
Remove the null keys from a DRM object's content keys. A read-only key view stays as it is.
real_kids
¶
Return the KIDs a DRM object names, without the all-zero and test-pattern placeholders.
own_kids
¶
Return the real KIDs that identify the track's own content key, as the DRM object knows them.