mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-05 07:25:08 +00:00
docs(rest-api): give the remote session protocol one page and move dl --remote setup to a user guide
This commit is contained in:
+63
-364
@@ -1,6 +1,6 @@
|
||||
# REST API Endpoints
|
||||
|
||||
This is the full endpoint reference for the unshackle REST API. It covers every route: its method and path, the request body it accepts, the response shape it returns, and the status codes it can give. This page groups the routes into general, download jobs, server management, and remote-dl sessions.
|
||||
This is the full endpoint reference for the unshackle REST API. It covers every route: its method and path, the request body it accepts, the response shape it returns, and the status codes it can give. This page groups the routes into general, download jobs, server management, remote sessions, and the remote services relay.
|
||||
|
||||
Start the server with [`unshackle serve`](../../guide/cli-reference.md). By default it binds to `127.0.0.1:8786`, and every route lives under the `/api/` prefix. The [Authentication](authentication.md) page gives authentication, server modes, and the `X-Secret-Key` header in detail. Read that first if you have not already. For an end-to-end walkthrough, see the [Quickstart](quickstart.md).
|
||||
|
||||
@@ -15,9 +15,9 @@ Start the server with [`unshackle serve`](../../guide/cli-reference.md). By defa
|
||||
- **Authentication.** Every request, `GET /api/health` included, requires the `X-Secret-Key` header when you configure an API key. `--no-key` disables the check entirely. See [Authentication](authentication.md).
|
||||
- **Content type.** Request bodies are JSON (`Content-Type: application/json`). All success responses are JSON unless this page documents a `204 No Content`.
|
||||
- **CORS.** Every response carries permissive CORS headers, and the server answers `OPTIONS` preflight requests automatically.
|
||||
- **Compression.** JSON responses of 256 bytes or more are gzip-compressed when the client sends `Accept-Encoding: gzip`. A [slow response](#slow-responses) is not compressed.
|
||||
- **Compression.** JSON responses of 256 bytes or more are gzip-compressed when the client sends `Accept-Encoding: gzip`. A [slow response](remote-sessions.md#slow-responses) is not compressed.
|
||||
- **Service allowlist.** The effective allowlist for your API key filters the service-facing endpoints (the intersection of the global `serve.services` list and your per-key list). The server treats services you cannot use as unknown.
|
||||
- **Remote services.** A full-mode server can run a service through one of its own `remote_services` servers (see [Remote sessions](remote-sessions.md)). `GET /api/config` lists their names in `remote_services`, and `GET /api/services?remote=<name>` lists that server's services, each with `remote` set to the name. Add `"remote": "<name>"` to `POST /api/search`, `/api/list-titles`, `/api/list-tracks` or `/api/download`, and the server opens a remote session with its own key for that server: the remote logs in and resolves titles, tracks and licences, and a download still runs, decrypts and muxes here. The tag may be any case or an alias, and your allowlist applies to it. An unknown name is `400 INVALID_PARAMETERS`, a server that does not answer is `SERVICE_UNAVAILABLE`, a server that rejects this server's API key is `AUTH_FAILED` (424), and a tag it does not offer is `INVALID_SERVICE`. List calls from the same API key for the same title, profile, proxy, client region and service options share one remote session, which closes after 120 seconds unused. When the server stops, a list call that waits on the login of a new remote session, or starts one, gets `SERVER_DRAINING` (409). A call that opens a lost remote session again can be cut too: `list-titles` then gets `SERVER_DRAINING`, and `list-tracks` that or `SERVICE_ERROR` (422). An optional `client_name` names your client on the remote server's dashboard as `serve (<client_name>)`. A relayed search opens no remote session. The server sends its own credentials, cookies and cache for the `profile` with the search. A service that searches with no login gets none of them. A `--remote-only` server does not relay. A remote login that waits on you (a pair code or URL to approve on another device) cannot answer through a list call, so poll `GET /api/remote/logins` alongside it: each entry carries the login's `notice`, its `qr` (the text of a QR code to scan, or null), and its `prompt` when it asks a question (an OTP), which you answer with `POST /api/remote/logins/{id}/input` and `{"response": "..."}`. A remote download job shows the same text as its own `notice`, and asks a question (an OTP) through `input_prompt` as a local job does.
|
||||
- **Remote services.** A full-mode server can run a service through one of its own `remote_services` servers. See [Remote services relay](#remote-services-relay).
|
||||
|
||||
!!! warning "Error responses have two shapes"
|
||||
Structured application errors (raised inside a handler) return `{"status": "error", "error_code": "...", "message": "...", "timestamp": "..."}`. The authentication middleware, however, returns a **different** shape: `{"status": 401, "message": "..."}` with an integer `status` and no `error_code`. The same middleware answers `429` in that shape when an API key goes over its rate limit. Clients must accept both shapes. The [Error responses](#error-responses) section at the bottom of this page gives the full error model.
|
||||
@@ -155,7 +155,7 @@ For a service with `anonymous_search`, the server does not log in and ignores `c
|
||||
| `proxy` | string | no | `null` | Full proxy URI on a public host, a Control D resolver as `controld://<resolver>@dns.controld.com`, or a country code when the API key has `server_proxy`. |
|
||||
| `no_proxy` | boolean | no | `false` | Force-disable all proxy use. |
|
||||
| `credentials`, `cookies`, `cache` | - | no | `null` | Your own login material, on a `--remote-only` server only. See [Client cache on a remote-only server](#client-cache-on-a-remote-only-server). |
|
||||
| `dl_params` | object | no | `null` | The `dl` track selection, as on [`POST /api/session/create`](#post-apisessioncreate). |
|
||||
| `dl_params` | object | no | `null` | The `dl` track selection, as on [`POST /api/session/create`](remote-sessions.md#post-apisessioncreate). |
|
||||
|
||||
=== "Request"
|
||||
|
||||
@@ -230,7 +230,7 @@ them in that mode.
|
||||
|
||||
`credentials` (`{username, password, extra?}`) and `cookies` (base64 of a
|
||||
zlib-compressed Netscape cookie file) are the same as on
|
||||
[`POST /api/session/create`](#post-apisessioncreate). `cache` is a map of cache
|
||||
[`POST /api/session/create`](remote-sessions.md#post-apisessioncreate). `cache` is a map of cache
|
||||
files in the same form: each cache key is the file path relative to the service cache
|
||||
directory, with `/` separators and no `.json` suffix, and each value is base64
|
||||
of the zlib-compressed file. The server writes these files into the request
|
||||
@@ -327,7 +327,7 @@ Show the video, audio, and subtitle tracks for a title. For series, you can scop
|
||||
| `part` | int/string | no | Part index of a split episode (combined with `season` and `episode`). |
|
||||
| `profile`, `proxy`, `no_proxy`, `cdm_type` | - | no | As on `list-titles`. |
|
||||
| `credentials`, `cookies`, `cache` | - | no | As on `list-titles`. |
|
||||
| `dl_params` | object | no | The `dl` track selection that the service reads from `ctx.parent.params`: `lang`, `v_lang`, `a_lang`, `s_lang`, `acodec`, `forced_subs` and `exact_lang`, as on [`POST /api/session/create`](#post-apisessioncreate). Some services select the manifests they fetch from these values. |
|
||||
| `dl_params` | object | no | The `dl` track selection that the service reads from `ctx.parent.params`: `lang`, `v_lang`, `a_lang`, `s_lang`, `acodec`, `forced_subs` and `exact_lang`, as on [`POST /api/session/create`](remote-sessions.md#post-apisessioncreate). Some services select the manifests they fetch from these values. |
|
||||
|
||||
When you give both `season` and `episode`, the server combines them into a `"{season}x{episode}"` selector. `part` narrows that to `"{season}x{episode}.{part}"`, one part of a [split episode](../creating-a-service.md#split-episodes). Without `part` you get every part of the episode. The server reads `part` only when you give both `season` and `episode`, and `wanted` takes precedence over all three. To scope a part by range, put it in `wanted` instead (`"S01E01.2"`).
|
||||
|
||||
@@ -437,7 +437,7 @@ Make a download job. It requires `service` and `title_id`. Every other field is
|
||||
}
|
||||
```
|
||||
|
||||
**Request body.** Every field except `service` and `title_id` is optional. The `dl` fields mirror the flags of the [`dl` command](../../guide/downloading.md). This table comes from the OpenAPI description that `/api/docs/` of a running server also shows.
|
||||
**Request body.** Every field except `service` and `title_id` is optional. The `dl` fields mirror the flags of the [`dl` command](../../guide/cli-reference.md#dl). This table comes from the OpenAPI description that `/api/docs/` of a running server also shows.
|
||||
|
||||
<!-- download-fields -->
|
||||
|
||||
@@ -899,127 +899,74 @@ Report the install status of the external binaries unshackle depends on (the sam
|
||||
|
||||
---
|
||||
|
||||
## Remote-dl sessions
|
||||
## Remote sessions
|
||||
|
||||
!!! note "Developer feature"
|
||||
The `/api/session/*` endpoints power unshackle's **remote download** mode. A thin local client authenticates once against a remote server, then fetches titles, tracks, and segments, and proxies DRM licensing back through it. The server mounts these endpoints in `--remote-only` mode, and they are what the built-in `RemoteService` client drives. Most end users never call them directly.
|
||||
The `/api/session/*` and `/api/tunnel` routes carry the remote sessions of `dl --remote`. The
|
||||
[remote session protocol](remote-sessions.md) page is their reference: each route, its request and
|
||||
response, the login states, the licensing modes and the error codes.
|
||||
|
||||
The server holds remote sessions in memory. They expire after `serve.session_ttl` (default 300s) without a request, except while the login runs, which can stay idle for the larger of `session_ttl` and 600s. A remote session whose client is gone ends sooner: see [Client presence](remote-sessions.md#client-presence). A remote session binds to the IP that made it, so the server rejects a request from a different IP with `403 FORBIDDEN`.
|
||||
## Remote services relay
|
||||
|
||||
### Remote session lifecycle overview
|
||||
A full-mode server can run a service through one of its own `remote_services` servers.
|
||||
`GET /api/config` lists their names in `remote_services`, and `GET /api/services?remote=<name>`
|
||||
lists the services of that server, each with `remote` set to the name. Add `"remote": "<name>"` to
|
||||
`POST /api/search`, `/api/list-titles`, `/api/list-tracks` or `/api/download`, and the server opens
|
||||
a remote session with its own API key for that server: the remote server logs in and resolves titles,
|
||||
tracks and licences, and a download still runs, decrypts and muxes here. The tag may be any case or
|
||||
an alias, and your allowlist applies to it. A `--remote-only` server does not relay.
|
||||
|
||||
```text
|
||||
POST /api/session/create → returns session_id, status "authenticating"
|
||||
GET /api/session/{id}/channel → WebSocket: prompts, CDM calls, logs, login state, drain
|
||||
GET /api/session/{id}/prompt → without the channel: poll until authenticated (submit answers via POST)
|
||||
GET /api/session/{id}/titles → list titles
|
||||
POST /api/session/{id}/tracks → tracks + chapters (with URLs) for one title; a track that resolves its URL on use has resolve_url true and no URL
|
||||
POST /api/session/{id}/segments → resolve segment URLs / DRM / headers per track
|
||||
POST /api/session/{id}/segment_filter → HLS segments the service drops (ads, bumpers)
|
||||
POST /api/session/{id}/samples → decrypt cbcs samples of a track on the server
|
||||
POST /api/session/{id}/license → proxy or server-CDM DRM licensing
|
||||
POST /api/session/{id}/keys → store the content keys the client proved on a track
|
||||
POST /api/session/{id}/keys/bad → report a server-vault content key that did not decrypt
|
||||
DELETE /api/session/{id} → tear down, harvest updated cache
|
||||
```
|
||||
- An unknown name is `400 INVALID_PARAMETERS`, a server that does not answer is
|
||||
`SERVICE_UNAVAILABLE`, a server that rejects the API key of this server is `AUTH_FAILED` (424),
|
||||
and a tag that it does not offer is `INVALID_SERVICE`.
|
||||
- List calls from the same API key for the same title, profile, proxy, client region and service
|
||||
options share one remote session, which closes after 120 seconds unused.
|
||||
- When the server stops, a list call that waits on the login of a new remote session, or starts one,
|
||||
gets `SERVER_DRAINING` (409). A call that opens a lost remote session again can be cut too:
|
||||
`list-titles` then gets `SERVER_DRAINING`, and `list-tracks` that or `SERVICE_ERROR` (422).
|
||||
- An optional `client_name` names your client on the dashboard of the remote server as
|
||||
`serve (<client_name>)`.
|
||||
- A relayed search opens no remote session. The server sends its own credentials, cookies and cache
|
||||
for the `profile` with the search. A service that searches with no login gets none of them.
|
||||
|
||||
### Slow responses
|
||||
A remote login that waits on you (a pair code or URL to approve on another device, or a question
|
||||
such as an OTP) cannot answer through a list call. Poll `GET /api/remote/logins` beside it. A remote
|
||||
download job shows the same text as its own `notice`, and asks a question through `input_prompt` as
|
||||
a local job does.
|
||||
|
||||
The `titles`, `tracks`, `segments` and `license` routes can take minutes on a large catalogue. When the
|
||||
answer is not ready after 30 seconds, the route sends status `200` and the headers. It then
|
||||
sends a newline every 30 seconds until the JSON body is ready. JSON parsers ignore the leading
|
||||
newlines. This keeps the connection open through a reverse proxy that closes an idle request.
|
||||
### `GET /api/remote/logins`
|
||||
|
||||
!!! warning "A late failure has status `200`"
|
||||
The server sent the status before the work ended. A failure after the first 30 seconds
|
||||
arrives as the [standard error body](errors.md#the-standard-error-shape) with status `200`.
|
||||
Check `status` in the body, not only the HTTP status. The body has no HTTP status field.
|
||||
Use `error_code` and `retryable` to decide what to do.
|
||||
|
||||
A slow response is not gzip-compressed. Gzip output cannot start before the body is ready, and
|
||||
the newlines must go out at once.
|
||||
|
||||
### `POST /api/session/create`
|
||||
|
||||
Make a remote session for a service and title. Authentication runs asynchronously in the background. This call returns immediately with `status: "authenticating"`, and you then poll the prompt endpoint. The body accepts `service` and `title_id` (both required). It also accepts a broad set of optional keys, because the body allows `additionalProperties`. These are `session_id`, `credentials` (`{username, password, extra?}`), `cookies` (base64 of zlib-compressed Netscape cookie file), `proxy`, `no_proxy`, `profile`, `cache` (map of forwarded cache files, keyed by the file path relative to the service cache directory with `/` separators and no `.json` suffix, so a nested key such as `session_web/<sha1>` lands in a subdirectory), `client_region`, `proxy_region`, `cdm_type`, `range_`, `vcodec`, `quality`, `best_available`, `dl_params`, `plugins`, `client`, and any service CLI options. `plugins` maps the id of each DRM plugin that the client loads to `{version, device?}`; `device` holds the plain values of the device attributes that the plugin names in `device_facts`. The server refuses a title with a track of a plugin that is not in `plugins` (or a body with no `plugins`) on `POST /api/session/{id}/tracks` with `DRM_ERROR`, and gives `device` to the service only in a remote session that the client's device licenses. A `plugins` value over 16384 bytes of JSON, or of another shape, gets `INVALID_INPUT`. `proxy_region` is the country code the client resolved `proxy` from; the server matches it against its own accounts. `client` is a freeform object the dashboard shows as sent (the CLI puts `version`, `code_hash`, `platform` and a redacted `argv` in it); the server ignores it above 4096 bytes of JSON.
|
||||
|
||||
`session_id` is the ID that you give the remote session, so that you can delete it before this call answers. It must be the canonical text of a version 4 UUID. Without it, the server makes the ID. A remote session with your ID ends when you send no request for it and open no channel within 150s of the create. A second create with the same ID from the same API key and IP ends the first one if the first one has not answered, and replaces its remote session when the new one is stored. A second create that fails leaves that remote session open.
|
||||
|
||||
`dl_params` is an object with the `dl` track selection: `lang`, `v_lang`, `a_lang` and `s_lang` (arrays of language strings), `acodec` (an array of audio codec names or `dl -a` aliases such as `ddp`), and `forced_subs` and `exact_lang` (booleans). The service reads these values from `ctx.parent.params`. The server uses the `dl` default for each absent value. It refuses a malformed value, an unknown codec, range or vcodec name, and a height of 0 or less with `INVALID_PARAMETERS`. The flat `range_`, `vcodec`, `quality`, `best_available` and `generate_dv` keys are `dl` values on this route. On the list and search routes they are `dl` values only when the body has `service_params`.
|
||||
|
||||
Service CLI options also travel in a nested `service_params` object. When the body has `service_params`, the server reads service options only from it, and a flat key with the same name stays a `dl` value. `profile` at the top level always means the credentials profile, never a service's own `--profile` option.
|
||||
|
||||
The `proxy` value must be a full proxy URI, unless the operator gives your API key `server_proxy` in the `serve.users` config. Without `server_proxy`, a proxy URI gets `INVALID_PROXY` when its host is not a public address, does not resolve, or is not a plain host name or IP address. Without `server_proxy`, the server does not resolve country codes with its own proxy providers. It rejects the request with `INVALID_PROXY` when no `proxy` is set and the reported `client_region` differs from the server's region. A request that reports no `client_region` is not blocked. Pass `proxy` with your own proxy, or `no_proxy` to accept the server's own connection. With `server_proxy`, the server resolves a country code and picks a proxy for your `client_region` itself. A Control D resolver, `controld://<resolver>@dns.controld.com`, counts as a full proxy URI: the server runs a forwarder for it and needs no Control D configuration of its own. A proxy URI needs an `http`, `https` or `socks` scheme: the server answers `INVALID_PROXY` to a `host:port` value, also with `server_proxy`.
|
||||
The logins of your list calls that wait on a remote server. An admin key sees the logins of every API
|
||||
key.
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{
|
||||
"session_id": "d4e5f6a7-...",
|
||||
"service": "EXAMPLE",
|
||||
"status": "authenticating",
|
||||
"server_account": false
|
||||
"logins": [
|
||||
{
|
||||
"id": "3f2a9c...",
|
||||
"remote": "my_server",
|
||||
"service": "EXAMPLE",
|
||||
"title_id": "0ABCDEF",
|
||||
"prompt": null,
|
||||
"notice": "Open https://example.com/activate and enter ABCD-1234",
|
||||
"qr": "https://example.com/activate?code=ABCD-1234"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
`server_account` is `true` when the server authenticated with one of its own accounts (`serve.server_accounts`). Otherwise the server uses only what the client sent, and never falls back to its own credentials. When the login succeeds and the remote session does not use a server account, the login belongs to the client, and the client gets cookies, auth headers, and the remote session cache back. A remote session on the server's device is the exception: the client gets its cookies back, but no auth headers and no cache. For a server-account remote session the tracks and segments responses carry no cookies and no auth headers. The server also drops secret-looking keys from track data, and the cache stays on the server. A server-account service also refuses a client proxy URI, because the server's login would pass through it.
|
||||
| Field | Description |
|
||||
| --- | --- |
|
||||
| `id` | The ID to answer the prompt with. |
|
||||
| `remote`, `service`, `title_id` | The remote server, the service and the title of the list call. |
|
||||
| `prompt` | What the login asks you (an OTP, a PIN), or `null`. |
|
||||
| `notice` | What the login shows you while it waits, such as a URL and a pair code, or `null`. |
|
||||
| `qr` | The text of a QR code to scan with the prompt or notice, or `null`. |
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | Session created; authentication in progress. |
|
||||
| `400` | `INVALID_INPUT` | Missing `service` or `title_id`, or a `session_id` that is not the canonical text of a version 4 UUID. |
|
||||
| `400` | `INVALID_PARAMETERS` | Invalid `range_`, `vcodec`, `quality` or `dl_params` value. |
|
||||
| `403` | `FORBIDDEN` | Another API key or another IP has the `session_id`. |
|
||||
| `404` | `SESSION_NOT_FOUND` | A `DELETE` or a newer create with the same `session_id` ended this create. |
|
||||
| `400` | `INVALID_SERVICE` | Unknown or disallowed service. |
|
||||
### `POST /api/remote/logins/{login_id}/input`
|
||||
|
||||
### `GET /api/session/{session_id}/channel`
|
||||
|
||||
Open the remote session channel: a WebSocket that carries the prompts, CDM calls, log records, login state and drain state of the remote session, and the client's answers. Pass `since=<seq>` to get only the log records newer than that sequence number. The server closes the WebSocket with code `4404` when the remote session ends. See [The remote session channel](remote-sessions.md#the-remote-session-channel) for the messages.
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `101` | - | WebSocket open. |
|
||||
| `403` | `FORBIDDEN` | Request IP differs from the remote session creator. |
|
||||
| `404` | `SESSION_NOT_FOUND` | No such session. |
|
||||
|
||||
### `GET /api/session/{session_id}/prompt`
|
||||
|
||||
The polling fallback of the remote session channel. Poll for the authentication status and any pending interactive prompt (OTP, PIN, device code). Response variants:
|
||||
|
||||
=== "Authenticating"
|
||||
|
||||
```json
|
||||
{ "status": "authenticating" }
|
||||
```
|
||||
|
||||
=== "Pending input"
|
||||
|
||||
```json
|
||||
{ "status": "pending_input", "prompt": "Enter the code sent to your email:" }
|
||||
```
|
||||
|
||||
=== "Authenticated"
|
||||
|
||||
```json
|
||||
{ "status": "authenticated" }
|
||||
```
|
||||
|
||||
=== "Failed"
|
||||
|
||||
```json
|
||||
{ "status": "failed", "error": "Invalid credentials" }
|
||||
```
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | Status returned. |
|
||||
| `403` | `FORBIDDEN` | Request IP differs from the remote session creator. |
|
||||
| `404` | `SESSION_NOT_FOUND` | No such session. |
|
||||
|
||||
### `POST /api/session/{session_id}/prompt`
|
||||
|
||||
Submit a response to a pending prompt. Body: `{ "response": "..." }` (required).
|
||||
Answer the prompt of a remote login. Body: `{ "response": "..." }` (required).
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
@@ -1029,258 +976,10 @@ Submit a response to a pending prompt. Body: `{ "response": "..." }` (required).
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | Response accepted. |
|
||||
| `400` | `INVALID_INPUT` | Missing `response`, or no prompt is pending. |
|
||||
| `404` | `SESSION_NOT_FOUND` | No such session. |
|
||||
|
||||
### `GET /api/session/{session_id}/logs`
|
||||
|
||||
The polling fallback of the remote session channel. Drain the service's server-side log output for this remote session. The server mirrors every log call the service makes (`self.log.info`, warnings, errors) into a bounded per-session buffer, so a remote client can see why an auth, title, or license step failed. Pass `since=<seq>` to get only records newer than the last drained sequence number. Works in every auth state, including `failed`.
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{
|
||||
"session_id": "a1b2c3",
|
||||
"logs": [
|
||||
{ "seq": 1, "level": "INFO", "message": "Signed in as profile 'Main'", "ts": 1724990000.1 },
|
||||
{ "seq": 2, "level": "WARNING", "message": " - ThePlatform returned no streams", "ts": 1724990002.7 }
|
||||
],
|
||||
"last_seq": 2
|
||||
}
|
||||
```
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | Records returned (empty list when nothing new). |
|
||||
| `404` | `SESSION_NOT_FOUND` | No such session. |
|
||||
|
||||
The buffer keeps the newest 500 records. Only the service instance's own logger is mirrored; core pipeline loggers stay on the server. A server-account session gets no log relay at all - auth-time service output can carry the operator account's identity, so it stays server-side.
|
||||
|
||||
### `GET /api/session/{session_id}/titles`
|
||||
|
||||
Fetch the titles for an authenticated remote session.
|
||||
A slow answer arrives as a [slow response](#slow-responses).
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{
|
||||
"session_id": "d4e5f6a7-...",
|
||||
"titles": [ { "type": "episode", "name": "Pilot", "id": "ep-1" } ]
|
||||
}
|
||||
```
|
||||
|
||||
`collection` is present only when the service returned a music collection. It holds the facts of the collection itself: `kind`, `title`, `artist`, `year`, `total_tracks`, `total_discs`, `artwork_url`, `total_duration`, `owner` and `description`, for example `"collection": { "kind": "playlist", "title": "Example Playlist", "total_tracks": 93 }`. A fact that the collection does not have is absent.
|
||||
|
||||
Requires an authenticated remote session. Otherwise it returns `404 SESSION_NOT_FOUND`.
|
||||
|
||||
### `POST /api/session/{session_id}/tracks`
|
||||
|
||||
Get tracks and chapters for a specific title within the remote session. Body: `{ "title_id": "..." }` (required). Unlike `list-tracks`, track objects here **include** download URLs, along with session headers/cookies and manifest data the client needs to download directly. A slow answer arrives as a [slow response](#slow-responses).
|
||||
|
||||
`manifests` holds each served DASH/ISM manifest once. One URL can have more than one entry, such as when a service merges a second manifest under the same URL. `track_ids` names the tracks that each entry restores, and the client matches such a track only in that entry's manifest. For DASH, `filtered_period_ids` names the periods that the download skips, such as ad periods. A service can build an AdaptationSet of its own that the served manifest does not contain. `track_manifests` holds a one-track MPD for each such track, and the client re-parses that in place of the whole manifest. That MPD starts at the period of the track and keeps the content periods after it.
|
||||
|
||||
`hls_playlists` holds the media playlist text of each HLS track that the service holds as text, with the track URL. A `file:` URL is never sent: such an entry has `url` set to `null`. The client keeps an entry only when it parses as a media playlist whose segment URIs are absolute `http` or `https` URLs, and is for the same URL as its track. Otherwise it logs `Refusing track <id>: its HLS playlist ...` and drops the track.
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{
|
||||
"title": { "type": "episode", "name": "Pilot", "id": "ep-1" },
|
||||
"video": [ { "id": "v-1", "url": "https://...", "drm": [ ... ] } ],
|
||||
"audio": [ { "id": "a-1", "url": "https://..." } ],
|
||||
"subtitles": [ { "id": "s-1", "url": "https://..." } ],
|
||||
"chapters": [ { "timestamp": "00:00:00.000", "name": "Intro" } ],
|
||||
"attachments": [ { "url": "https://...", "name": "font.ttf", "mime_type": "font/ttf", "description": "" } ],
|
||||
"manifests": [ { "type": "dash", "url": "https://...", "data": "<base64 zlib xml>", "track_ids": [ "v-1", "a-1" ], "filtered_period_ids": [ "ad-1" ] } ],
|
||||
"track_manifests": [ { "track_id": "s-1", "type": "dash", "url": "https://...", "data": "<base64 zlib xml>" } ],
|
||||
"hls_playlists": [ { "track_id": "v-1", "url": "https://...", "data": "<base64 zlib m3u8>" } ],
|
||||
"session_headers": { "User-Agent": "..." },
|
||||
"session_cookies": { "sid": "..." },
|
||||
"session_cookie_jar": [ { "name": "sid", "value": "...", "domain": ".example.com", "path": "/", "secure": true } ],
|
||||
"server_cdm_type": "widevine"
|
||||
}
|
||||
```
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | Tracks returned. |
|
||||
| `400` | `INVALID_INPUT` | Missing or unknown `title_id`. |
|
||||
| `404` | `SESSION_NOT_FOUND` | No such session. |
|
||||
|
||||
### `POST /api/session/{session_id}/segments`
|
||||
|
||||
Get the download URL, DRM info, headers, cookies, and track data for the selected tracks. Body: `{ "track_ids": ["v-1", "a-1"] }` (required). A track that the tracks response sent with `resolve_url` gets its URL from the service here. The server makes one service call at a time per remote session, so parallel requests wait for each other. A slow answer arrives as described in [Slow responses](#slow-responses).
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{
|
||||
"tracks": {
|
||||
"v-1": { "descriptor": "DASH", "url": "https://...", "drm": [ ... ], "headers": { ... }, "cookies": { ... }, "cookie_jar": [ ... ], "data": { ... } }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`data` has the form of the track `data` in `list-tracks`: the JSON-safe part of the service-set `track.data`, without the `hls`, `dash`, and `ism` parser keys. `cookies` gives names and values only. `cookie_jar` gives the same cookies with their domain, path and `secure` flag, in the `session_cookie_jar` form of the tracks response.
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | Segment info returned. |
|
||||
| `400` | `INVALID_INPUT` | Missing `track_ids`. |
|
||||
| `404` | `TRACK_NOT_FOUND` | An unknown track ID was requested. |
|
||||
|
||||
### `POST /api/session/{session_id}/segment_filter`
|
||||
|
||||
Get the HLS segments a service drops (ads, bumpers, dub cards). The server runs the service's own segment filter over the track's media playlist and returns only the URIs, so the client drops the same segments the service does. Body: `{ "track_id": "v-1" }` (required). `unwanted` is `null` when the track has no filter. The client keeps every segment when the server does not have this route. When the server answers with an error, the client stops the track download.
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{ "unwanted": ["https://cdn.example/hls/ad1.ts"] }
|
||||
```
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | Unwanted segment URIs, or `null`. |
|
||||
| `400` | `INVALID_INPUT` | Missing `track_id`. |
|
||||
| `404` | `TRACK_NOT_FOUND` | An unknown track ID was requested. |
|
||||
| `422` | `SERVICE_ERROR` | The playlist request or the filter failed. |
|
||||
|
||||
### `POST /api/session/{session_id}/samples`
|
||||
|
||||
Decrypt the samples of a track that the service decrypts itself after the download. The tracks response lists those track IDs in `sample_decrypt_tracks`. The client downloads the file, then sends each `stsd` sample entry's samples here, and writes the plaintexts back in place. The query string names the track and the 1-based entry: `?track_id=a-1&entry=2`.
|
||||
|
||||
- An empty body asks how the entry decrypts. The JSON response is `{ "key": "<hex>" }`, which the client then uses itself, or `{ "decrypter": true }`.
|
||||
- An `application/octet-stream` body is a sample frame: a big-endian `uint32` count, one `uint32` length per sample, then the samples. Each sample is a ciphertext cut to whole AES blocks. The response is a frame of the same shape with the plaintexts in the same order.
|
||||
|
||||
The client sends at most 8 MiB of samples per request, and the route accepts a body of up to 16 MiB. Binary frames keep the upload the size of the samples, and the server does not compress them. The route needs the `server_cdm` grant for the service, because the decrypter can use a process or an account of the server.
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | The content key, `decrypter`, or the plaintext frame. |
|
||||
| `400` | `INVALID_INPUT` | Missing `track_id`, a bad `entry`, a malformed frame, or a track the service does not decrypt. |
|
||||
| `413` | - | The body is larger than 16 MiB. |
|
||||
| `403` | `FORBIDDEN` | The API key has no `server_cdm` grant for the service. |
|
||||
| `404` | `TRACK_NOT_FOUND` | An unknown track ID was requested. |
|
||||
| `422` | `SERVICE_ERROR` | The service's decrypter failed. |
|
||||
|
||||
### `POST /api/session/{session_id}/license`
|
||||
|
||||
Get the content keys for the DRM. The `mode` field selects one of two modes.
|
||||
A slow answer arrives as a [slow response](#slow-responses).
|
||||
|
||||
**Proxy mode** (`mode: "proxy"`, the default) forwards the client's CDM `challenge` to the service's license endpoint and returns the raw license bytes:
|
||||
|
||||
=== "Request"
|
||||
|
||||
```json
|
||||
{ "track_id": "v-1", "challenge": "<base64 CDM challenge>", "drm_type": "widevine" }
|
||||
```
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{ "license": "<base64 license bytes>" }
|
||||
```
|
||||
|
||||
**Server-CDM mode** (`mode: "server_cdm"`) runs the full CDM flow on the server using the device configured for your API key, returning content keys directly. Use `track_id` for a single track or `track_ids` for a batch:
|
||||
|
||||
=== "Single: Response `200`"
|
||||
|
||||
```json
|
||||
{ "keys": { "<kid_hex>": "<key_hex>" }, "vault_keys": ["<kid_hex>"], "drm_type": "widevine" }
|
||||
```
|
||||
|
||||
=== "Batch: Response `200`"
|
||||
|
||||
```json
|
||||
{ "keys": { "v-1": { "<kid_hex>": "<key_hex>" } }, "vault_keys": ["<kid_hex>"], "drm_type": "widevine" }
|
||||
```
|
||||
|
||||
| Field | Description |
|
||||
| --- | --- |
|
||||
| `track_id` / `track_ids` | Single track, or a batch of tracks. |
|
||||
| `challenge` | Base64 CDM challenge (proxy mode). |
|
||||
| `pssh` | Base64 PSSH. Server-CDM mode licenses this PSSH. Proxy mode gives it to the service licence callback as `pssh` (Widevine) or `pssh_b64` (PlayReady), the PSSH of the header the challenge is for. A proxy-mode PSSH that names a KID the track does not carry goes to no callback. |
|
||||
| `drm_type` | `widevine` (default), `playready`, or the id of a DRM plugin that both peers load. In server-CDM mode the server's `cdm` mapping for the service decides the DRM system and the response `drm_type` names the system that licensed. A mapping with a device for each system takes the system of the device the remote session loaded. With no mapping, the client's value decides when the track carries that system; else a system the track carries decides, PlayReady first. The tracks response `server_cdm_type` names the system the same order gives for the title's tracks. A track whose DRM is a whole-file cipher takes `clearkeyctr` with no `pssh`: the service on the server licenses it. A track of a DRM plugin that licenses locally takes the plugin id with no `pssh` and `mode` `server_cdm`: the server answers in `keys` with the content key from a server vault or from a licence of its own plugin device, only in a session that uses the server CDM, and only under the licence cap (`SERVER_CDM_CAPPED` above it). |
|
||||
| `mode` | `proxy` (default) or `server_cdm`. |
|
||||
| `clear_tracks` (response) | Requested track ids that carry no DRM, so they have no keys. Absent when every requested track is encrypted. |
|
||||
| `file_keys` (response) | Content keys of whole-file ciphers, by track id, for a single track and for a batch. Absent when no requested track holds such a cipher. |
|
||||
| `vault_keys` (response) | KIDs whose content key came from a server vault, not the CDM. The client proves such a content key with a decode before it trusts it; the field is absent when every content key came from the CDM. |
|
||||
| `bridge_kids` (response) | For a batch: the KIDs of the init segments of each FairPlay-only track that the server licensed through the FairPlay bridge, by track id. The client needs the content key of each of these KIDs, or the download of that track stops. Absent when the batch has no such track. |
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | License/keys returned. |
|
||||
| `400` | `INVALID_INPUT` | Missing challenge/PSSH, or no CDM device configured for the API key. |
|
||||
| `400` | `INVALID_PARAMETERS` | Unsupported `drm_type`. |
|
||||
| `404` | `TRACK_NOT_FOUND` | Unknown track ID. |
|
||||
| `404` | `NO_CONTENT` | Server CDM produced no keys. |
|
||||
| `422` | `SERVICE_ERROR` | The service aborted during licensing. |
|
||||
|
||||
### `POST /api/session/{session_id}/keys`
|
||||
|
||||
Store the content keys that the client proved on a track and that the server did not serve to this remote session. The server stores a content key only for a KID that a track of the remote session names and that no local server vault holds a content key for. It never stores a pair flagged bad, and it never removes a flag. The server answers when its local vaults hold the pairs, and sends them to its other vaults after the answer. The client sends each key of a licence when the licence returns, and each vault key after its decode check passes. A licence key of a FairPlay-only track that the client licensed through the bridge goes only after its decode check passes, so a client without FFmpeg does not send it.
|
||||
|
||||
```json
|
||||
{ "track_id": "<track_id>", "keys": { "<kid_hex>": "<key_hex>" } }
|
||||
```
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | `{}`, whatever the server stored. |
|
||||
| `404` | `SESSION_NOT_FOUND` | Unknown remote session. |
|
||||
|
||||
### `POST /api/session/{session_id}/keys/bad`
|
||||
|
||||
Report a content key from `vault_keys` that did not decrypt the track. The server flags the pair in its local vaults and reports it to the vault that served it, and the next licence for that KID reaches the CDM. When the CDM returns the same pair, the server removes the flag. The client never learns the server vault names.
|
||||
|
||||
```json
|
||||
{ "kid": "<kid_hex>", "key": "<key_hex>" }
|
||||
```
|
||||
|
||||
| Status | Error code | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `200` | - | `{"flagged": true}`: the pair is flagged. `{"flagged": false}`: the CDM licensed the pair, so it is not flagged. |
|
||||
| `400` | `INVALID_INPUT` | This remote session was not served that pair. |
|
||||
| `404` | `SESSION_NOT_FOUND` | Unknown remote session. |
|
||||
|
||||
### `GET /api/session/{session_id}`
|
||||
|
||||
Return remote session metadata and validity.
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{
|
||||
"session_id": "d4e5f6a7-...",
|
||||
"service": "EXAMPLE",
|
||||
"valid": true,
|
||||
"expires_in": 300,
|
||||
"draining": false,
|
||||
"track_count": 4,
|
||||
"title_count": 10
|
||||
}
|
||||
```
|
||||
|
||||
`404 SESSION_NOT_FOUND` if the remote session does not exist or has expired.
|
||||
|
||||
### `DELETE /api/session/{session_id}`
|
||||
|
||||
Tear down a remote session. The server cancels its input bridge, harvests any updated cache files, and deletes the remote session and its cache directory. A create of the same API key and IP that still runs under this ID ends too: it makes no remote session and answers `404 SESSION_NOT_FOUND`. If no remote session exists yet, the `DELETE` answers `200` with no `cache`.
|
||||
|
||||
=== "Response `200`"
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"cache": { "tokens": "<base64 zlib bytes>", "session_web/<sha1>": "<base64 zlib bytes>" }
|
||||
}
|
||||
```
|
||||
|
||||
The `cache` field is present only if the remote session produced cache files and the login belongs to the client. Each cache key is the file path relative to the session cache directory, with `/` separators and no `.json` suffix, so a file in a subdirectory keeps its place on the client. The server rejects a cache key with a drive letter, a root, a `..` segment, or an empty segment, and so does the client. `404 SESSION_NOT_FOUND` if the remote session does not exist.
|
||||
| `200` | - | Answer accepted. |
|
||||
| `400` | `INVALID_INPUT` | No `response`. |
|
||||
| `404` | `NOT_FOUND` | No such remote login for this API key. |
|
||||
| `409` | `CONFLICT` | The login asks nothing now. |
|
||||
|
||||
---
|
||||
|
||||
@@ -1320,4 +1019,4 @@ When a generic (uncategorized) exception reaches a handler, unshackle inspects i
|
||||
- [REST API overview](index.md). What the server is and when to use it.
|
||||
- [Authentication](authentication.md). Keys, server modes, and the `X-Secret-Key` header.
|
||||
- [Quickstart](quickstart.md). A first end-to-end request walkthrough.
|
||||
- [Downloading](../../guide/downloading.md). The `dl` flags mirrored by `POST /api/download`.
|
||||
- [CLI reference: `dl`](../../guide/cli-reference.md#dl). The `dl` flags mirrored by `POST /api/download`.
|
||||
|
||||
Reference in New Issue
Block a user