mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-05 07:25:08 +00:00
docs: give each dl and serve flag and the error envelope one owner page and tighten the cli-reference test
This commit is contained in:
@@ -18,9 +18,7 @@ Start the server with [`unshackle serve`](../../guide/cli-reference.md). By defa
|
||||
- **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 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.
|
||||
- **Errors.** [Error Responses](errors.md) gives the [standard error shape](errors.md#the-standard-error-shape) and the [authentication error](errors.md#the-authentication-error-exception) of the API-key middleware.
|
||||
|
||||
---
|
||||
|
||||
@@ -439,7 +437,7 @@ Make a download job. It requires `service` and `title_id`. Every other field is
|
||||
|
||||
<!-- download-fields -->
|
||||
|
||||
**Validation.** Invalid values return `400 INVALID_PARAMETERS`. `vcodec`, `acodec` and `sub_format` take the same spellings as the CLI options of the same name (`unshackle dl --help` prints each list). The API and the CLI read one list, so they cannot disagree. `range` must be one of SDR/HDR10/HDR10P/VIVID/DV/HLG/HYBRID, and `HDR10+` and `HDR Vivid` are also valid. The bitrate, download worker, and download counts must be positive integers. You cannot combine `no_subs` with `subs_only`, or `no_audio` with `audio_only`. The server runs the same option checks as `unshackle dl`, so a request that `dl` would refuse returns `400` when you submit it, and the message names the `dl` option. The language fields (`lang`, `v_lang`, `a_lang`, `s_lang`, `forced_s_lang` and the `require_*` fields) must be arrays of strings: a single string such as `"en"` returns `400`. The server checks every other field with the type of its `dl` option. A `null` or an empty string gets the default from the table.
|
||||
**Validation.** Invalid values return `400 INVALID_PARAMETERS`. `vcodec`, `acodec` and `sub_format` take the same spellings as the CLI options of the same name (`unshackle dl --help` prints each list). The API and the CLI read one list, so they cannot disagree. You cannot combine `no_subs` with `subs_only`, or `no_audio` with `audio_only`. The server runs the same option checks as `unshackle dl`, so a request that `dl` would refuse returns `400` when you submit it, and the message names the `dl` option. The language fields (`lang`, `v_lang`, `a_lang`, `s_lang`, `forced_s_lang` and the `require_*` fields) must be arrays of strings: a single string such as `"en"` returns `400`. The server checks every other field with the type of its `dl` option. A `null` or an empty string gets the default from the table.
|
||||
|
||||
**Service options.** A service's own CLI options travel in the same body. Send them in a nested
|
||||
`service_params` object, or as flat top-level keys. When the body has `service_params`, the server
|
||||
@@ -981,37 +979,6 @@ Answer the prompt of a remote login. Body: `{ "response": "..." }` (required).
|
||||
|
||||
---
|
||||
|
||||
## Error responses
|
||||
|
||||
The server serialises every structured error raised inside a handler to the same JSON envelope:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "error",
|
||||
"error_code": "INVALID_PARAMETERS",
|
||||
"message": "Invalid video codec: XYZ",
|
||||
"timestamp": "2026-07-03T12:00:00+00:00",
|
||||
"details": { "field": "vcodec" },
|
||||
"retryable": true,
|
||||
"debug_info": { "exception_type": "APIError", "traceback": "..." }
|
||||
}
|
||||
```
|
||||
|
||||
- `details` appears only when non-empty.
|
||||
- `retryable` appears only when the error is retryable (e.g. network errors, rate limiting).
|
||||
- `debug_info` appears only when you start the server with `--debug-api`.
|
||||
|
||||
!!! warning "Authentication errors differ"
|
||||
Errors raised by the API-key middleware use a distinct shape (`{"status": 401, "message": "Secret Key is Empty."}`, `{"status": 401, "message": "Secret Key is Invalid."}`, or `{"status": 429, "message": "Rate limit exceeded."}` with a `Retry-After` header) with an integer `status` and no `error_code`, `timestamp`, or `details`. A `429` from the middleware therefore carries no `error_code`, unlike the `RATE_LIMITED` code below, which a handler raises for a rate limit the *service* imposed. A malformed JSON body on any POST, by contrast, returns the standard envelope with `error_code: "INVALID_INPUT"`.
|
||||
|
||||
### Error codes and default status
|
||||
|
||||
The [error code catalogue](errors.md#error-code-catalogue) gives the default HTTP status of each error code.
|
||||
|
||||
When a generic (uncategorised) exception reaches a handler, unshackle inspects its message and type to pick a code. For example, messages mentioning "connection" or "timeout" become `NETWORK_ERROR` (424, retryable), "rate limit" or "429" become `RATE_LIMITED` (429, retryable), and anything unrecognised collapses to `INTERNAL_ERROR` (422).
|
||||
|
||||
---
|
||||
|
||||
## See also
|
||||
|
||||
- [Server Overview](index.md). What the server is and when to use it.
|
||||
|
||||
@@ -55,21 +55,8 @@ pywidevine / pyplayready clients) in addition to the REST API.
|
||||
|
||||
### Common options
|
||||
|
||||
The `serve` command accepts the following flags:
|
||||
|
||||
| Option | Default | Effect |
|
||||
|---|---|---|
|
||||
| `-h`, `--host` | `127.0.0.1` | Address to bind to. Use `0.0.0.0` to accept connections from other machines. |
|
||||
| `-p`, `--port` | `8786` | Port to bind to. |
|
||||
| `--api-only` | off | Serve only the REST API, without the Widevine/PlayReady CDM HTTP endpoints. |
|
||||
| `--cdm-only` | off | Serve only the Widevine/PlayReady CDM HTTP endpoints, plus `/api/health` and the dashboard. No REST API, no remote sessions, no Swagger UI. Cannot be combined with `--api-only` or `--remote-only`. |
|
||||
| `--no-widevine` | off | Disable the Widevine CDM endpoints. Cannot be combined with `--api-only`. |
|
||||
| `--no-playready` | off | Disable the PlayReady CDM endpoints. Cannot be combined with `--api-only`. |
|
||||
| `--no-key` | off | Disable API-key authentication entirely; every request is allowed. |
|
||||
| `--remote-only` | off | Expose only the [remote session routes](remote-sessions.md#routes). Implies `--api-only`. |
|
||||
| `--debug-api` | off | Include tracebacks and worker stderr in error responses. |
|
||||
| `--debug` | off | Enable debug-level logging. |
|
||||
| `--caddy` | off | Also launch [Caddy](https://caddyserver.com/) as a reverse proxy, using the `Caddyfile` in your user-config directory. |
|
||||
The [`serve` options](../../guide/cli-reference.md#serve) in the CLI reference give each flag, its
|
||||
default and the flags that you cannot use together.
|
||||
|
||||
```shell title="Serve the REST API only, on all interfaces"
|
||||
unshackle serve --api-only --host 0.0.0.0 --port 8786
|
||||
|
||||
@@ -72,18 +72,7 @@ unshackle serve --api-only
|
||||
|
||||
By default the server binds to `127.0.0.1:8786`. The `--api-only` flag serves only the REST API and omits the Widevine/PlayReady CDM HTTP endpoints. Drop it when you also want those endpoints.
|
||||
|
||||
Common options:
|
||||
|
||||
| Option | Default | Effect |
|
||||
| --- | --- | --- |
|
||||
| `-h, --host` | `127.0.0.1` | Address to bind to |
|
||||
| `-p, --port` | `8786` | Port to bind to |
|
||||
| `--api-only` | off | Serve only the REST API, no CDM endpoints |
|
||||
| `--no-key` | off | Disable API-key authentication (allow all requests) |
|
||||
| `--debug-api` | off | Include tracebacks and stderr in error responses |
|
||||
| `--debug` | off | Enable DEBUG-level logging |
|
||||
| `--remote-only` | off | Expose only the remote session routes: `/api/health`, `/api/services`, `/api/search`, `/api/session/*`, `/api/tunnel` and `/api/tunnel/check`, and the dashboard routes when `serve.dashboard.key` is set |
|
||||
| `--caddy` | off | Also launch Caddy as a reverse proxy (for HTTPS) |
|
||||
The [`serve` options](../../guide/cli-reference.md#serve) in the CLI reference give every flag.
|
||||
|
||||
Once it is up you will see the API mounted under `/api/` and, unless you started in remote-only mode, an interactive Swagger UI:
|
||||
|
||||
@@ -166,7 +155,7 @@ If the API key is missing or wrong, you get a `401` with a plain body:
|
||||
```
|
||||
|
||||
!!! warning "Two error shapes exist"
|
||||
The authentication middleware returns the short `{"status": 401, "message": "..."}` shape shown above. Every **other** error the API produces uses the richer structured shape (`error_code`, `timestamp`, `details`, ...) described in [Error handling](#error-handling). Parse both shapes in your client.
|
||||
The authentication middleware answers with the short shape above, and every other JSON error has the [standard error shape](errors.md#the-standard-error-shape). Parse both shapes in your client.
|
||||
|
||||
The `tag` value for the service you want is the identifier you pass as `service` in the calls below.
|
||||
|
||||
@@ -400,38 +389,7 @@ The interactive **Swagger UI at `/api/docs/`** documents every route and lets yo
|
||||
|
||||
## Error handling
|
||||
|
||||
Apart from the auth middleware's short form, every error the API returns uses a single structured envelope:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "error",
|
||||
"error_code": "INVALID_PARAMETERS",
|
||||
"message": "Human-readable description",
|
||||
"timestamp": "2026-07-03T12:00:00Z",
|
||||
"details": { }
|
||||
}
|
||||
```
|
||||
|
||||
`details` appears only when the server has more to add. `retryable: true` appears only for transient failures. The server includes a `debug_info` block (exception type and traceback) only when it runs with `--debug-api`.
|
||||
|
||||
The `error_code` maps to an HTTP status. The ones you will meet most often:
|
||||
|
||||
| Error code | HTTP | Typical cause |
|
||||
| --- | --- | --- |
|
||||
| `INVALID_INPUT` | 400 | Malformed JSON body or missing required field |
|
||||
| `INVALID_SERVICE` | 400 | Unknown or disallowed service tag |
|
||||
| `INVALID_PARAMETERS` | 400 | A download field failed validation |
|
||||
| `AUTH_FAILED` | 401 | Service login/credential failure |
|
||||
| `FORBIDDEN` | 403 | A gated field was used without server opt-in |
|
||||
| `NOT_FOUND` | 404 | Title or resource does not exist |
|
||||
| `JOB_NOT_FOUND` | 404 | No job with that `job_id` |
|
||||
| `CONFLICT` | 409 | Illegal state transition (e.g. retry a running job) |
|
||||
| `SERVICE_ERROR` | 422 | The service raised an error |
|
||||
| `RATE_LIMITED` | 429 | Upstream throttling (retryable) |
|
||||
| `INTERNAL_ERROR` | 422 | Unexpected server-side failure |
|
||||
| `NETWORK_ERROR` | 424 | Connection/timeout reaching the service (retryable) |
|
||||
|
||||
The [error code catalogue](errors.md#error-code-catalogue) lists every code.
|
||||
|
||||
!!! tip "Retry politely"
|
||||
Codes marked retryable (`NETWORK_ERROR`, `RATE_LIMITED`, `SERVICE_UNAVAILABLE`) reflect transient conditions. Back off and retry rather than hammering the server.
|
||||
Every JSON error has one of two shapes: the [standard error shape](errors.md#the-standard-error-shape),
|
||||
or the [authentication error](errors.md#the-authentication-error-exception) of the API-key
|
||||
middleware. The [error code catalogue](errors.md#error-code-catalogue) gives the HTTP status of
|
||||
each code, and [the `retryable` hint](errors.md#the-retryable-hint) marks the errors to retry.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Remote Session Protocol
|
||||
|
||||
The remote session protocol is the one record of the routes, login states, error codes and message
|
||||
shapes that a `--remote` client and the server share. A remote session keeps an authenticated
|
||||
service on the server between requests. The client logs in one time, then asks for titles, tracks,
|
||||
This page lists the routes, login states, error codes and message shapes that a `--remote` client
|
||||
and the server share. A remote session keeps an authenticated service on the server between
|
||||
requests. The client logs in one time, then asks for titles, tracks,
|
||||
segments and licences in the same remote session. The client downloads, decrypts and muxes.
|
||||
|
||||
The record is `unshackle/core/remote_protocol.py`: both the client (`unshackle/core/remote_service.py`,
|
||||
@@ -174,7 +174,7 @@ The server keeps remote sessions in memory. A restart loses them all.
|
||||
| Idle time | `serve.session_ttl`. Each request and each new remote session channel starts it again. A remote session does not reach it while a request works on it or while its remote session channel is open. |
|
||||
| Idle time during the login | The larger of `session_ttl` and 600 seconds, unless the client is gone. |
|
||||
| Client presence | See [Client presence](#client-presence). |
|
||||
| Remote sessions at the same time | `serve.max_sessions`. A create at the limit ends the least recently used remote session of the API key that holds the most. A remote session that a request works on goes last. |
|
||||
| Remote sessions at the same time | `serve.max_sessions`. A create at the limit ends one remote session: [`max_sessions`](../../reference/configuration/services.md#serve) gives which one. |
|
||||
| Sweep | Every 5 seconds the server ends each expired remote session. |
|
||||
|
||||
[`serve`](../../reference/configuration/services.md#serve) in the configuration reference gives
|
||||
|
||||
@@ -99,10 +99,10 @@ The attributes table of [`Service`][unshackle.core.service.Service] lists each o
|
||||
[Request and HTTP session objects](#request-and-http-session-objects) explains the main ones.
|
||||
|
||||
The constructor also resolves proxies: it reads `--proxy`, which `dl` and `search` have already
|
||||
resolved through the per-service `proxy_map`, and, if `GEOFENCE` is set and you did not give an explicit proxy, does a live
|
||||
IP check and auto-fetches a proxy to `GEOFENCE[0]` when it detects a geoblock. A
|
||||
`GEOBLOCK` hit with no `GEOFENCE` stops the run with a "not available in your region"
|
||||
error, because there is no main region to fetch a proxy for; pass `--proxy` yourself.
|
||||
resolved through the per-service `proxy_map`. Without an explicit proxy, it does a live IP check
|
||||
and, when it detects a geoblock, fetches a proxy to the first `GEOFENCE` region that `GEOBLOCK`
|
||||
allows, as the attributes of [`Service`][unshackle.core.service.Service] give. When no such region
|
||||
is left, the run stops with a "not available in your region" error; pass `--proxy` yourself.
|
||||
A proxy whose exit is in a `GEOBLOCK` region stops the run the same way. A proxy whose exit is
|
||||
outside `GEOFENCE` logs a warning and the run continues.
|
||||
See [Proxies and VPN](../guide/proxies-and-vpn.md).
|
||||
|
||||
Reference in New Issue
Block a user