mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-02 05:55:08 +00:00
feat(drm): bridge a FairPlay-only HLS track only for a service with get_fairplay_bridge_license
This commit is contained in:
@@ -451,11 +451,48 @@ needs:
|
||||
| `get_widevine_license(title, track, challenge)` | license bytes | POST the Widevine challenge to the license server, return the response. |
|
||||
| `get_playready_license(title, track, challenge)` | license | Same for PlayReady; defaults to delegating to Widevine. |
|
||||
| `get_clearkey_license(title, track, challenge)` | dict / str / bytes / `None` | For `ClearKeyCENC`; return `None` to let the framework POST to the manifest `Laurl`. |
|
||||
| `get_fairplay_bridge_license(title, track, challenge, drm_system)` | license | Optional, not on the base class. Licenses a FairPlay-only HLS track; see [The FairPlay bridge hook](#the-fairplay-bridge-hook). |
|
||||
|
||||
You do not open CDM sessions or operate shaka-packager yourself. The `Widevine`/`PlayReady`
|
||||
classes drive the CDM handshake and call the decryption backend. Your hook is only the
|
||||
"send this challenge, give me back the license" step.
|
||||
|
||||
### The FairPlay bridge hook
|
||||
|
||||
unshackle has no FairPlay CDM and never sends a FairPlay challenge. For a FairPlay-only track it can send a PlayReady or Widevine challenge for the KIDs of the init segments to the licence server of the platform, which works only when that server issues the same content key to PlayReady or Widevine. The bridge runs only for a service that defines
|
||||
`get_fairplay_bridge_license`. The base class does not define it.
|
||||
|
||||
```python
|
||||
def get_fairplay_bridge_license(
|
||||
self, *, challenge: bytes, title: Title_T, track: AnyTrack, drm_system: str
|
||||
) -> bytes | str:
|
||||
"""The licence server of this platform issues the content keys of its FairPlay-only tracks to PlayReady."""
|
||||
licence = self.get_playready_license if drm_system == "playready" else self.get_widevine_license
|
||||
return licence(challenge=challenge, title=title, track=track)
|
||||
```
|
||||
|
||||
- `drm_system` is `"playready"` or `"widevine"`. The hook must accept it.
|
||||
- The hook can also declare the arguments of the licence callback of that system: `pssh` for Widevine,
|
||||
`pssh_b64` for PlayReady, and `session_id`. It gets only the arguments that it declares.
|
||||
- The key IDs are on the DRM object of the track (`track.drm[0].kids`) when the hook runs. A service that
|
||||
needs its own request shape builds the request in the hook.
|
||||
- The challenge of every other track goes to `get_playready_license` or `get_widevine_license`, as before.
|
||||
|
||||
The DRM system of the challenge is the `drm_preference` of the track, else the system of the configured
|
||||
CDM. For a licence server that issues the content key to one system only, set `drm_preference` on the
|
||||
FairPlay-only tracks in `get_tracks()`:
|
||||
|
||||
```python
|
||||
for track in tracks.videos + tracks.audio:
|
||||
if not track.drm:
|
||||
track.drm_preference = "playready"
|
||||
```
|
||||
|
||||
Without the hook, the download of a FairPlay-only track stops with
|
||||
`None of the key systems are supported`, and no challenge goes to the licence server. A licence
|
||||
server that does not issue the content key refuses the challenge, and can flag the device. Test the route with a licence-only run
|
||||
(`--cdm-only --skip-dl`) before a service relies on it.
|
||||
|
||||
### Decrypting a cbcs file yourself
|
||||
|
||||
Some tracks cannot use the framework's decryption: a single cbcs file whose sample entries share
|
||||
@@ -479,26 +516,28 @@ that needs a process on the server also works for a remote client.
|
||||
|
||||
A media playlist can name only a key system that unshackle does not read, such as an `skd://` key
|
||||
over cbcs media, while the licence server of the platform also issues the same content key over
|
||||
PlayReady or Widevine. `HLS.download_track` licenses such a track with no service code when all of
|
||||
these conditions are true:
|
||||
PlayReady or Widevine. `HLS.download_track` licenses such a track when all of these conditions are true:
|
||||
|
||||
- The service has the [FairPlay bridge hook](#the-fairplay-bridge-hook).
|
||||
- The track has no DRM object.
|
||||
- Every `EXT-X-KEY` of its media playlist is `SAMPLE-AES` or `SAMPLE-AES-CTR` for a DRM system
|
||||
unshackle cannot license, or `METHOD=NONE`. A segment under `METHOD=NONE` must have an init segment
|
||||
that no encrypted segment uses: a decrypter that reads the encrypted init segment decrypts the clear
|
||||
samples too. A tag with `KEYFORMAT="identity"`, or with no `KEYFORMAT`, names no DRM system: each
|
||||
encrypted segment also needs a tag of a DRM system.
|
||||
- The configured CDM is a PlayReady or Widevine CDM.
|
||||
- The `drm_preference` of the track, or else the configured CDM, is PlayReady or Widevine.
|
||||
- The init segment (`EXT-X-MAP`) of the track names a key ID in its `tenc` box. When the `tenc` key ID is all
|
||||
zeros, the playlist must have one key URI, and each init segment under the key tag must give the same
|
||||
key ID: its `tenc` key ID, or else the one key ID that its `pssh` boxes name. A clear init segment,
|
||||
such as the one of a clear lead or tail, does not count. MPEG-TS media has no init segment.
|
||||
- The init segment does not change without an `EXT-X-DISCONTINUITY`.
|
||||
|
||||
The download reads the key ID from the init segment, builds a DRM object for the DRM system of the
|
||||
CDM with `drm_stub`, and sends the challenge to the licence callback of the service. Over `--remote`
|
||||
the server reads the same key ID at the licence step, so it accepts the DRM object of the client. A
|
||||
licence that gives no content key stops the track before it downloads a segment.
|
||||
The download reads the key ID from the init segment, builds a DRM object for that DRM system with
|
||||
`drm_stub`, and sends the challenge to the hook. Over `--remote` the tracks reply tells the client that
|
||||
the service on the server has the hook. The server reads the same key ID at the licence step, accepts
|
||||
the DRM object of the client and sends the challenge to the hook of its service. A server that cannot
|
||||
read the key ID refuses the challenge. A licence that gives no content key stops the track before it
|
||||
downloads a segment.
|
||||
|
||||
unshackle reads one key ID from each init segment. So it licenses a playlist that changes its content key
|
||||
correctly only when each content key has its own init segment with a real `tenc` key ID, after an
|
||||
|
||||
@@ -78,7 +78,14 @@ need a `.prd` device. You can hold both, and unshackle automatically selects the
|
||||
appropriate one for each track.
|
||||
|
||||
!!! note "HLS tracks with only a FairPlay key tag"
|
||||
unshackle has no FairPlay CDM. When each `EXT-X-KEY` of an fMP4 playlist is sample encryption
|
||||
unshackle has no FairPlay CDM and never sends a FairPlay challenge.
|
||||
For a FairPlay-only track it can send a PlayReady or Widevine challenge for the KIDs of the init
|
||||
segments to the licence server of the platform, which works only when that server issues the same
|
||||
content key to PlayReady or Widevine.
|
||||
Only a service that defines this route does it. For another service, the download of a FairPlay-only
|
||||
track stops with `None of the key systems are supported`.
|
||||
|
||||
When each `EXT-X-KEY` of an fMP4 playlist is sample encryption
|
||||
for a DRM system that unshackle cannot license, such as FairPlay, unshackle reads the key ID from
|
||||
the init segment and asks for the licence with your PlayReady or Widevine device. unshackle reads one
|
||||
key ID from each init segment. So it licenses a playlist that changes its content key correctly only
|
||||
@@ -579,8 +586,8 @@ unshackle dl --skip-dl --all-drm --export EXAMPLE 81234567
|
||||
system does not license, so the title fails unless you use `--best-available`.
|
||||
- An HLS playlist that changes its `EXT-X-KEY` entries part-way: only the first set
|
||||
licenses with the second system.
|
||||
- An HLS playlist with only FairPlay key tags: the DRM system of the configured CDM
|
||||
licenses it.
|
||||
- An HLS playlist with only FairPlay key tags, for a service that defines the FairPlay
|
||||
route: the DRM system of the track's `drm_preference`, else of the configured CDM, licenses it.
|
||||
- A remote session that the server CDM licenses, and `unshackle import`. unshackle
|
||||
shows a warning and ignores the flag.
|
||||
- A remote CDM that stores content keys can answer without a challenge to the service.
|
||||
|
||||
Reference in New Issue
Block a user