Deployed 87b58190 with MkDocs version: 1.6.1

This commit is contained in:
2026-12-05 03:00:15 +00:00
parent 56cac92f20
commit 6ed040a6dd
44 changed files with 17665 additions and 13063 deletions
+285 -412
View File
@@ -16,7 +16,7 @@
<link rel="prev" href="../creating-a-service/">
<link rel="next" href="../rest-api/">
<link rel="next" href="../rest-api/quickstart/">
@@ -347,28 +347,6 @@
<li class="md-tabs__item">
<a href="../../reference/api/service/" class="md-tabs__link">
API Reference
</a>
</li>
</ul>
</div>
</nav>
@@ -614,6 +592,8 @@
@@ -886,6 +866,171 @@
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_9" >
<div class="md-nav__link md-nav__container">
<a href="../rest-api/" class="md-nav__link ">
<span class="md-ellipsis">
Server
</span>
</a>
<label class="md-nav__link " for="__nav_3_9" id="__nav_3_9_label" tabindex="0">
<span class="md-nav__icon md-icon"></span>
</label>
</div>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_9_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_9">
<span class="md-nav__icon md-icon"></span>
Server
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../rest-api/authentication/" class="md-nav__link">
<span class="md-ellipsis">
Authentication
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../rest-api/dashboard/" class="md-nav__link">
<span class="md-ellipsis">
Dashboard
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../guide/remote-sessions/" class="md-nav__link">
<span class="md-ellipsis">
Remote Sessions
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
@@ -1078,7 +1223,7 @@
<span class="md-ellipsis">
Output & Naming
Output & Naming Options
@@ -1162,7 +1307,7 @@
<span class="md-ellipsis">
Key Vaults
Key Vault Options
@@ -1282,6 +1427,8 @@
@@ -1794,14 +1941,6 @@
@@ -1830,9 +1969,8 @@
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_3" >
<div class="md-nav__link md-nav__container">
<a href="../rest-api/" class="md-nav__link ">
<label class="md-nav__link" for="__nav_5_3" id="__nav_5_3_label" tabindex="">
<span class="md-ellipsis">
@@ -1846,14 +1984,8 @@
</a>
<label class="md-nav__link " for="__nav_5_3" id="__nav_5_3_label" tabindex="">
<span class="md-nav__icon md-icon"></span>
</label>
</div>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_3">
@@ -1867,8 +1999,6 @@
<ul class="md-nav__list" data-md-scrollfix>
@@ -1882,35 +2012,7 @@
<span class="md-ellipsis">
Quick Start
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../rest-api/authentication/" class="md-nav__link">
<span class="md-ellipsis">
Authentication
REST API Quick Start
@@ -1987,14 +2089,14 @@
<li class="md-nav__item">
<a href="../rest-api/dashboard/" class="md-nav__link">
<a href="../rest-api/errors/" class="md-nav__link">
<span class="md-ellipsis">
Dashboard
Error Responses
@@ -2022,7 +2124,7 @@
<span class="md-ellipsis">
Remote Sessions
Remote Session Protocol
@@ -2036,55 +2138,20 @@
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../rest-api/errors/" class="md-nav__link">
<span class="md-ellipsis">
Error Responses
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
@@ -2103,25 +2170,28 @@
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6" >
<label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="0">
<li class="md-nav__item md-nav__item--section md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_4" >
<label class="md-nav__link" for="__nav_5_4" id="__nav_5_4_label" tabindex="">
<span class="md-ellipsis">
API Reference
Python API
@@ -2132,12 +2202,12 @@
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6">
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_4">
<span class="md-nav__icon md-icon"></span>
API Reference
Python API
</label>
@@ -2289,6 +2359,14 @@
</li>
</ul>
</nav>
</li>
</ul>
</nav>
@@ -2736,63 +2814,9 @@ does the rest.</p>
Two kinds of members matter: <strong>class variables</strong> that give the details of the service, and
<strong>methods</strong> that the pipeline calls.</p>
<h3 id="class-variables">Class variables<a class="headerlink" href="#class-variables" title="Permanent link">&para;</a></h3>
<p>Declared at the top of your service class, these are static descriptors:</p>
<table>
<thead>
<tr>
<th>Class variable</th>
<th>Type</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>ALIASES</code></td>
<td><code>tuple[str, ...]</code></td>
<td>Alternate tags the service answers to, in any case (resolved by <code>Services.get_tag</code>).</td>
</tr>
<tr>
<td><code>GEOFENCE</code></td>
<td><code>tuple[str, ...]</code></td>
<td>ISO region codes the service requires; empty means no geofence. unshackle treats the first entry as the "main region" for automatic proxy selection.</td>
</tr>
<tr>
<td><code>GEOBLOCK</code></td>
<td><code>tuple[str, ...]</code></td>
<td>ISO region codes where the service refuses to work; every other region is allowed. Use it for a service that works worldwide except in its home market.</td>
</tr>
<tr>
<td><code>VAULT_TAG</code></td>
<td><code>Optional[str]</code></td>
<td>Overrides the key-vault namespace; defaults to the service's own tag.</td>
</tr>
<tr>
<td><code>AUTH_METHODS</code></td>
<td><code>Optional[tuple[str, ...]]</code></td>
<td>Accepted auth methods (<code>"cookies"</code> / <code>"credentials"</code>). When <code>None</code>, the REST <code>/services</code> endpoint infers them from <code>authenticate()</code>.</td>
</tr>
<tr>
<td><code>ANONYMOUS_SEARCH</code></td>
<td><code>bool</code></td>
<td><code>search()</code> needs no login and no state from <code>authenticate()</code>. A search then skips the cookie load, <code>authenticate()</code> and the cookie save. Default <code>False</code>.</td>
</tr>
<tr>
<td><code>ANIME</code></td>
<td><code>bool</code></td>
<td>The catalogue is anime, so metadata lookups prefer AniList. A title's own <code>anime</code> flag overrides it.</td>
</tr>
<tr>
<td><code>METADATA_PROVIDER</code></td>
<td><code>Optional[str]</code></td>
<td>The metadata provider the catalogue resolves through, such as <code>"tmdb"</code>. Lookups try it first. It only reorders <code>metadata_providers</code> and never adds a provider the user left out. A title's own <code>metadata_provider</code> overrides it.</td>
</tr>
<tr>
<td><code>DAILY</code></td>
<td><code>bool</code></td>
<td>The catalogue is daily/date-based, so unshackle names episodes by air date. A title's own <code>daily</code> flag overrides it.</td>
</tr>
</tbody>
</table>
<p>Declared at the top of your service class, class variables such as <code>ALIASES</code>, <code>GEOFENCE</code> and
<code>NO_SUBTITLES</code> describe the service to the framework. The attributes table of
<a class="autorefs autorefs-internal" title="&lt;code class=&quot;doc-symbol doc-symbol-heading doc-symbol-class&quot;&gt;&lt;/code&gt; &lt;span class=&quot;doc doc-object-name doc-class-name&quot;&gt;Service&lt;/span&gt;" href="../../reference/api/service/#unshackle.core.service.Service"><code>Service</code></a> in the Service API gives each one, with its type and purpose.</p>
<h3 id="required-methods">Required methods<a class="headerlink" href="#required-methods" title="Permanent link">&para;</a></h3>
<p>These are abstract. A service will not load unless it defines all three:</p>
<ul>
@@ -2808,14 +2832,12 @@ Two kinds of members matter: <strong>class variables</strong> that give the deta
<li><strong><code>search()</code></strong>: raises <code>NotImplementedError</code> by default. Write it so that the
<code>search</code> command can operate. unshackle calls <code>authenticate()</code> first, unless the
service sets <code>ANONYMOUS_SEARCH</code>.</li>
<li><strong>DRM license hooks</strong>: <code>get_widevine_service_certificate</code>, <code>get_widevine_license</code>,
<code>get_playready_license</code> (delegates to Widevine by default), and
<code>get_clearkey_license</code> (returns <code>None</code> by default). See <a href="#drm-hooks">DRM hooks</a> below.</li>
<li><strong><code>request_input(prompt, qr=None)</code></strong>: prompts the user. It goes through the remote-dl input
<li><strong>Licence callbacks</strong>: see <a href="#drm-hooks">DRM hooks</a> below.</li>
<li><strong><code>request_input(prompt, qr=None)</code></strong>: prompts the user. It goes through the remote session input
bridge, the REST download job relay, or the rich console.</li>
<li><strong><code>wait_for_approval(message, check, timeout, interval=3.0, qr=None)</code></strong>: shows a message, then
calls <code>check</code> until it returns a value. Use it for a login that the user approves on
another device, such as a pair code. A remote-dl session shows the message as a log
another device, such as a pair code. A remote session shows the message as a log
line, and a REST download job shows it as the job's <code>notice</code>. Both methods take <code>qr</code>, the
text of a QR code to scan, and the terminal or UI that shows the user the message draws it.
When the login API gives only a PNG, <code>read_qr_image(data)</code> in <code>unshackle.core.console</code>
@@ -2826,49 +2848,9 @@ Two kinds of members matter: <strong>class variables</strong> that give the deta
</ul>
<h3 id="what-__init__-wires-up-for-you">What <code>__init__</code> wires up for you<a class="headerlink" href="#what-__init__-wires-up-for-you" title="Permanent link">&para;</a></h3>
<p>You rarely override <code>__init__</code>. The base constructor takes the Click context and sets
up the objects your methods rely on:</p>
<table>
<thead>
<tr>
<th>Attribute</th>
<th>What it is</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>self.config</code></td>
<td>The merged service config (see <a href="#request-and-http-session-objects">Request and HTTP session objects</a>).</td>
</tr>
<tr>
<td><code>self.log</code></td>
<td>A <code>logging.Logger</code> named after your class.</td>
</tr>
<tr>
<td><code>self.session</code></td>
<td>A ready-to-use HTTP session (headers, retries, and proxy applied). Send every request through it: with a proxy active, a request from service code that does not go through the proxy logs a warning. A separate HTTP session that goes direct on purpose sets <code>proxy_exempt = True</code>.</td>
</tr>
<tr>
<td><code>self.cache</code></td>
<td>A generic key/value <code>Cacher</code> namespaced to the service.</td>
</tr>
<tr>
<td><code>self.title_cache</code></td>
<td>A region- and account-aware <code>TitleCacher</code>.</td>
</tr>
<tr>
<td><code>self.cache_dir</code></td>
<td><code>config.directories.cache / &lt;ServiceName&gt;</code>.</td>
</tr>
<tr>
<td><code>self.credential</code></td>
<td>The active <code>Credential</code>, or <code>None</code> until authenticated.</td>
</tr>
<tr>
<td><code>self.track_request</code></td>
<td>A <code>TrackRequest</code> describing the requested codecs, ranges, and best-available flag (see below).</td>
</tr>
</tbody>
</table>
up the objects your methods rely on, such as <code>self.session</code>, <code>self.cache</code> and <code>self.track_request</code>.
The attributes table of <a class="autorefs autorefs-internal" title="&lt;code class=&quot;doc-symbol doc-symbol-heading doc-symbol-class&quot;&gt;&lt;/code&gt; &lt;span class=&quot;doc doc-object-name doc-class-name&quot;&gt;Service&lt;/span&gt;" href="../../reference/api/service/#unshackle.core.service.Service"><code>Service</code></a> lists each one.
<a href="#request-and-http-session-objects">Request and HTTP session objects</a> explains the main ones.</p>
<p>The constructor also resolves proxies: it reads <code>--proxy</code>, which <code>dl</code> and <code>search</code> have already
resolved through the per-service <code>proxy_map</code>, and, if <code>GEOFENCE</code> is set and you did not give an explicit proxy, does a live
IP check and auto-fetches a proxy to <code>GEOFENCE[0]</code> when it detects a geoblock. A
@@ -2879,12 +2861,16 @@ outside <code>GEOFENCE</code> logs a warning and the run continues.
See <a href="../../guide/proxies-and-vpn/">Proxies and VPN</a>.</p>
<div class="admonition note">
<p class="admonition-title"><code>TrackRequest</code></p>
<p><code>self.track_request</code> is a small dataclass built from the CLI: <code>codecs</code>
(from <code>--vcodec</code>, empty means "accept any"), <code>ranges</code> (from <code>--range</code>, default
<code>[Video.Range.SDR]</code>), <code>best_available</code>, and <code>generate_dv</code> (from <code>--generate-dv</code>).
Use it in <code>get_tracks</code> to decide which variants to fetch. A service that fetches
<p><code>self.track_request</code> is a <a class="autorefs autorefs-internal" title="&lt;code class=&quot;doc-symbol doc-symbol-heading doc-symbol-class&quot;&gt;&lt;/code&gt; &lt;span class=&quot;doc doc-object-name doc-class-name&quot;&gt;TrackRequest&lt;/span&gt;
&lt;span class=&quot;doc doc-labels&quot;&gt;
&lt;small class=&quot;doc doc-label doc-label-dataclass&quot;&gt;&lt;code&gt;dataclass&lt;/code&gt;&lt;/small&gt;
&lt;/span&gt;" href="../../reference/api/service/#unshackle.core.service.TrackRequest"><code>TrackRequest</code></a> built from the
CLI. Use it in <code>get_tracks</code> to decide which variants to fetch. A service that fetches
the HYBRID variants itself must also fetch HDR10P when <code>generate_dv</code> is set and
the title has no DV track, because unshackle prefers an HEVC HDR10+ base.</p>
the title has no DV track, because unshackle prefers an HEVC HDR10+ base.
<code>get_tracks_for_variants</code> does this for you.</p>
</div>
<h2 id="titles-and-the-title-hierarchy">Titles and the <code>Title</code> hierarchy<a class="headerlink" href="#titles-and-the-title-hierarchy" title="Permanent link">&para;</a></h2>
<p><code>get_titles()</code> returns a <strong>title collection</strong>, one of the <code>Titles_T</code> types. Each
@@ -2992,9 +2978,7 @@ copies them from the best selected lossless track (FLAC, ALAC or PCM) of the fir
If that changes the Quality row, <code>dl</code> shows the release header again. A lossy track
changes nothing.</p>
<p>A <code>Song</code> is an ordinary <code>Title</code> on the one generic download path. unshackle has no
music-specific service API and no separate music download loop. The
<code>GROUP_AUDIO_DOWNLOADS</code> flag, <code>get_music_track_options</code> and <code>get_music_collection_label</code>
no longer exist, and a music service does not need them.</p>
music-specific service API and no separate path for music.</p>
<p>Core picks the container of a <code>Song</code> from the codec in the downloaded file, so a music
service does not rename the track path. Read
<a href="../../guide/output-and-naming/#music-output-files">Music output files</a>.</p>
@@ -3105,8 +3089,8 @@ The value also goes to a <code>--remote</code> client. A track without it muxes
and <code>sdh</code>, and <code>forced</code> cannot combine with either. <code>Subtitle.Codec</code> includes <code>SubRip</code>
(SRT), <code>WebVTT</code> (VTT), <code>SubStationAlpha</code>/<code>SubStationAlphav4</code> (SSA/ASS),
<code>TimedTextMarkupLang</code> (TTML), <code>SAMI</code>, <code>SCC</code>, and the box-encapsulated DASH formats <code>fTTML</code>
(STPP) and <code>fVTT</code> (WVTT). Subtitles receive post-download normalization
(segment merging, WebVTT sanitization, format conversion, and optional SDH stripping),
(STPP) and <code>fVTT</code> (WVTT). Subtitles receive post-download normalisation
(segment merging, WebVTT sanitisation, format conversion, and optional SDH stripping),
all documented for users in <a href="../../guide/subtitles/">Subtitles</a>.</p>
<h3 id="chapters-and-attachments">Chapters and attachments<a class="headerlink" href="#chapters-and-attachments" title="Permanent link">&para;</a></h3>
<ul>
@@ -3211,33 +3195,33 @@ least one and no track is left.</p>
<li><strong>Segments</strong> of each format: unshackle inflates a segment body that is one whole gzip member
before the merge, up to a size limit. A CDN can send such a body with no <code>Content-Encoding</code>
header. Any other body stays as it is, such as AES-128 ciphertext that starts with the gzip magic.</li>
<li><strong>ISM</strong> has no list of segments and no init segments: the parser synthesizes segment URLs
<li><strong>ISM</strong> has no list of segments and no init segments: the parser synthesises segment URLs
from the <code>&lt;c&gt;</code> fragment timeline, and rebuilds a <code>moov</code>/<code>ftyp</code> init box from <code>CodecPrivateData</code>
(supported for AVC, HEVC, DV-over-HEVC, AAC, EC-3, and TTML). A track id covers the manifest
URL, so a title you build from one ISM manifest per codec or range keeps every variant:
<code>Tracks.add</code> no longer reads the second manifest's tracks as duplicates of the first.</li>
<code>Tracks.add</code> does not read the tracks of the second manifest as duplicates of the first.</li>
</ul>
<h2 id="drm-hooks">DRM hooks<a class="headerlink" href="#drm-hooks" title="Permanent link">&para;</a></h2>
<p>If a track carries DRM, the framework licenses and decrypts it, but it needs your
service to talk to the platform's license server. unshackle recognizes six DRM classes:</p>
service to talk to the platform's licence server. unshackle recognises six DRM classes:</p>
<table>
<thead>
<tr>
<th>DRM class</th>
<th>System</th>
<th>License flow</th>
<th>Licence flow</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Widevine</code></td>
<td>Widevine</td>
<td>CDM challenge → license server → content keys (<code>.wvd</code> device)</td>
<td>CDM challenge → licence server → content keys (<code>.wvd</code> device)</td>
</tr>
<tr>
<td><code>PlayReady</code></td>
<td>PlayReady</td>
<td>CDM challenge (WRM header) → license server → content keys (<code>.prd</code> device)</td>
<td>CDM challenge (WRM header) → licence server → content keys (<code>.prd</code> device)</td>
</tr>
<tr>
<td><code>ClearKeyCENC</code></td>
@@ -3257,7 +3241,7 @@ service to talk to the platform's license server. unshackle recognizes six DRM c
<tr>
<td><code>ClearKeyCTR</code></td>
<td>AES-128-CTR over a whole file</td>
<td>the service gives the IV and licenses the content key at the licence step; no CDM, no license server</td>
<td>the service gives the IV and licenses the content key at the licence step; no CDM, no licence server</td>
</tr>
</tbody>
</table>
@@ -3269,50 +3253,27 @@ decrypted with shaka-packager or mp4decrypt like Widevine.</p>
</div>
<h3 id="the-service-side-hooks">The service-side hooks<a class="headerlink" href="#the-service-side-hooks" title="Permanent link">&para;</a></h3>
<p>The framework supplies the CDM and the decryption backend. Your service gives the network
calls that must carry the CDM's challenge. Override the hooks that your platform
needs:</p>
<table>
<thead>
<tr>
<th>Hook</th>
<th>Return</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>get_widevine_service_certificate(title, track, challenge)</code></td>
<td>cert bytes</td>
<td>Optional privacy-mode service certificate.</td>
</tr>
<tr>
<td><code>get_widevine_license(title, track, challenge)</code></td>
<td>license bytes</td>
<td>POST the Widevine challenge to the license server, return the response.</td>
</tr>
<tr>
<td><code>get_playready_license(title, track, challenge)</code></td>
<td>license</td>
<td>Same for PlayReady; defaults to delegating to Widevine.</td>
</tr>
<tr>
<td><code>get_clearkey_license(title, track, challenge)</code></td>
<td>dict / str / bytes / <code>None</code></td>
<td>For <code>ClearKeyCENC</code>; return <code>None</code> to let the framework POST to the manifest <code>Laurl</code>.</td>
</tr>
<tr>
<td><code>get_fairplay_bridge_license(title, track, challenge, drm_system)</code></td>
<td>license</td>
<td>Optional, not on the base class. Licenses a FairPlay-only HLS track; see <a href="#the-fairplay-bridge-hook">The FairPlay bridge hook</a>.</td>
</tr>
</tbody>
</table>
calls that must carry the CDM's challenge. Override the licence callbacks that your platform
needs: <code>get_widevine_service_certificate</code>, <code>get_widevine_license</code>, <code>get_playready_license</code> and
<code>get_clearkey_license</code>. Each one gets <code>challenge</code>, <code>title</code> and <code>track</code> as keyword arguments, and
returns the licence as the server gives it, without decoding it. The base <code>get_playready_license</code> calls
<code>get_widevine_license</code>, and the base <code>get_clearkey_license</code> returns <code>None</code>, so that the framework
POSTs the challenge to the manifest <code>Laurl</code>. The <a href="../../reference/api/service/">Service API</a> gives the
signature and the return type of each callback.</p>
<p>A licence callback can also declare optional keyword arguments. <code>get_widevine_license</code> can ask for
<code>pssh</code> and <code>session_id</code>. <code>get_playready_license</code> can ask for <code>pssh_b64</code> and <code>session_id</code>.
<code>session_id</code> is the open CDM session. A callback gets only the arguments that its signature declares.
When a <code>--remote</code> client licenses with its own CDM, the callback on the server gets <code>pssh</code> or
<code>pssh_b64</code> for the header that the client licenses, but no <code>session_id</code>.</p>
<p>You do not open CDM sessions or operate shaka-packager yourself. The <code>Widevine</code>/<code>PlayReady</code>
classes drive the CDM handshake and call the decryption backend. Your hook is only the
"send this challenge, give me back the license" step.</p>
classes drive the CDM handshake and call the decryption backend. Your callback is only the
"send this challenge, give me back the licence" step.</p>
<h3 id="the-fairplay-bridge-hook">The FairPlay bridge hook<a class="headerlink" href="#the-fairplay-bridge-hook" title="Permanent link">&para;</a></h3>
<p>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
<code>get_fairplay_bridge_license</code>. The base class does not define it.</p>
<p>unshackle has no FairPlay CDM and never sends a FairPlay challenge. For a FairPlay-only HLS track it can
send a PlayReady or Widevine challenge for the KIDs of the init segments to the licence server of the
platform. This works only when that server issues the same content key to PlayReady or Widevine. The
bridge runs only for a service that defines <code>get_fairplay_bridge_license</code>. The base class does not
define it.</p>
<div class="language-python highlight"><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="k">def</span><span class="w"> </span><span class="nf">get_fairplay_bridge_license</span><span class="p">(</span>
</span><span id="__span-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a> <span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">challenge</span><span class="p">:</span> <span class="nb">bytes</span><span class="p">,</span> <span class="n">title</span><span class="p">:</span> <span class="n">Title_T</span><span class="p">,</span> <span class="n">track</span><span class="p">:</span> <span class="n">AnyTrack</span><span class="p">,</span> <span class="n">drm_system</span><span class="p">:</span> <span class="nb">str</span>
</span><span id="__span-4-3"><a id="__codelineno-4-3" name="__codelineno-4-3" href="#__codelineno-4-3"></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bytes</span> <span class="o">|</span> <span class="nb">str</span><span class="p">:</span>
@@ -3322,11 +3283,12 @@ classes drive the CDM handshake and call the decryption backend. Your hook is on
</span></code></pre></div>
<ul>
<li><code>drm_system</code> is <code>"playready"</code> or <code>"widevine"</code>. The hook must accept it.</li>
<li>The hook can also declare the arguments of the licence callback of that system: <code>pssh</code> for Widevine,
<code>pssh_b64</code> for PlayReady, and <code>session_id</code>. It gets only the arguments that it declares.</li>
<li>The hook can also declare the optional arguments of the licence callback of that system (see
<a href="#the-service-side-hooks">The service-side hooks</a>). It gets only the arguments that it declares.</li>
<li>The key IDs are on the DRM object of the track (<code>track.drm[0].kids</code>) when the hook runs. A service that
needs its own request shape builds the request in the hook.</li>
<li>The challenge of every other track goes to <code>get_playready_license</code> or <code>get_widevine_license</code>, as before.</li>
<li>The hook gets only the challenges of FairPlay-only tracks. The challenge of every other track goes to
<code>get_playready_license</code> or <code>get_widevine_license</code>.</li>
</ul>
<p>The DRM system of the challenge is the <code>drm_preference</code> of the track, else the system of the configured
CDM. For a licence server that issues the content key to one system only, set <code>drm_preference</code> on the
@@ -3335,23 +3297,13 @@ FairPlay-only tracks in <code>get_tracks()</code>:</p>
</span><span id="__span-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">track</span><span class="o">.</span><span class="n">drm</span><span class="p">:</span>
</span><span id="__span-5-3"><a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a> <span class="n">track</span><span class="o">.</span><span class="n">drm_preference</span> <span class="o">=</span> <span class="s2">"playready"</span>
</span></code></pre></div>
<p>Without the hook, no challenge goes to the licence server for a FairPlay-only track, and <code>dl</code> leaves
such a track out of the selection:</p>
<ul>
<li>After the selection and the deferred DRM load, <code>dl</code> checks each selected video and audio track that has
no DRM object. An HLS track costs one request for its media playlist. A DASH track is FairPlay-only when
its <code>ContentProtection</code> elements name only DRM systems that unshackle cannot license and its init segment
has no Widevine or PlayReady <code>pssh</code>.</li>
<li><code>dl</code> removes each FairPlay-only track and selects again, so the run takes the next best track that
licenses. It logs one line for each title: <code>Left out 2 FairPlay-only tracks: EXAMPLE has no FairPlay bridge hook</code>.</li>
<li>When a quality, range or codec flag matches only FairPlay-only tracks, the second selection skips the
title with its usual reason, and <code>--best-available</code> takes its usual fallback. When each selected video
or each selected audio track is FairPlay-only, <code>dl</code> skips the title.</li>
<li><code>--list</code> shows every track and checks none. An import is not checked, because its export holds the
content keys.</li>
<li>With the hook, <code>dl</code> still leaves out FairPlay-only DASH tracks, because the bridge works for HLS only.
The line then reads <code>Left out 1 FairPlay-only track: DASH has no FairPlay bridge</code>.</li>
</ul>
<p>The init segment (<code>EXT-X-MAP</code>) of the track must name a real key ID in its <code>tenc</code> box. When the <code>tenc</code>
key ID is all zeros and the playlist has one key URI, the <code>pssh</code> boxes of the init segment can name it.
unshackle never reads a key ID from the <code>skd://</code> URI.</p>
<p>Without the hook, <code>dl</code> leaves each FairPlay-only track out of the selection and takes the next best
track that licenses. It logs one line for each title:
<code>Left out 2 FairPlay-only tracks: EXAMPLE has no FairPlay bridge hook</code>. With the hook, <code>dl</code> still leaves
out FairPlay-only DASH tracks, because the bridge works for HLS only.</p>
<p>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 (<code>--cdm-only --skip-dl</code>) before a service relies on it.</p>
<h3 id="decrypting-a-cbcs-file-yourself">Decrypting a cbcs file yourself<a class="headerlink" href="#decrypting-a-cbcs-file-yourself" title="Permanent link">&para;</a></h3>
@@ -3372,41 +3324,8 @@ to <code>None</code>, and after it your <code>on_track_downloaded</code> runs an
runs on the server: the client sends the samples through the <code>samples</code> route, so a decrypter
that needs a process on the server also works for a remote client.</p>
<h3 id="a-playlist-whose-key-tag-unshackle-cannot-license">A playlist whose key tag unshackle cannot license<a class="headerlink" href="#a-playlist-whose-key-tag-unshackle-cannot-license" title="Permanent link">&para;</a></h3>
<p>A media playlist can name only a key system that unshackle does not read, such as an <code>skd://</code> key
over cbcs media, while the licence server of the platform also issues the same content key over
PlayReady or Widevine. <code>HLS.download_track</code> licenses such a track when all of these conditions are true:</p>
<ul>
<li>The service has the <a href="#the-fairplay-bridge-hook">FairPlay bridge hook</a>.</li>
<li>The track has no DRM object.</li>
<li>Every <code>EXT-X-KEY</code> of its media playlist is <code>SAMPLE-AES</code> or <code>SAMPLE-AES-CTR</code> for a DRM system
unshackle cannot license, or <code>METHOD=NONE</code>. A segment under <code>METHOD=NONE</code> 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 <code>KEYFORMAT="identity"</code>, or with no <code>KEYFORMAT</code>, names no DRM system: each
encrypted segment also needs a tag of a DRM system.</li>
<li>The <code>drm_preference</code> of the track, or else the configured CDM, is PlayReady or Widevine.</li>
<li>The init segment (<code>EXT-X-MAP</code>) of the track names a key ID in its <code>tenc</code> box. When the <code>tenc</code> 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 <code>tenc</code> key ID, or else the one key ID that its <code>pssh</code> 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.</li>
<li>The init segment does not change without an <code>EXT-X-DISCONTINUITY</code>.</li>
</ul>
<p>The download reads the key ID from the init segment, builds a DRM object for that DRM system with
<code>drm_stub</code>, and sends the challenge to the hook. Over <code>--remote</code> 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. With the server CDM, the batch licence names the key IDs that the server read, so an
answer without their content keys stops the track in the same way. A content key that does not decode
the downloaded track stops the track with an error, and unshackle keeps no output file.</p>
<p>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 <code>tenc</code> key ID, after an
<code>EXT-X-DISCONTINUITY</code>. When the first key ID is real, the download also reads the <code>tenc</code> key ID of
each other init segment of the encrypted segments, and licenses each real key ID in its own licence step. A
PlayReady DRM object then has one header for each key ID, because the header of <code>drm_stub</code> holds
one key ID. A key ID that gets no content key stops the track before it downloads a segment. An
init segment that gives no real key ID does not count.</p>
<p>A service that must choose the DRM system itself, or one that knows the key ID, puts the DRM object
on the track:</p>
on the track and needs no <a href="#the-fairplay-bridge-hook">FairPlay bridge hook</a>:</p>
<ol>
<li>Read the key ID from the init segment of the encrypted segments. <code>HLS.get_track_kid_from_init</code> returns it
for the track, a reader of init segments (<code>HLS.init_reader(playlist, session)</code>) and that init segment.</li>
@@ -3416,24 +3335,16 @@ on the track:</p>
<li>Let your licence callback send the challenge to the server that issues that key.</li>
</ol>
<p><code>drm_stub</code> builds the header from the key ID alone, so this works with a licence server that goes
by the key ID, not with one that checks a header a packager signed. A platform can issue the
content key of one package of a title and refuse another. When a track carries a Widevine or PlayReady DRM
object and every <code>EXT-X-KEY</code> of its playlist is <code>SAMPLE-AES</code> or <code>SAMPLE-AES-CTR</code> for a key system
unshackle cannot license, or <code>METHOD=NONE</code> under the same condition, <code>HLS.drop_unsupported_keys</code> removes the
tags from the parsed playlist.
The download then licenses and decrypts the track with the DRM object of the track. This works for
one content key per track: the key changes of the playlist go with the tags. This limit also
applies to a DRM object that the download builds. Any other track stops with
<code>None of the key systems are supported</code> before it downloads a segment.</p>
<p>A DASH track with no DRM object stops with the same error when its init segment has an encrypted
sample entry. A DASH track with no init segment stops after the download when the file has one, and
unshackle deletes the file. A service sample decrypter turns off both checks.</p>
by the key ID, not with one that checks a header a packager signed. When every <code>EXT-X-KEY</code> of the
playlist names a key system that unshackle cannot license, unshackle ignores those tags and licenses
and decrypts the track with its DRM object, for one content key per track. Any other track that has
only such tags stops with <code>None of the key systems are supported</code> before it downloads a segment.</p>
<h3 id="how-unshackle-chooses-a-cdm-and-finds-keys">How unshackle chooses a CDM and finds keys<a class="headerlink" href="#how-unshackle-chooses-a-cdm-and-finds-keys" title="Permanent link">&para;</a></h3>
<p>CDM selection is config-driven: the <code>cdm</code> map resolves a service tag (and optionally the
<p>The CDM choice comes from config: the <code>cdm</code> map resolves a service tag (and optionally the
track quality or DRM type) to a device name, which <code>load_cdm</code> instantiates as a local
<code>.wvd</code>/<code>.prd</code> or a remote CDM. Before ever requesting a license, the framework tries an
in-process cache of content keys and the configured <strong>key vaults</strong>. Only unresolved KIDs
trigger an actual license request, and the framework writes newly licensed keys back to
<code>.wvd</code>/<code>.prd</code> or a remote CDM. Before ever requesting a licence, the framework tries an
in-process cache of content keys and the configured <strong>key vaults</strong>. The CDM makes a challenge only
for an unresolved KID, and the framework writes newly licensed keys back to
every vault. This is why the same content key is rarely re-licensed twice. Users configure
all of this in <a href="../../guide/drm-and-cdm/">DRM and CDM</a> and
<a href="../../guide/vaults/">Key vaults</a>. The <a href="../../reference/api/drm/">DRM API reference</a> gives
@@ -3464,8 +3375,8 @@ prepared, all derived from the Click context (<code>ctx</code>) that <code>dl</c
<li><strong><code>self.session</code></strong>: a <code>requests.Session</code> with <code>config.headers</code> applied, a retry policy
(<code>total=5</code>, backoff, retry on 429/5xx), and any resolved proxy already mounted. Pass this
HTTP session into the manifest parsers and DRM calls so headers, cookies, and proxies flow
everywhere. (unshackle also ships an rnet-based TLS-fingerprinting HTTP session that the
newer <code>session()</code> factory uses and that the <code>network</code> config key configures.)</li>
everywhere. To impersonate a browser TLS fingerprint, override <code>get_session()</code> to return an
rnet HTTP session from <code>session()</code> in <code>unshackle.core.session</code>, which the <code>network</code> config key configures.</li>
<li><strong><code>self.credential</code></strong>: the active <code>Credential</code> (<code>username:password[:extra]</code>), populated
by <code>authenticate</code>. unshackle uses its <code>sha1</code> as the account hash for cache keys. A login
with cookies only uses a hash of the path of its cookie file.</li>
@@ -3477,46 +3388,8 @@ prepared, all derived from the Click context (<code>ctx</code>) that <code>dl</c
to stale data within <code>title_cache_max_retention</code> when an API call fails, and <code>--no-cache</code>
bypasses it. If you put the cookies of a different account into the same cookie file, use
<code>--reset-cache</code> once.</li>
<li><strong><code>self.track_request</code></strong>: the <code>TrackRequest</code> describing what the user asked for
(codecs, ranges, best-available), for use inside <code>get_tracks</code>.</li>
</ul>
<div class="admonition example">
<p class="admonition-title">A minimal service skeleton</p>
<div class="language-python highlight"><span class="filename">services/EXMP/__init__.py</span><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="kn">from</span><span class="w"> </span><span class="nn">unshackle.core.service</span><span class="w"> </span><span class="kn">import</span> <span class="n">Service</span>
</span><span id="__span-6-2"><a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a><span class="kn">from</span><span class="w"> </span><span class="nn">unshackle.core.manifests</span><span class="w"> </span><span class="kn">import</span> <span class="n">DASH</span>
</span><span id="__span-6-3"><a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a><span class="kn">from</span><span class="w"> </span><span class="nn">unshackle.core.titles</span><span class="w"> </span><span class="kn">import</span> <span class="n">Movie</span><span class="p">,</span> <span class="n">Movies</span>
</span><span id="__span-6-4"><a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a>
</span><span id="__span-6-5"><a id="__codelineno-6-5" name="__codelineno-6-5" href="#__codelineno-6-5"></a>
</span><span id="__span-6-6"><a id="__codelineno-6-6" name="__codelineno-6-6" href="#__codelineno-6-6"></a><span class="k">class</span><span class="w"> </span><span class="nc">EXMP</span><span class="p">(</span><span class="n">Service</span><span class="p">):</span>
</span><span id="__span-6-7"><a id="__codelineno-6-7" name="__codelineno-6-7" href="#__codelineno-6-7"></a> <span class="n">ALIASES</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"example"</span><span class="p">,)</span>
</span><span id="__span-6-8"><a id="__codelineno-6-8" name="__codelineno-6-8" href="#__codelineno-6-8"></a> <span class="n">GEOFENCE</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"us"</span><span class="p">,)</span>
</span><span id="__span-6-9"><a id="__codelineno-6-9" name="__codelineno-6-9" href="#__codelineno-6-9"></a>
</span><span id="__span-6-10"><a id="__codelineno-6-10" name="__codelineno-6-10" href="#__codelineno-6-10"></a> <span class="k">def</span><span class="w"> </span><span class="nf">get_titles</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Movies</span><span class="p">:</span>
</span><span id="__span-6-11"><a id="__codelineno-6-11" name="__codelineno-6-11" href="#__codelineno-6-11"></a> <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="sa">f</span><span class="s2">"https://api.example.com/title/</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">title</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>
</span><span id="__span-6-12"><a id="__codelineno-6-12" name="__codelineno-6-12" href="#__codelineno-6-12"></a> <span class="k">return</span> <span class="n">Movies</span><span class="p">([</span>
</span><span id="__span-6-13"><a id="__codelineno-6-13" name="__codelineno-6-13" href="#__codelineno-6-13"></a> <span class="n">Movie</span><span class="p">(</span>
</span><span id="__span-6-14"><a id="__codelineno-6-14" name="__codelineno-6-14" href="#__codelineno-6-14"></a> <span class="n">id_</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="s2">"id"</span><span class="p">],</span>
</span><span id="__span-6-15"><a id="__codelineno-6-15" name="__codelineno-6-15" href="#__codelineno-6-15"></a> <span class="n">service</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span>
</span><span id="__span-6-16"><a id="__codelineno-6-16" name="__codelineno-6-16" href="#__codelineno-6-16"></a> <span class="n">name</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="s2">"name"</span><span class="p">],</span>
</span><span id="__span-6-17"><a id="__codelineno-6-17" name="__codelineno-6-17" href="#__codelineno-6-17"></a> <span class="n">year</span><span class="o">=</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"year"</span><span class="p">),</span>
</span><span id="__span-6-18"><a id="__codelineno-6-18" name="__codelineno-6-18" href="#__codelineno-6-18"></a> <span class="n">language</span><span class="o">=</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"language"</span><span class="p">),</span>
</span><span id="__span-6-19"><a id="__codelineno-6-19" name="__codelineno-6-19" href="#__codelineno-6-19"></a> <span class="p">)</span>
</span><span id="__span-6-20"><a id="__codelineno-6-20" name="__codelineno-6-20" href="#__codelineno-6-20"></a> <span class="p">])</span>
</span><span id="__span-6-21"><a id="__codelineno-6-21" name="__codelineno-6-21" href="#__codelineno-6-21"></a>
</span><span id="__span-6-22"><a id="__codelineno-6-22" name="__codelineno-6-22" href="#__codelineno-6-22"></a> <span class="k">def</span><span class="w"> </span><span class="nf">get_tracks</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="s2">"Tracks"</span><span class="p">:</span>
</span><span id="__span-6-23"><a id="__codelineno-6-23" name="__codelineno-6-23" href="#__codelineno-6-23"></a> <span class="n">mpd_url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="o">...</span><span class="p">)</span><span class="o">.</span><span class="n">json</span><span class="p">()[</span><span class="s2">"manifest"</span><span class="p">]</span>
</span><span id="__span-6-24"><a id="__codelineno-6-24" name="__codelineno-6-24" href="#__codelineno-6-24"></a> <span class="n">mpd</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">mpd_url</span><span class="p">)</span><span class="o">.</span><span class="n">text</span>
</span><span id="__span-6-25"><a id="__codelineno-6-25" name="__codelineno-6-25" href="#__codelineno-6-25"></a> <span class="k">return</span> <span class="n">DASH</span><span class="o">.</span><span class="n">from_text</span><span class="p">(</span><span class="n">mpd</span><span class="p">,</span> <span class="n">mpd_url</span><span class="p">)</span><span class="o">.</span><span class="n">to_tracks</span><span class="p">(</span><span class="n">language</span><span class="o">=</span><span class="n">title</span><span class="o">.</span><span class="n">language</span><span class="p">)</span>
</span><span id="__span-6-26"><a id="__codelineno-6-26" name="__codelineno-6-26" href="#__codelineno-6-26"></a>
</span><span id="__span-6-27"><a id="__codelineno-6-27" name="__codelineno-6-27" href="#__codelineno-6-27"></a> <span class="k">def</span><span class="w"> </span><span class="nf">get_chapters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">):</span>
</span><span id="__span-6-28"><a id="__codelineno-6-28" name="__codelineno-6-28" href="#__codelineno-6-28"></a> <span class="k">return</span> <span class="p">[]</span>
</span><span id="__span-6-29"><a id="__codelineno-6-29" name="__codelineno-6-29" href="#__codelineno-6-29"></a>
</span><span id="__span-6-30"><a id="__codelineno-6-30" name="__codelineno-6-30" href="#__codelineno-6-30"></a> <span class="k">def</span><span class="w"> </span><span class="nf">get_widevine_license</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">challenge</span><span class="p">,</span> <span class="n">title</span><span class="p">,</span> <span class="n">track</span><span class="p">):</span>
</span><span id="__span-6-31"><a id="__codelineno-6-31" name="__codelineno-6-31" href="#__codelineno-6-31"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">"https://lic.example.com/wv"</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">challenge</span><span class="p">)</span><span class="o">.</span><span class="n">content</span>
</span></code></pre></div>
<p>The directory name (<code>EXMP</code>) must match the class name exactly. That stem is the
service tag. Put your service in one of the <code>directories.services</code> paths.</p>
</div>
<p><a href="../creating-a-service/#minimal-service-skeleton">Creating a Service</a> gives a complete minimal service.</p>
<h2 id="where-to-go-next">Where to go next<a class="headerlink" href="#where-to-go-next" title="Permanent link">&para;</a></h2>
<ul>
<li><strong><a href="../creating-a-service/">Creating a Service</a></strong>: a guided walkthrough that builds on this model.</li>
@@ -3579,13 +3452,13 @@ service tag. Put your service in one of the <code>directories.services</code> pa
<a href="../rest-api/" class="md-footer__link md-footer__link--next" aria-label="Next: Overview">
<a href="../rest-api/quickstart/" class="md-footer__link md-footer__link--next" aria-label="Next: REST API Quick Start">
<div class="md-footer__title">
<span class="md-footer__direction">
Next
</span>
<div class="md-ellipsis">
Overview
REST API Quick Start
</div>
</div>
<div class="md-footer__button md-icon">