mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-05 07:25:08 +00:00
docs(rest-api): build the download request table from the OpenAPI yaml
This commit is contained in:
@@ -437,68 +437,9 @@ Make a download job. It requires `service` and `title_id`. Every other field is
|
||||
}
|
||||
```
|
||||
|
||||
**Common parameters** (all optional). These mirror the [`dl` command](../../guide/downloading.md) flags:
|
||||
**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.
|
||||
|
||||
| Field | Type | Default | Notes |
|
||||
| --- | --- | --- | --- |
|
||||
| `profile` | string | `null` | Credential/cookie profile. |
|
||||
| `quality` | int[] | `[]` | Target resolution(s); best available if empty, or the lowest with `worst`. |
|
||||
| `vcodec` | string/string[] | `[]` | Video codec filter. |
|
||||
| `acodec` | string/string[] | `[]` | Audio codec filter. |
|
||||
| `vbitrate` / `abitrate` | int | `null` | Video / audio bitrate in kbps (positive). |
|
||||
| `vbitrate_range` / `abitrate_range` | string | `null` | `"MIN-MAX"` bitrate window. |
|
||||
| `range` | string[] | `["SDR"]` | Dynamic range(s). |
|
||||
| `channels` | number | `null` | Audio channel layout. |
|
||||
| `no_atmos` | boolean | `false` | Exclude Atmos tracks. |
|
||||
| `wanted` | string / string[] | `[]` | Episode/season selectors, as a list or as one comma-separated string. Accepts the part form, `"S01E01.2"`, and the air-date form, `"2026-08-11"` or `"2026-08-01:2026-08-31"`. For a music release, a selector is a number of the track list, `"1-5"` or `"1,3,7"`, or `"{disc}x{track}"` such as `"2x3"`. |
|
||||
| `latest_episode` | boolean | `false` | Only the newest episode. |
|
||||
| `latest_episodes` | integer | `null` | Only the N newest episodes. A positive integer. When set, it overrides `latest_episode`. |
|
||||
| `max_downloads` | integer | `null` | Stop the job after N titles have downloaded. A positive integer. A title in `skipped_titles` or `already_present` does not count. |
|
||||
| `lang` / `v_lang` / `a_lang` / `s_lang` | string[] | `["orig"]` / `[]` / `[]` / `["all"]` | Language filters. A missing `s_lang` language gives a warning and the job continues. |
|
||||
| `require_audio` | string[] | `[]` | Audio languages that must exist. The job fails if one is missing, even with `best_available`, or skips the title with `skip_missing`. |
|
||||
| `require_video` | string[] | `[]` | Video languages that must exist. The job fails if one is missing, even with `best_available`, or skips the title with `skip_missing`. |
|
||||
| `require_subs` | string[] | `[]` | Subtitle languages that must exist. The job fails if one is missing, or skips the title with `skip_missing`. `s_lang` still decides what to keep. |
|
||||
| `skip_missing` | boolean | `false` | Skip a title that misses a required language or track, and continue with the next title. The job's `skipped_titles` lists each skip. The job fails when it has one title or skips every title. |
|
||||
| `skip_existing` | boolean | `false` | Skip variants recorded as completed for this API key, matched after selection by service, title ID, quality, range and codec. Does not verify files on disk or compare audio/subtitle choices. |
|
||||
| `force` | boolean | `false` | Bypass the completion archive check for this job. Does not change overwrite behaviour. |
|
||||
| `forced_subs` | boolean | `false` | Include forced subtitles. |
|
||||
| `forced_subs_only` | boolean | `false` | Download forced subtitles and no other subtitle; implies `forced_subs`. Not valid with `no_subs`, `video_only`, `audio_only` or `chapters_only`. |
|
||||
| `forced_s_lang` | string[] | `[]` | Forced subtitle language(s); implies `forced_subs`. |
|
||||
| `exact_lang` | boolean | `false` | A language tag without a region never falls back to another variant. A tag with a region is always exact. |
|
||||
| `sub_format` | string | `null` | Output subtitle format. |
|
||||
| `sub_font` | string | `null` | Font for subtitles converted to ASS; implies `sub_format` ASS. With another `sub_format` the request returns `400`. |
|
||||
| `video_only` / `audio_only` / `subs_only` / `chapters_only` | boolean | `false` | Track-type restriction. Two or more combine, as on the CLI. |
|
||||
| `no_subs` / `no_audio` / `no_chapters` / `no_video` / `no_attachments` | boolean | `false` | Skip a track type. |
|
||||
| `skip_subtitle_errors` | boolean | `false` | Skip a subtitle that fails to download and keep the other tracks. |
|
||||
| `audio_description` | boolean | `false` | Download audio description. |
|
||||
| `audio_description_only` | boolean | `false` | Download audio description and no standard audio. Not valid with `no_audio`, `video_only`, `subs_only` or `chapters_only`. |
|
||||
| `slow` | boolean/string/array | `null` | Randomized delay between downloads: `true` (60-120 seconds), `"MIN-MAX"`, or `[MIN, MAX]`. |
|
||||
| `split_audio` | boolean | `null` | Separate files per audio codec. |
|
||||
| `skip_dl` | boolean | `false` | Only fetch keys, do not download. |
|
||||
| `all_drm` | boolean | `false` | License each track with both Widevine and PlayReady. Needs a CDM for each DRM system. Key vaults are read first; `cdm_only: true` sends a challenge for each system. The server refuses it with `cdm`, which selects one device. |
|
||||
| `export` | boolean | `false` | Export manifest/keys/subs to JSON. |
|
||||
| `cdm_only` | boolean | `null` | Force CDM-only (`true`) or vault-only (`false`) key retrieval. With `remote`, `true` licenses every track with the CDM of this server and uses no CDM or vault of the remote server. |
|
||||
| `proxy` / `no_proxy` / `no_proxy_download` / `proxy_download` | string / bool / bool / string | `null` / `false` / `false` / `null` | Proxy controls. `proxy` and `proxy_download` must be full proxy URIs on a public host unless the API key has `server_proxy`. A Control D resolver, `controld://<resolver>@dns.controld.com`, counts as a full proxy URI: the server runs a forwarder for it. |
|
||||
| `no_folder` / `no_source` / `no_mux` | boolean | `false` | Output/mux controls. |
|
||||
| `sample` | boolean/string | `null` | Download a short sample and write it with a `SAMPLE` tag on the filename in a `Sample` folder inside the output folder. `true` is 60 seconds from 2 minutes in; `"0-60"` is a window in seconds. |
|
||||
| `include_sample` | boolean | `false` | Download the full title, then also cut a 60 second sample from each muxed file into a `Sample` folder next to it. |
|
||||
| `workers` | int | `null` | Threads per track. |
|
||||
| `adaptive_workers` | boolean | `false` | Scale segment workers to measured CDN throughput, up to the `workers` cap. |
|
||||
| `download_processes` | int | `1` | Split a track's segments across this many processes. Only engages for large batches. |
|
||||
| `continue_downloads` | boolean | `false` | Keep the completed segment files across runs and resume a download that failed before. |
|
||||
| `downloads` | int | `1` | Concurrent tracks. |
|
||||
| `worst` | boolean | `false` | Pick the lowest-bitrate video at each resolution in `quality`, or at the lowest resolution if `quality` is empty. |
|
||||
| `best_available` | boolean | `false` | Fall back to best available. With `all_drm`, a DRM system that does not license is a warning. |
|
||||
| `generate_dv` | boolean | `false` | With `HYBRID` in `range`, make Dolby Vision from the HDR10+ metadata or the decoded video when a title has no DV track. With `HDR10` or `HDR10P` in `range` and no `HYBRID`, make it for that base and ignore a DV track. With none of the three in `range`, the field has no effect. |
|
||||
| `repack` | boolean | `false` | Add REPACK tag. |
|
||||
| `tag` | string | `null` | Release group tag. |
|
||||
| `tmdb_id` / `imdb_id` / `tvdb_id` / `anilist_id` | - | `null` | External ID overrides. Each resolves its metadata directly instead of by a title search, and is used for tagging. Set `enrich` to also take the title, year and original language. Give at most one of `tmdb_id`, `imdb_id` and `tvdb_id`, since unshackle resolves the others from it. Sending two returns `400`. `anilist_id` still combines with one of them. `tmdb_id` and `tvdb_id` must be positive integers, `imdb_id` must look like `tt1375666`, and `anilist_id` must be a positive integer or a string like `mal:12345`, or the request returns `400`. An ID whose provider is unconfigured, such as `tmdb_id` with no `tmdb_api_key`, returns `400`. `anilist_id` needs no API key. |
|
||||
| `tvdb_order` | `official`, `dvd`, `absolute`, `alternate`, `regional` | `null` | Renumber episodes to a TVDB season order. Falls back to the `tvdb_order` config option. |
|
||||
| `continuous_episodes` | boolean | `false` | Number each season on from the season before it, so season two starts at episode 5 after four episodes. Season 0 and episode 0 keep their numbers. `wanted` selects by the new numbers, but the list endpoints show the numbers of the service. |
|
||||
| `enrich` | boolean | `false` | Overwrite title, year and original language with the external source's. Needs one of `tmdb_id`, `imdb_id`, `tvdb_id` or `anilist_id`. Without one the request returns `400`. |
|
||||
| `daily` | boolean | `false` | Treat the title as daily/date-based content and fill missing episode air dates from TVDB. The fill needs `enrich` and a TVDB ID. An air date the service already set is kept. |
|
||||
| `output_dir` | string | `null` | Output directory, relative to the server's downloads directory. The server rejects a path that resolves outside it with `400`. |
|
||||
| `no_cache` / `reset_cache` | boolean | `false` | Title cache controls. |
|
||||
<!-- 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.
|
||||
|
||||
|
||||
@@ -224,26 +224,11 @@ JOB=$(curl -s -X POST "$BASE/api/download" \
|
||||
| python -c "import sys, json; print(json.load(sys.stdin)['job_id'])")
|
||||
```
|
||||
|
||||
### Frequently used download fields
|
||||
### Download fields
|
||||
|
||||
The request body accepts the full download parameter set. A few of the most useful:
|
||||
The request body takes every `dl` option. The [request body table](endpoints.md#post-apidownload) gives the type, default and meaning of each field.
|
||||
|
||||
| Field | Default | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `service` | - | Service tag (required) |
|
||||
| `title_id` | - | Title identifier (required) |
|
||||
| `profile` | `null` | Named credential/cookie profile to use |
|
||||
| `quality` | `[]` | Resolution(s), e.g. `[1080]`; empty means best available |
|
||||
| `vcodec` | `[]` | Video codec, e.g. `"H265"` |
|
||||
| `acodec` | `[]` | Audio codec, e.g. `"EC3"` |
|
||||
| `range` | `["SDR"]` | Dynamic range: `SDR`, `HDR10`, `HDR10+`, `VIVID`, `DV`, `HLG`, `HYBRID` |
|
||||
| `wanted` | `[]` | Episodes to fetch, e.g. `["S01E01"]`, or music tracks, e.g. `["1-5"]`. Empty means all |
|
||||
| `lang` | `["orig"]` | Video/audio language(s) |
|
||||
| `s_lang` | `["all"]` | Subtitle language(s) |
|
||||
| `downloads` | `1` | Number of tracks to download concurrently |
|
||||
| `proxy` | `null` | Proxy URI or country code |
|
||||
|
||||
Validation is strict: invalid codecs, subtitle formats, dynamic-range names, non-positive counts, or flags that conflict (for example both `no_subs` and `subs_only`) come back as `400` with error code `INVALID_PARAMETERS`. See the full reference on the [download reference page](endpoints.md) for every accepted field.
|
||||
Validation is strict: invalid codecs, subtitle formats, dynamic-range names, non-positive counts, or flags that conflict (for example both `no_subs` and `subs_only`) come back as `400` with error code `INVALID_PARAMETERS`.
|
||||
|
||||
!!! note "Gated fields"
|
||||
The server refuses a per-request CDM (`cdm`) or inline credentials (`credential` / `credentials`) with `403 FORBIDDEN`, unless the server operator has explicitly opted in with `serve.cdm_overrides` and `serve.allow_job_credentials`. Both are off by default.
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""MkDocs hook that renders the POST /api/download request body table from the OpenAPI block in routes.py.
|
||||
|
||||
It reads routes.py with ast and never imports unshackle, because the docs build installs only the docs requirements.
|
||||
"""
|
||||
|
||||
import ast
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
MARKER = "<!-- download-fields -->"
|
||||
PAGE = "dev/rest-api/endpoints.md"
|
||||
ROUTES = Path(__file__).parents[2] / "unshackle/core/api/routes.py"
|
||||
|
||||
|
||||
def request_schema() -> dict[str, Any]:
|
||||
"""The JSON schema of the POST /api/download request body, read from the docstring of ``download`` after its last
|
||||
``---``, as aiohttp_swagger3 reads it."""
|
||||
tree = ast.parse(ROUTES.read_text(encoding="utf-8"))
|
||||
func = next(node for node in tree.body if isinstance(node, ast.AsyncFunctionDef) and node.name == "download")
|
||||
spec = yaml.safe_load(str(ast.get_docstring(func)).rsplit("---", 1)[-1])
|
||||
return spec["requestBody"]["content"]["application/json"]["schema"]
|
||||
|
||||
|
||||
def type_text(schema: dict[str, Any]) -> str:
|
||||
if "oneOf" in schema:
|
||||
return " / ".join(type_text(option) for option in schema["oneOf"])
|
||||
if "enum" in schema:
|
||||
return ", ".join(f"`{value}`" for value in schema["enum"])
|
||||
if schema["type"] == "array":
|
||||
return type_text(schema["items"]) + "[]"
|
||||
return schema["type"] + (f" ≥ {schema['minimum']}" if "minimum" in schema else "")
|
||||
|
||||
|
||||
def render(schema: dict[str, Any]) -> str:
|
||||
rows = ["| Field | Type | Default | Description |", "| --- | --- | --- | --- |"]
|
||||
for name, field in schema["properties"].items():
|
||||
default = "required" if name in schema.get("required", ()) else f"`{json.dumps(field.get('default'))}`"
|
||||
description = " ".join(field.get("description", "").split()).replace("|", "\\|")
|
||||
rows.append(f"| `{name}` | {type_text(field)} | {default} | {description} |")
|
||||
return "\n".join(rows)
|
||||
|
||||
|
||||
def on_page_markdown(markdown: str, page: Any, **kwargs: Any) -> str:
|
||||
if MARKER not in markdown:
|
||||
if page.file.src_uri == PAGE:
|
||||
raise ValueError(f"{PAGE} has no {MARKER} marker for the download request table")
|
||||
return markdown
|
||||
return markdown.replace(MARKER, render(request_schema()))
|
||||
Reference in New Issue
Block a user