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:
@@ -73,7 +73,7 @@ unshackle dl EX 20914 # via an ALIAS
|
||||
`preferences` in `config.yaml`, and read it from `self.config["preferences"]`.
|
||||
Over `--remote`, the client's own `services.<TAG>.preferences` values reach
|
||||
that block on the server with no extra code. See
|
||||
[Your preferences](rest-api/remote-sessions.md#your-preferences).
|
||||
[Your preferences](../guide/remote-sessions.md#your-preferences).
|
||||
|
||||
!!! warning "Split across files? Use relative imports"
|
||||
If your service grows beyond a single `__init__.py`, import your own
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# REST API Authentication
|
||||
|
||||
The unshackle REST API protects every endpoint (with one exception) behind a single API key. Clients present that API key in a request header, and the server examines it against the API keys in your configuration. This page explains how that check works, how to configure API keys, and how clients send them. It also explains the extra controls on top of the API key: per-key service allowlists, per-key CDM device access, and remote session IP binding.
|
||||
The unshackle REST API protects every endpoint, `GET /api/health` included, behind an API key. The [dashboard](dashboard.md) routes take the dashboard key instead. Clients present that API key in a request header, and the server examines it against the API keys in your configuration. This page explains how that check works, how to configure API keys, and how clients send them. It also explains the extra controls on top of the API key: per-key service allowlists, per-key CDM device access, and remote session IP binding.
|
||||
|
||||
You start the API with the [`unshackle serve`](../../guide/cli-reference.md) command. Authentication is on by default: if you start the server without an API key configured, it refuses to launch.
|
||||
|
||||
@@ -345,7 +345,7 @@ The header and config are identical between modes, but the code that enforces th
|
||||
|
||||
- **Integrated server** (default). A `serve_authentication` middleware wraps pywidevine's authentication (and pyplayready's for `/playready*` paths), and the REST routes live in the same application, guarded by the same check. Here the accepted-keys map is your full `serve` config: `api_secret` (auto-added with access to all loaded devices) plus every entry under `users`, each with its declared `devices` / `playready_devices`.
|
||||
|
||||
Because the API-only middleware guards *all* non-health paths, the Swagger UI at `/api/docs/` is also behind `X-Secret-Key` there. In `--remote-only` mode the Swagger UI is not mounted at all.
|
||||
Because the API-only middleware guards every path outside the dashboard prefix, the Swagger UI at `/api/docs/` is also behind `X-Secret-Key` there. In `--remote-only` mode the Swagger UI is not mounted at all.
|
||||
|
||||
Both middlewares read the caller's API key through the shared `request_secret_key()` helper in `unshackle/core/api/handlers.py`. That helper returns the `X-Secret-Key` header, and falls back to the `secret_key` query parameter only when the matched route is the job event stream. The integrated server needs one extra branch for this. pywidevine's `authentication` is header-only. So `serve_authentication` compares the API key from the query parameter itself when the header is absent, and delegates to pywidevine in every other case. That is why both modes reject a present-but-wrong header.
|
||||
|
||||
|
||||
+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`.
|
||||
|
||||
@@ -124,7 +124,7 @@ while the server restarts.
|
||||
| `NOT_FOUND` | 404 | A requested resource (title, history entry, and so on) does not exist. |
|
||||
| `NO_CONTENT` | 404 | The request was valid but produced nothing: no matching titles, tracks, episodes, or keys. |
|
||||
| `JOB_NOT_FOUND` | 404 | The referenced download job does not exist. |
|
||||
| `SESSION_NOT_FOUND` | 404 | The remote-dl session does not exist or has expired. |
|
||||
| `SESSION_NOT_FOUND` | 404 | The remote session does not exist or has expired. |
|
||||
| `TRACK_NOT_FOUND` | 404 | A referenced track ID is not present in the remote session. |
|
||||
| `CONFLICT` | 409 | The target resource is in a state that disallows the action (retrying a running job, prioritising a non-queued job, clearing cache during an active download). |
|
||||
| `SERVER_DRAINING` | 409 | The server is about to restart or stops, and starts no new remote session, remote login or download job. Open work continues. Retryable after the restart. A `dl --remote` client waits for the restart and opens a new remote session. |
|
||||
@@ -232,9 +232,9 @@ body that uses an integer `status` and no `error_code` or `timestamp`.
|
||||
|
||||
## Late failures with status `200`
|
||||
|
||||
The remote session `titles`, `tracks` and `license` routes send status `200` and the headers
|
||||
The remote session `titles`, `tracks`, `segments` and `license` routes send status `200` and the headers
|
||||
when the work takes longer than 30 seconds. They then send a newline every 30 seconds to keep
|
||||
the connection open. See [Slow responses](endpoints.md#slow-responses). A failure after that
|
||||
the connection open. See [Slow responses](remote-sessions.md#slow-responses). A failure after that
|
||||
time arrives as the standard error body, but with status `200`. The body has no field for the
|
||||
HTTP status that the error would otherwise have. `error_code` and `retryable` stay in the body.
|
||||
|
||||
|
||||
+13
-23
@@ -28,10 +28,10 @@ calls you can script against:
|
||||
- **History and housekeeping**: read the log of finished jobs, inspect the server's
|
||||
effective (redacted) configuration, examine external tool versions, and clear caches
|
||||
or temp files.
|
||||
- **Remote-download sessions**: a thin local client can authenticate against a
|
||||
service *on the server*, then pull titles, tracks, and segment info back, and proxy
|
||||
- **Remote sessions**: a thin local client can authenticate against a
|
||||
service *on the server*, then pull titles, tracks, and segment info back, and relay
|
||||
DRM licensing. This is how one machine with the credentials and CDMs can serve
|
||||
downloads to another. See [Remote Sessions](remote-sessions.md).
|
||||
downloads to another. See the [remote session protocol](remote-sessions.md).
|
||||
|
||||
Because every download runs as a queued job in a separate job worker process, the API is
|
||||
well suited to running unattended: submit work, come back later, and read the result.
|
||||
@@ -194,29 +194,19 @@ request and response in full.
|
||||
| `POST` | `/api/maintenance/clear-temp` | Clear the temp directory. |
|
||||
| `POST` | `/api/maintenance/refresh-services` | `git pull` each configured service repository and re-import the services that changed. |
|
||||
|
||||
### Remote-download sessions
|
||||
### Remote sessions
|
||||
|
||||
The `/api/session/*`, `/api/tunnel` and `/api/tunnel/check` routes carry the remote sessions of
|
||||
`dl --remote`. The [remote session protocol](remote-sessions.md#routes) lists each route.
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| `POST` | `/api/session/create` | Start a server-side, authenticated service session. |
|
||||
| `GET` | `/api/session/{session_id}` | Remote session info and time-to-live. |
|
||||
| `DELETE` | `/api/session/{session_id}` | Tear down a session. |
|
||||
| `GET` | `/api/session/{session_id}/titles` | Titles for the session's title ID. |
|
||||
| `POST` | `/api/session/{session_id}/tracks` | Tracks (with URLs) for a chosen title. |
|
||||
| `POST` | `/api/session/{session_id}/segments` | Per-track segment/download details. |
|
||||
| `POST` | `/api/session/{session_id}/segment_filter` | Server-side HLS segment filter results for one track. |
|
||||
| `POST` | `/api/session/{session_id}/samples` | Server-side cbcs sample decryption for one track. |
|
||||
| `POST` | `/api/session/{session_id}/license` | Proxy or server-side DRM licensing. |
|
||||
| `POST` | `/api/session/{session_id}/keys` | Store the content keys the client proved on a track. |
|
||||
| `POST` | `/api/session/{session_id}/keys/bad` | Report a server-vault content key that did not decrypt. |
|
||||
| `GET` | `/api/session/{session_id}/channel` | WebSocket of the remote session channel: prompts, CDM calls, logs, login state. |
|
||||
| `GET` | `/api/session/{session_id}/logs` | Drain the service's server-side log output. |
|
||||
| `GET` | `/api/session/{session_id}/prompt` | Poll for interactive auth status/prompt. |
|
||||
| `POST` | `/api/session/{session_id}/prompt` | Submit an answer to an auth prompt. |
|
||||
| `GET` | `/api/remote/logins` | The logins of a [relayed](endpoints.md#remote-services-relay) list call that wait on you. |
|
||||
| `POST` | `/api/remote/logins/{login_id}/input` | Answer the prompt of such a login. |
|
||||
|
||||
!!! note "Remote-only routes"
|
||||
The health, services, search, and `/api/session/*` routes are the ones exposed
|
||||
when the server runs with `--remote-only`. Everything else (downloads, jobs,
|
||||
A server that runs with `--remote-only` exposes only the
|
||||
[remote session routes](remote-sessions.md#routes) and the dashboard routes. Everything else (downloads, jobs,
|
||||
history, config, maintenance) is only available in the full or `--api-only` modes.
|
||||
|
||||
## Authentication in one line
|
||||
@@ -246,8 +236,8 @@ the full model, including per-key service allowlists.
|
||||
shape, endpoint by endpoint.
|
||||
- **[Job Lifecycle](job-lifecycle.md)**: how a download moves from `queued` to a
|
||||
terminal state, live progress, cancellation, and retries.
|
||||
- **[Remote Sessions](remote-sessions.md)**: the `/api/session/*` flow for driving a
|
||||
service from a thin remote client.
|
||||
- **[Remote Session Protocol](remote-sessions.md)**: the routes, login states,
|
||||
licensing modes and message shapes of a remote session.
|
||||
- **[Error Responses](errors.md)**: the standard error envelope, error codes, and
|
||||
their HTTP statuses.
|
||||
|
||||
|
||||
@@ -418,7 +418,7 @@ Each job carries a cancellation event. When you `DELETE` a live job:
|
||||
subprocess (escalating to `kill()` if it does not exit within 5 seconds), and raises
|
||||
a cancellation so the task unwinds. The subprocess model is what makes this a clean,
|
||||
immediate stop rather than a cooperative one. A job with the `remote` parameter first ends its
|
||||
[remote session](remote-sessions.md#when-the-client-ends-a-remote-session), in at most 4
|
||||
[remote session](../../guide/remote-sessions.md#when-the-client-ends-a-remote-session), in at most 4
|
||||
seconds, and runs no post-script after the cancel.
|
||||
|
||||
### Secret handling in serialized jobs
|
||||
@@ -437,4 +437,4 @@ or logs them.
|
||||
- [Endpoints](endpoints.md): the full request/response reference for every job endpoint.
|
||||
- [Error Responses](errors.md): the error envelope, codes, and HTTP statuses a failed job reports.
|
||||
- [Authentication](authentication.md): the `X-Secret-Key` header and per-key service allowlists that gate job creation and retry.
|
||||
- [Downloading](../../guide/downloading.md): the equivalent options on the `dl` command line.
|
||||
- [CLI reference: `dl`](../../guide/cli-reference.md#dl): the equivalent options on the `dl` command line.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,371 @@
|
||||
# Remote sessions
|
||||
|
||||
A remote session runs a service on a remote unshackle server and the download on your machine.
|
||||
The server logs in to the service, lists the titles, gets the tracks and their manifests, and can
|
||||
license the tracks. Your machine selects the tracks, downloads and decrypts them, and muxes the
|
||||
result.
|
||||
|
||||
!!! note "When to use a remote session"
|
||||
- The server has service accounts, cookies or a CDM that you do not want to copy to each machine.
|
||||
- You want to download on a fast machine and keep the logins and the licensing in one place.
|
||||
- A service is available only in the region of the server.
|
||||
|
||||
The server is an `unshackle serve` instance. The routes, fields and message shapes between your
|
||||
machine and the server are on the [remote session protocol](../dev/rest-api/remote-sessions.md)
|
||||
page. The server settings are under [`serve`](../reference/configuration/services.md#serve).
|
||||
|
||||
## Configure the client
|
||||
|
||||
On your machine (the client), add a `remote_services` block to `unshackle.yaml`. Each entry names
|
||||
a server and gives its URL and API key:
|
||||
|
||||
```yaml title="unshackle.yaml (client)"
|
||||
remote_services:
|
||||
my_server:
|
||||
url: "https://my-box.example:8786"
|
||||
api_key: "your-api-key"
|
||||
server_cdm: true # optional: the server CDM licenses the tracks
|
||||
services:
|
||||
EXAMPLE:
|
||||
server_cdm: false # optional: your own CDM licenses EXAMPLE
|
||||
title_map:
|
||||
"0ABCDEF": "The Show (Renamed Locally)"
|
||||
```
|
||||
|
||||
[`remote_services`](../reference/configuration/services.md#remote_services) in the configuration
|
||||
reference gives each setting of a server entry.
|
||||
|
||||
### Select a server
|
||||
|
||||
When you configure one server, unshackle uses it:
|
||||
|
||||
```bash
|
||||
unshackle dl --remote EXAMPLE 0ABCDEF
|
||||
```
|
||||
|
||||
When you configure more than one server, select one with `--server`:
|
||||
|
||||
```bash
|
||||
unshackle dl --remote --server my_server EXAMPLE 0ABCDEF
|
||||
```
|
||||
|
||||
With no `remote_services` block, unshackle stops with an error that tells you to add one.
|
||||
|
||||
### Make a service remote by default { #making-a-service-remote-by-default }
|
||||
|
||||
To run a service on the server without `--remote`, set `remote` in the
|
||||
[`services`](../reference/configuration/services.md#services) block, not in the `services`
|
||||
sub-dict of `remote_services`. Add `server` to select one of several servers:
|
||||
|
||||
```yaml title="unshackle.yaml (client)"
|
||||
services:
|
||||
EXAMPLE:
|
||||
dl:
|
||||
remote: true
|
||||
server: my_server
|
||||
```
|
||||
|
||||
`unshackle dl EXAMPLE 0ABCDEF` and `unshackle search EXAMPLE "query"` then run on `my_server`.
|
||||
`--local` runs the local service code for one run. The
|
||||
[`services`](../reference/configuration/services.md#services) reference gives the other rules.
|
||||
|
||||
---
|
||||
|
||||
## What happens during a download
|
||||
|
||||
The command looks like an ordinary download. The client takes the remote session through these
|
||||
steps.
|
||||
|
||||
=== "1. Log in"
|
||||
|
||||
The client creates the remote session and sends what it can, so that the server does not
|
||||
have to prompt:
|
||||
|
||||
- The local **credentials** and **cookies** of the service and profile.
|
||||
- The local **cache files** of the service (for example refreshed tokens), including the files
|
||||
in subdirectories of the service cache directory, but only the files of the active profile.
|
||||
The client withholds a file whose path, in any directory or file name, embeds a hash of another
|
||||
credential or the name of another profile. Thus the tokens of one profile never reach the
|
||||
server while you use a different profile. At worst, a withheld file makes the server log in
|
||||
again.
|
||||
- A resolved **proxy**, or, if you set none, your detected **region**. Without the
|
||||
[`server_proxy`](../reference/configuration/services.md#serve) grant on your API key, the
|
||||
proxy must be a full proxy URI on a public host, and the server rejects the remote session when
|
||||
it is in a different region from yours: pass `--proxy` with your own proxy, or `--no-proxy`
|
||||
to accept the server's own connection. For Control D, see
|
||||
[Control D](proxies-and-vpn.md#control-d). The client also downloads playlists and segments
|
||||
through the same proxy, as a local run does. `--no-proxy-download` and `--proxy-download`
|
||||
change that for downloads only.
|
||||
- With `--local-proxy`, the client opens a tunnel first, and the server sends the service
|
||||
requests through your machine's own connection. See
|
||||
[Send the server's requests through your machine](proxies-and-vpn.md#send-the-servers-requests-through-your-machine).
|
||||
- Your track selection (`-r`, `-v`, `-q`, `--best-available`, `--generate-dv`) and your language and
|
||||
audio codec selection (`-l`, `-vl`, `-al`, `-a`, `-fs`), so that the server fetches the right
|
||||
manifests. Some services fetch one manifest for each audio language.
|
||||
|
||||
The server uses its own accounts only when the operator lists the service in
|
||||
`serve.server_accounts` and gives your API key `server_accounts`. For any other service, a
|
||||
client that sends no credentials or cookies logs in with nothing. For a listed service the client
|
||||
sends no credentials, cookies or cache: the server picks one of its own accounts that works in
|
||||
your region, and rotates through them. `--proxy ca` picks a `ca` account.
|
||||
|
||||
The service listing of the server gives the regions that those accounts cover. When your region is
|
||||
not one of them and you set no `--proxy`, the client resolves a proxy for the first of those
|
||||
regions itself, so both sides are in a region that the account works in. This is a bare region
|
||||
query, so it skips Control D. A server-account service does not accept a Control D resolver from
|
||||
the client.
|
||||
|
||||
=== "2. Prompts"
|
||||
|
||||
Some services need a one-time code, a PIN or a device confirmation. When the login on the server
|
||||
asks for input, the server sends the prompt to the client. The client shows it to you, and sends
|
||||
your answer back.
|
||||
|
||||
```text
|
||||
Enter the 6-digit code sent to your email: 483920
|
||||
```
|
||||
|
||||
The server also sends each record of the service's own log to the client, which prints it, so you
|
||||
see the reason when a step fails on the server.
|
||||
|
||||
=== "3. Titles and tracks"
|
||||
|
||||
The client gets the title list, then the tracks of the title that you select. The server sends
|
||||
the manifests, and the client parses them again to download the segments itself. The client
|
||||
uses the HTTP headers and cookies that the server used. Each cookie keeps its domain, path and
|
||||
`secure` flag, so it goes only to its own hosts.
|
||||
|
||||
=== "4. Licensing"
|
||||
|
||||
For a DRM-protected title, the [licensing mode](#who-licenses-the-tracks) of the remote session
|
||||
decides who licenses each track.
|
||||
|
||||
=== "5. Download and end"
|
||||
|
||||
The client downloads, decrypts and muxes locally. While it works, the remote session stays open,
|
||||
so a long download does not let it expire. When the run ends, also early (`--list`, Ctrl+C, an
|
||||
error), the client ends the remote session (see
|
||||
[When the client ends a remote session](#when-the-client-ends-a-remote-session)).
|
||||
|
||||
When the login belongs to the client, the server returns the changed cache files (for example
|
||||
a refreshed token), and the client saves them, so the **next** remote session can skip the
|
||||
interactive login. The login belongs to the client when it succeeds and the remote session uses
|
||||
no server account. This includes a pair code that you approve on another device. A server-account
|
||||
login never belongs to the client, and neither does a remote session on the server's device (see
|
||||
below). The client saves only the returned files that pass the same profile check as before it
|
||||
sent them, so a file for another profile cannot overwrite that profile's local file.
|
||||
|
||||
!!! tip "Rename remote titles locally"
|
||||
To rename titles of a remote service that you do not have installed locally, add a `title_map`
|
||||
under that service in `remote_services.<name>.services`. The server sends the titles exactly as
|
||||
the service returns them, and applies no `title_map` of its own. The client applies your map,
|
||||
so the output name stays under your control.
|
||||
|
||||
---
|
||||
|
||||
## Who licenses the tracks
|
||||
|
||||
When the server creates the remote session, it fixes the licensing mode: who licenses the tracks
|
||||
for the whole remote session. There are four licensing modes:
|
||||
|
||||
| Licensing mode | Who licenses | When |
|
||||
|---|---|---|
|
||||
| Server CDM | The server's device, up to the licence cap of your API key. The client needs no CDM. | Your API key has the `server_cdm` grant for the service, and your client did not decline it. |
|
||||
| Client device | Your local CDM, through a licence relay on the server. With the [`server_vault`](../reference/configuration/services.md#serve) grant (or `server_cdm`), the server vault answers first, and a track that no server vault holds goes back to your device. | Your client declined the server CDM, the API key has no server CDM for the service, or `-q` asks for more than the licence cap. |
|
||||
| Lent device | Nobody licenses live. The content keys come from the server vault (with the grant) or from your own vaults. | A service option runs the remote session on the server's device. |
|
||||
| No device | Nobody licenses: only your own key vaults can give the content keys. The service on the server sees no device. | No server CDM, and your client has no local CDM. |
|
||||
|
||||
### The server CDM
|
||||
|
||||
The server checks its key vaults, loads the device for your API key, licenses, and returns the
|
||||
content keys. When the server's `cdm` entry for the service has a `widevine` and a `playready`
|
||||
device, the server loads the device of your local CDM's DRM system. See
|
||||
[`cdm`](../reference/configuration/drm.md).
|
||||
|
||||
- Set `server_cdm: true` in the server entry to ask for it.
|
||||
- A content key from a server vault is unproven. The client decrypts with it and checks that the
|
||||
output decodes, and reports a wrong pair to the server. The server flags the pair, and the next
|
||||
licence for that KID reaches the CDM. The client never learns the server vault names.
|
||||
- A content key in your own vaults goes first, also when the server already answered. The client
|
||||
proves it, and a server key waits as the next candidate.
|
||||
- When the server licence fails, or the server gives a track no content key, your own device
|
||||
licenses the track only when the `cdm` entry for the service gives the loaded device (see
|
||||
[`remote_services`](../reference/configuration/services.md#remote_services)). Otherwise, or when
|
||||
that device also fails, the run stops at the licence step of that track with one `DRM_ERROR` line.
|
||||
|
||||
!!! note "The licence cap"
|
||||
An API key with `server_cdm_max_height` gets the server CDM only up to that height. Above it,
|
||||
the client reads its own key vaults first, then licenses the track with its own local CDM. When
|
||||
the track has no DRM of that CDM's system, the client uses the device that its own `cdm` entry
|
||||
names for the DRM system of the track. With no such device, the download of that track stops. See
|
||||
[`server_cdm_max_height`](../reference/configuration/services.md#serve).
|
||||
|
||||
### Your own device
|
||||
|
||||
Your local CDM makes the licence challenge. The server sends it to the service, and returns the
|
||||
licence for your CDM to parse.
|
||||
|
||||
- Your client declines the server CDM in the cases that
|
||||
[`remote_services`](../reference/configuration/services.md#remote_services) gives
|
||||
(`server_cdm: false`, `dl --cdm`, a `cdm` entry for the service). The server then builds the service on your
|
||||
device, also when the API key has the server CDM.
|
||||
- A service option that the service lists in `SERVER_DEVICE_OPTIONS` keeps the server CDM, and the
|
||||
service gets the server's device whatever device you have. The client shows a warning when the
|
||||
server did not apply its choice.
|
||||
- The service on the server sees your device, not the server's. See
|
||||
[Your own device identity](#your-own-device-identity).
|
||||
|
||||
### The lent device
|
||||
|
||||
A service can offer an option that builds the remote session on the server's own device and
|
||||
identity, for the quality that device reaches. The remote session then makes no live licence: each
|
||||
content key comes from the server vault or your own vaults, and a content key that no vault holds
|
||||
stops the download with an error that names its KID, when the client knows it. The service uses the
|
||||
server's own config: your identity values do not apply, but your preferences do (see
|
||||
[Your preferences](#your-preferences)). The client reads the server vault only when the API key has
|
||||
the `server_vault` grant (or `server_cdm`). The login tokens of such a remote session hold the
|
||||
server's device identity, so the server keeps them and returns no cache files.
|
||||
|
||||
!!! note "A DRM type that the client does not know"
|
||||
The client rebuilds the DRM of each track from the track list of the server. When the server
|
||||
sends a DRM type that the client does not know, the client stops the title with one `DRM_ERROR`
|
||||
line that names the type. Update the client to the version of the server.
|
||||
|
||||
### Your own device identity
|
||||
|
||||
A service can need more than a licence challenge from your device: an ESN, model keys, or a
|
||||
session-key exchange that runs on the CDM. The device never leaves your machine. Only these cross
|
||||
to the server:
|
||||
|
||||
- **Device facts.** The client sends its DRM system, security level, system ID and device type. The
|
||||
service sees a stand-in with these facts.
|
||||
- **CDM calls.** When the service calls the CDM, the server sends the call to the client and waits.
|
||||
The client makes the challenge, or parses the licence, on its own CDM. When the service closes a
|
||||
CDM session, the server tells the client, because a CDM holds only a few sessions.
|
||||
- **Session keys only.** The client returns only the Widevine `OPERATOR_SESSION` and `SIGNING` keys.
|
||||
It never returns a content key, and it refuses a PlayReady keys call. Thus a server cannot use your
|
||||
device to license titles for itself.
|
||||
- **Identity config.** A service lists the config keys that a client may send (for example a device
|
||||
serial, device keys, or a map of serials). The client sends only those keys, from its own `services: <TAG>:` block in
|
||||
`unshackle.yaml`. When the client sends an identity, the server drops its own value for each of
|
||||
those keys, so the two identities never mix. A mapping merges the client's
|
||||
entries over the server's. A client entry replaces a server entry with the same key, also when the
|
||||
server's key is a number. The server keeps these values in the memory of the remote session only.
|
||||
|
||||
### Your preferences
|
||||
|
||||
The `preferences` block of a service is the place for user choices, such as a metadata language or
|
||||
a subtitle format. It is not an identity, so it crosses `--remote` in every licensing mode, whatever
|
||||
CDM the client has, and no service declares anything for it:
|
||||
|
||||
- The client sends each entry of its own `services: <TAG>: preferences:` block in `unshackle.yaml`
|
||||
that is a string, a number or a boolean. It leaves out other entries and logs one debug line for
|
||||
each.
|
||||
- The server merges the entries key by key over its own `preferences` block for that service. An
|
||||
entry that the client sends replaces the server's value, and a config key that the client does not
|
||||
send keeps the server's value. The entries never count as an identity, and they stay when the
|
||||
service builds the remote session on the server's device.
|
||||
- The server refuses a `preferences` value that is not an object of strings, numbers and booleans
|
||||
with `INVALID_INPUT`.
|
||||
|
||||
A service reads its preferences from `self.config["preferences"]`, locally and over `--remote`
|
||||
alike. Keep a value that changes the server's account (a profile, an account type) out of
|
||||
`preferences` unless every client of the server may choose it: a server account is shared, and the
|
||||
service can store the choice in its cache.
|
||||
|
||||
---
|
||||
|
||||
## When the server restarts
|
||||
|
||||
The server keeps remote sessions in memory only, so a restart loses them all. The client recovers
|
||||
in two ways:
|
||||
|
||||
- **A drain.** The operator can announce a restart. The client then finishes the current title,
|
||||
ends its remote session so that the refreshed cache comes back, waits until the server is back,
|
||||
opens a new remote session and continues with the next title.
|
||||
- **A lost remote session.** After a connection error, an answer cut off after its headers, a timeout,
|
||||
a closed tunnel or a gateway error page, the client waits for the server and checks the old remote
|
||||
session. A live remote session takes the call again only after a connection error, because a call
|
||||
that timed out can already have run. A cut-off answer counts as a connection error, so the server
|
||||
can run that call twice. The client replaces a lost remote session: it opens a new one, gets the
|
||||
titles and the tracks of the current title again, and sends the failed call again. It matches a
|
||||
title by season and episode number, and a track by its attributes, so a new ID on the server
|
||||
changes nothing for the run.
|
||||
|
||||
The client waits up to 30 minutes for the server, which covers the drain of a deploy. A Ctrl+C ends
|
||||
this wait. The client stops with an error when the new remote session licenses differently from the
|
||||
old one, for example after a change to the `server_cdm` grant of the API key. An interactive login
|
||||
asks for its input again.
|
||||
|
||||
## When the client ends a remote session
|
||||
|
||||
The client ends the remote session, closes its tunnel, and saves the returned cache:
|
||||
|
||||
- when `dl` has finished every title, before the run post-scripts
|
||||
- when the process exits: `--list`, an error, or Ctrl+C in any step, also before the server answers
|
||||
the create request
|
||||
- when a signal or a closed console stops the process, or the cancel of a download job stops its
|
||||
worker
|
||||
- when the login or any other step of the opening fails, or the create request times out or its
|
||||
answer is cut off
|
||||
- when a server that relays for a REST client closes its pooled remote session, or stops
|
||||
|
||||
The end request has a connect and read timeout of 15s each. The client sends it again only once,
|
||||
when a gateway answers with an error page or asks for the API key in the other header. It does not
|
||||
wait for a rate limit.
|
||||
|
||||
A Ctrl+C during the downloads cancels the run. The client waits for the download threads and for
|
||||
the content keys that still go to the vaults, and then ends the remote session. The cancel ends each
|
||||
wait of a download thread within 0.5s: the wait for a server that restarts, for a rate limit and
|
||||
for a login. A cancelled thread opens no new remote session. The cancel does not stop a request
|
||||
that the server already has: the client waits for its answer. A failed track is not a cancel, so
|
||||
the next title can open a new remote session.
|
||||
|
||||
While the client ends a remote session, it ignores the first Ctrl+C, so it does not lose the
|
||||
returned cache. The next Ctrl+C stops the wait at once. On Windows, a Ctrl+C counts when the network
|
||||
read that blocks returns, so the 15s timeout limits the wait.
|
||||
|
||||
`SIGHUP` (a closed terminal) and `SIGTERM` stop `dl`, `search` and `tunnel-test` as Ctrl+C does,
|
||||
with an exit code other than 0. Three things are different:
|
||||
|
||||
- The end request goes first: before the wait for the download threads, for a CDM call and for the
|
||||
remote session channel.
|
||||
- The process ends 8s after the first signal at the latest, also when the server does not answer.
|
||||
- A later signal changes nothing, and Ctrl+C keeps its own count.
|
||||
|
||||
After `SIGHUP` the process writes nothing more to a terminal. A redirected output gets each line.
|
||||
`nohup` keeps its effect.
|
||||
|
||||
On Windows, a closed console window and Ctrl+Break send the end request and then end the process,
|
||||
without the rest of the Ctrl+C steps. The system gives a closed window about 5s. A kill
|
||||
(`SIGKILL`, a Windows task end, the cancel of a download job on Windows) sends no end request, so
|
||||
only the server ends the remote session, at its own limits (see
|
||||
[Remote session lifetime](../dev/rest-api/remote-sessions.md#remote-session-lifetime)). A cancelled
|
||||
job that uses a remote server sends the end request for at most 4s, then its worker ends.
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
!!! example "\"Could not connect to remote server at ...\""
|
||||
The client could not reach the URL. Make sure that `unshackle serve` runs on the server, that
|
||||
the `url` and port in `remote_services` are correct (default port `8786`), and that each firewall
|
||||
or reverse proxy allows the connection.
|
||||
|
||||
!!! example "`Remote server <url> rejected the API key (HTTP 401)`"
|
||||
The server does not know the `api_key` of the `remote_services` entry. Ask the operator for a
|
||||
valid API key, or set `auth_headers` when a gateway in front of the server reads another header.
|
||||
|
||||
!!! example "`403 FORBIDDEN` during a download"
|
||||
The request came from a different IP address than the one that created the remote session.
|
||||
Remote sessions are bound to that address. Do not move between networks (or NAT egress
|
||||
addresses) during a remote download.
|
||||
|
||||
!!! example "The login times out or the prompt never resolves"
|
||||
An interactive login has a time limit (see
|
||||
[Login states](../dev/rest-api/remote-sessions.md#login-states)). After that time the login
|
||||
fails and the server ends the remote session. Start the download again. If the server never prompts you, make
|
||||
sure that the credentials and cookies that the client sent are valid for the service.
|
||||
|
||||
!!! example "\"Multiple remote services configured, pick one with --server: ...\""
|
||||
You have more than one entry under `remote_services`. Pass `--server <name>` to select one.
|
||||
@@ -21,7 +21,7 @@ Per-service configuration, keyed by the service tag in any case (for example `EX
|
||||
several servers. On the command line, `--local` and `--server` override these keys. A REST API job ignores both keys.
|
||||
A REST API job takes the other keys that it accepts as download parameters as its defaults,
|
||||
above the `serve` defaults and below the values that the request sends.
|
||||
See [making a service remote by default](../../dev/rest-api/remote-sessions.md#making-a-service-remote-by-default).
|
||||
See [making a service remote by default](../../guide/remote-sessions.md#making-a-service-remote-by-default).
|
||||
|
||||
A service can also read settings of its own, such as a preferred metadata language. The service's own
|
||||
`config.yaml` and its README, when it has one, name them. To change one, copy its config key into this
|
||||
@@ -31,10 +31,10 @@ other values in the same section stay.
|
||||
|
||||
Over `--remote`, the server builds the service from its own config. The client sends only the
|
||||
config keys that the service lists for a client identity, see
|
||||
[your own device identity](../../dev/rest-api/remote-sessions.md#your-own-device-identity),
|
||||
[your own device identity](../../guide/remote-sessions.md#your-own-device-identity),
|
||||
and the strings, numbers and booleans of its `preferences` block. Each preference that you set
|
||||
replaces the server's value for that config key, in every licensing mode, see
|
||||
[your preferences](../../dev/rest-api/remote-sessions.md#your-preferences).
|
||||
[your preferences](../../guide/remote-sessions.md#your-preferences).
|
||||
For every other setting, the value in the server's config applies.
|
||||
|
||||
User- or device-specific values (API keys, account IDs, device attributes) belong in this block
|
||||
@@ -171,7 +171,7 @@ unshackle cannot fetch the list. Each synthetic command carries the server-side
|
||||
documentation, so `unshackle dl --remote <TAG> -h` shows the same help text as it does on the
|
||||
server. Service names resolve against the server's tags and aliases, not your local services.
|
||||
If the server does not offer a name to your API key, unshackle rejects the name and lists the
|
||||
tags it does offer. See [remote sessions](../../dev/rest-api/remote-sessions.md) for the
|
||||
tags it does offer. See [remote sessions](../../guide/remote-sessions.md) for the
|
||||
full setup.
|
||||
|
||||
## `serve`
|
||||
@@ -187,10 +187,10 @@ is the [REST API](../../dev/rest-api/index.md) section. These are the config key
|
||||
| `users` | dict | `{}` | Per-user API keys and their allowlists (see below). |
|
||||
| `tiers` | dict | `{}` | Named settings that `users` entries reference by name (see below). |
|
||||
| `services` | list | *(unset)* | Global service allowlist. Omit to allow all. |
|
||||
| `remote_only` | bool | `false` | Expose only the remote service session endpoints (health, services, search, session) and disable the rest of the REST API. |
|
||||
| `remote_only` | bool | `false` | Expose only the [remote session routes](../../dev/rest-api/remote-sessions.md#routes) and disable the rest of the REST API. |
|
||||
| `dashboard` | dict | *(unset)* | Developer dashboard: `key` is the API key for the read-only `/api/dashboard/` endpoints (status, remote sessions, remote session logs, jobs, keys, services, health, logs, SSE events). Unset leaves those routes unregistered, and a reload that removes the key makes them answer `404`. See [dashboard endpoints](../../dev/rest-api/dashboard.md). |
|
||||
| `session_ttl` | int (s) | `300` | Seconds a remote session can stay idle before it expires. A remote client sends keep-alive requests to its remote session during a download, so the remote session does not expire during a long download. A remote session that still logs in can stay idle for the larger of this value and 600 seconds. A client that closes or loses its channel and does not come back loses its remote session sooner: see [Client presence](../../dev/rest-api/remote-sessions.md#client-presence). |
|
||||
| `max_sessions` | int or null | `100` | Maximum concurrent remote sessions; at the cap the server evicts the oldest remote session of the API key that holds the most. Set it to `null` or `0` for no limit, which is also what `/api/dashboard/status` then reports, so a dashboard can tell "no cap" from a cap that happens to sit at the default. |
|
||||
| `session_ttl` | int (s) | `300` | Seconds a remote session can stay idle before it expires. An open session channel, or a request that works on the remote session, keeps it from expiring, so it does not expire during a long download. A remote session that still logs in can stay idle for the larger of this value and 600 seconds. A client that closes or loses its channel and does not come back loses its remote session sooner: see [Client presence](../../dev/rest-api/remote-sessions.md#client-presence). |
|
||||
| `max_sessions` | int or null | `100` | Maximum concurrent remote sessions; at the cap the server evicts the least recently used remote session of the API key that holds the most, and a remote session that a request works on goes last. Set it to `null` or `0` for no limit, which is also what `/api/dashboard/status` then reports, so a dashboard can tell "no cap" from a cap that happens to sit at the default. |
|
||||
| `history_limit` | int | `100` | How many finished jobs to retain in history. |
|
||||
| `compression_level` | int | `1` | gzip level for responses. |
|
||||
| `services_refresh_interval` | int (s) | `0` | How often the server pulls the git-backed service repositories in `directories.services` and hot-reloads the services that changed. `0` turns it off. A service with a running or queued job, or a live remote session, is staged and swaps to the new code as soon as its last job and session finish. |
|
||||
|
||||
+2
-1
@@ -126,6 +126,7 @@ nav:
|
||||
- Key Vaults: guide/vaults.md
|
||||
- Output & Naming: guide/output-and-naming.md
|
||||
- Subtitles: guide/subtitles.md
|
||||
- Remote Sessions: guide/remote-sessions.md
|
||||
- Troubleshooting: guide/troubleshooting.md
|
||||
- Configuration:
|
||||
- Overview: reference/configuration/index.md
|
||||
@@ -149,7 +150,7 @@ nav:
|
||||
- Endpoints: dev/rest-api/endpoints.md
|
||||
- Job Lifecycle: dev/rest-api/job-lifecycle.md
|
||||
- Dashboard: dev/rest-api/dashboard.md
|
||||
- Remote Sessions: dev/rest-api/remote-sessions.md
|
||||
- Remote Session Protocol: dev/rest-api/remote-sessions.md
|
||||
- Error Responses: dev/rest-api/errors.md
|
||||
- API Reference:
|
||||
- Service: reference/api/service.md
|
||||
|
||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import functools
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -26,6 +27,7 @@ CLIENT_METHODS = {
|
||||
"ws_connect": "GET",
|
||||
}
|
||||
SERVED = {(method, path): handler for method, path, handler, _ in routes.ROUTES}
|
||||
ROOT = Path(__file__).parents[3]
|
||||
|
||||
|
||||
@functools.cache
|
||||
@@ -103,6 +105,22 @@ def test_the_server_takes_its_remote_session_routes_from_the_protocol():
|
||||
assert {path for path in served_paths if path.startswith("/api/session")} <= protocol_paths
|
||||
|
||||
|
||||
def test_the_protocol_page_lists_each_remote_route():
|
||||
"""The route table of the protocol page holds the routes that a remote-only server mounts, and no other.
|
||||
|
||||
Each route of the table that the page itself documents has a section of its own.
|
||||
"""
|
||||
page = (ROOT / "docs" / "dev" / "rest-api" / "remote-sessions.md").read_text(encoding="utf-8")
|
||||
listed = set(re.findall(r"^\| `(GET|POST|DELETE)` \| `([^`]+)` \|", page, re.MULTILINE))
|
||||
sections = set(re.findall(r"^### `(GET|POST|DELETE) ([^`]+)`$", page, re.MULTILINE))
|
||||
assert listed == {(method, path) for method, path, _, remote in routes.ROUTES if remote}
|
||||
assert sections == listed - {
|
||||
("GET", protocol.HEALTH_ROUTE),
|
||||
("GET", protocol.SERVICES_ROUTE),
|
||||
("POST", protocol.SEARCH_ROUTE),
|
||||
}
|
||||
|
||||
|
||||
def test_the_wire_values_stay_what_older_peers_send():
|
||||
"""Both halves read one record, so only this list catches a renamed value that an older peer still sends."""
|
||||
assert {name: getattr(protocol, name) for name in ROUTE_NAMES} == {
|
||||
|
||||
Reference in New Issue
Block a user