mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-05 07:25:08 +00:00
324 lines
17 KiB
Markdown
324 lines
17 KiB
Markdown
# Output & Naming Options { #output-naming }
|
||
|
||
Keys that control the output filename, the per-title subfolder, release-group tagging, and
|
||
filename character handling. For how unshackle builds a path, and for worked naming examples, see
|
||
the [Output & naming guide](../../guide/output-and-naming.md).
|
||
|
||
## `output_template`
|
||
|
||
- **Type:** `dict` · **Required** (no usable default; `dl` exits with an error if this is missing)
|
||
|
||
Filename templates keyed by media kind, using `{variable}` placeholders. `dl` stops with
|
||
`No 'output_template' in your unshackle.yaml` when the config key is missing or empty. A trailing `?` on
|
||
a variable (e.g. `{quality?}`) marks it optional: if empty, it and one adjacent separator are
|
||
dropped.
|
||
|
||
| Kind | Applies to | When unset |
|
||
|---|---|---|
|
||
| `movies` | Movies | The title name and year, with spaces: `The Movie (2024)`. |
|
||
| `series` | TV episodes | The show, year, episode number and name, with spaces: `The Show 2024 S01E05 Pilot`. |
|
||
| `sports` | Episodes that the service marks as a sports event | The `series` template. |
|
||
| `songs` | Songs | `"{track_number}. {title}"` |
|
||
| `albums` | Album folders, in `folder` only | The `songs` folder template, then a single-string `folder`, then `"{artist} - {album} ({year})"`, or `"{artist} - {album}"` with no year. |
|
||
|
||
```yaml title="unshackle.yaml"
|
||
output_template:
|
||
movies: "{title}.{year}.{quality?}.{source}-{tag}"
|
||
series: "{title}.{season_episode}.{episode_name?}.{quality?}.{source}-{tag}"
|
||
sports: "{title}.{year?}.{date?}.{episode_name}.{quality?}.{source}-{tag}"
|
||
songs: "{track_number}. {title}"
|
||
folder: # special nested key, see below
|
||
movies: "{title} ({year})"
|
||
series: "{title} ({year})"
|
||
sports: "{title}.{year?}"
|
||
```
|
||
|
||
**The nested `folder` sub-key** controls output subfolders, and unshackle pops it out of
|
||
`output_template`:
|
||
|
||
- A **dict** sets per-kind folder templates (kinds: `movies`, `series`, `sports`, `songs`, `albums`).
|
||
- A **str** sets a single folder template for everything.
|
||
|
||
unshackle validates templates on load and emits warnings for unknown variables, non-string
|
||
values, filesystem-unsafe characters (`< > : " / \ | ? *`), empty templates, and unknown
|
||
folder-kind keys.
|
||
|
||
### Template variables { #template-variables }
|
||
|
||
unshackle takes the values from the downloaded media (through MediaInfo), from the title
|
||
metadata, or from your config. A variable that does not apply to a title becomes an empty
|
||
string. The common and audio variables work in every template. The episode variables belong to
|
||
the `series` and `sports` templates, and the music variables to the `songs` and `albums`
|
||
templates. unshackle warns at startup about such a variable in another template, also in a
|
||
single-string `folder` template, which still fills it in for the titles that have it.
|
||
|
||
**Common and video**
|
||
|
||
| Variable | Meaning | Example |
|
||
|---|---|---|
|
||
| `title` | Title name (movie/show/song name; `$` is rendered as `S`) | `The Show` |
|
||
| `title_type` | Media kind of the title | `movie`, `series`, `music` |
|
||
| `year` | Release year | `2024` |
|
||
| `source` | Service tag / class name (empty with `--no-source`) | `EXAMPLE` |
|
||
| `quality` | Standard resolution with scan suffix | `1080p`, `2160p`, `576i` |
|
||
| `resolution` | Standard resolution number only | `1080` |
|
||
| `video` | Video codec; rename it with [`codec_names`](#codec_names) | `H.264`, `H.265` |
|
||
| `hdr` | Dynamic-range label | `HDR`, `HDR10P`, `DV`, `DV.HDR`, `DV.HDR10P`, `DV.HDRVivid`, `HDRVivid`, `HLG` |
|
||
| `hfr` | High frame rate marker (frame rate > 30) | `HFR` |
|
||
| `3d` | Stereoscopic 3D marker (MV-HEVC video) | `3D` |
|
||
| `edition` | Edition label from the track, if any | `Directors Cut` |
|
||
| `tag` | Release-group tag (from [`tag`](#tagging-naming-keys), [`tag_rules`](#tag_rules) or `--tag`) | `TAG` |
|
||
| `repack` | `REPACK` when the `--repack` flag is used | `REPACK` |
|
||
| `lang_tag` | Result of your [`language_tags`](download.md#language_tags) rules, if configured | `MULTi` |
|
||
|
||
**Audio**
|
||
|
||
| Variable | Meaning | Example |
|
||
|---|---|---|
|
||
| `audio` | Audio codec; rename it with [`codec_names`](#codec_names) | `DDP`, `DD`, `AAC`, `DTS-X` |
|
||
| `audio_channels` | Channel layout; bed.LFE.heights when the track has height channels | `5.1`, `2.0`, `5.1.4` |
|
||
| `audio_full` | Codec + channels combined; a name that ends in a digit gets a separator | `DDP5.1`, `DTS-X.5.1.4`, `AC4.2.0` |
|
||
| `atmos` | `Atmos` when an audio track in the file carries JOC or is marked Atmos, as in the `--list` row (MediaInfo shows no JOC for AC-4) | `Atmos` |
|
||
| `dual` | `DUAL` for two audio languages (see [`dual_multi_mode`](download.md#dual_multi_mode)) | `DUAL` |
|
||
| `multi` | `MULTi` for more than two audio languages | `MULTi` |
|
||
| `dubbed` | `DUBBED` for a single audio language that is not the original (strict mode only) | `DUBBED` |
|
||
|
||
**Episode** (`series` and `sports` templates)
|
||
|
||
| Variable | Meaning | Example |
|
||
|---|---|---|
|
||
| `season` | Zero-padded season (`S%02d`) | `S01` |
|
||
| `episode` | Zero-padded episode (`E%02d`) | `E05` |
|
||
| `season_episode` | Combined | `S01E05` |
|
||
| `episode_name` | Episode title | `Pilot` |
|
||
| `part` | Part index of a [split episode](../../guide/output-and-naming.md#split-episodes), empty otherwise | `2` |
|
||
| `absolute` | Absolute episode number, zero-padded to 3 digits, empty when unknown | `007` |
|
||
| `date` | ISO air date, empty when the episode has none | `2024-06-01` |
|
||
|
||
When an episode has an air date, `season` and `season_episode` become the formatted air date,
|
||
unshackle clears `episode` and `year`, and `{date}` holds the ISO date. The separator inside
|
||
the date follows the style of the template. A `sports` template differs: `{date}` holds the
|
||
air date in the separator style of the template (`2026.11.01`), and `{year}` is empty when the
|
||
event has an air date. See [Sports events](../../guide/output-and-naming.md#sports-events).
|
||
|
||
**Music** (`songs` and `albums` templates)
|
||
|
||
| Variable | Meaning |
|
||
|---|---|
|
||
| `track_number` | Zero-padded track number |
|
||
| `artist` / `album_artist` | Artist / album artist (falls back to artist) |
|
||
| `album` | Album name |
|
||
| `disc` | Disc number (only shown when greater than 1) |
|
||
| `track_total` / `disc_total` | Totals |
|
||
| `release_type` | `album`, `single`, `ep`, or another type the service supplies |
|
||
| `genre` | Genre |
|
||
| `explicit` | `Explicit` when flagged |
|
||
| `isrc` / `upc` / `label` | ISRC, UPC and record label |
|
||
|
||
!!! note "`quality` and `resolution` use the standard height"
|
||
unshackle names a video by the nearest standard height (4320, 2160, 1440, 1080, 720, 576, 540,
|
||
480, 360 or 240) when it is within 10%. It measures the short side and the height that a 16:9
|
||
picture of the same width has, and uses the larger one. So a cropped 1920x800, a padded
|
||
1920x1088 and a 1080x1920 portrait video are all `1080p`. A short side within 16 lines of
|
||
2160, 1440 or 1080 gives that height, so an ultrawide 2560x1080 is `1080p`. A size with no
|
||
standard height near it, such as 1600x900, keeps its own height. `dl -q` and the
|
||
`dl --export` file name use the same rule.
|
||
|
||
!!! warning "An unknown variable stops the naming"
|
||
unshackle warns at startup about a variable that is not in the tables above, and continues.
|
||
When it names a file, a required variable (no `?`) that the title does not have, such as a
|
||
typo like `{quailty}` or `{season}` in a `movies` template, stops the title with
|
||
`Missing required template variables`. An optional `{quailty?}` is removed.
|
||
|
||
!!! warning "`{part?}` is already inside `{season_episode}`"
|
||
`part` holds the bare part index of a
|
||
[split episode](../../guide/output-and-naming.md#split-episodes) (`2`) and is empty on
|
||
every other title. unshackle folds it into `{episode}` and `{season_episode}`, so the
|
||
shipped `series` template names split episodes correctly with no edit. Putting
|
||
`{part?}` next to either of them renders the part twice (`S01E01.Part.2.2`). Use the
|
||
standalone variable only in a template that names neither `{episode}` nor
|
||
`{season_episode}`, and note that it is always empty in a folder template, since
|
||
folders do not carry the part.
|
||
|
||
!!! tip "`{absolute}` counts episodes across seasons"
|
||
`absolute` holds the absolute episode number, zero-padded to 3 digits (`007`), and is
|
||
empty on titles that have none. You add it to the name yourself, and it never replaces `{season}`
|
||
or `{episode}`. Any series with a TVDB absolute order can use it, anime most often.
|
||
Services can supply it, and
|
||
[`--enrich`](../../guide/downloading.md#metadata-and-tagging) fills it in from TVDB.
|
||
Use `{absolute?}` so the name stays clean when it is unknown. To keep the season and
|
||
continue the episode number instead (`S02E05`), use
|
||
[`--continuous-episodes`](../../guide/downloading.md#continuous-episode-numbers).
|
||
|
||
!!! tip "`sports` names an event by year or date"
|
||
A service marks an event episode as sport, and that episode then uses the `sports`
|
||
templates. Without them it uses the `series` templates. For the variables and
|
||
examples, see [Sports events](../../guide/output-and-naming.md#sports-events).
|
||
|
||
## Tagging & naming keys
|
||
|
||
| Key | Type | Default | Description |
|
||
|-----|------|---------|-------------|
|
||
| `tag` | str | `""` | Release-group tag. Fills the `{tag}` template variable and is written into MKV/audio tags. |
|
||
| `tag_group_name` | bool | `true` | Include the group name (`tag`) in the MKV `Group` tag. |
|
||
| `tag_imdb_tmdb` | bool | `true` | Write IMDb/TMDB/TVDB external-ID tags into the MKV (needs metadata providers). |
|
||
| `chapter_fallback_name` | str | `""` | The name of a chapter that has no name, as a template, e.g. `"Chapter {i:02}"`. `{i}` is the chapter number, from 1; `{j}` counts only the chapters without a name. Format directives such as `{i:02}` work. |
|
||
| `unicode_filenames` | bool | `false` | `false` transliterates non-ASCII characters to ASCII and removes accents. `true` keeps the native characters in file and folder names, with the vowel and tone marks of languages such as Thai, Hindi and Bengali. With each value, unshackle first normalises the name to Unicode NFC. |
|
||
| [`filename_replacements`](#filename_replacements) | dict | `{}` | Replace text in file and folder names, e.g. `&` with `and`. |
|
||
|
||
## `codec_names`
|
||
|
||
- **Type:** `dict` · **Default:** `{}`
|
||
|
||
Renames the codec and HDR names in the filename. Each map key is a name that unshackle writes by
|
||
default, and its value is the name to write instead. The map applies to the `video`, `audio`,
|
||
and `hdr` [template variables](#template-variables), and so
|
||
also to `audio_full`. A name that is not in the map stays as it is, and an empty value removes
|
||
the name. You can also set `codec_names` for one service under `services`.
|
||
|
||
```yaml title="unshackle.yaml"
|
||
codec_names:
|
||
DDP: EAC3 # DDP5.1 -> EAC3.5.1
|
||
DD: AC3 # DD5.1 -> AC3.5.1
|
||
H.265: HEVC # H.265 -> HEVC
|
||
HDR10P: HDR10+ # DV.HDR10P -> DV.HDR10+
|
||
```
|
||
|
||
For `hdr`, unshackle renames each part of a Dolby Vision label separately, so `HDR10P` also
|
||
changes `DV.HDR10P` to `DV.HDR10+`. When an audio name ends in a digit, `audio_full` puts a
|
||
separator before the channels: `EAC3.5.1`, not `EAC35.1`.
|
||
|
||
The REST API fields `codec_display` and `range_display` use the same names and the same map.
|
||
The `dl --export` file name does not use `codec_names`.
|
||
|
||
!!! note "`tag_rules` see the new names"
|
||
unshackle evaluates [`tag_rules`](#tag_rules) after the rename. With the example above, a
|
||
rule must match `audio: EAC3`, not `audio: DDP`.
|
||
|
||
## `filename_replacements`
|
||
|
||
- **Type:** `dict` · **Default:** `{}`
|
||
|
||
Replaces text in file and folder names. Each entry of the map names the text to find, and its
|
||
value is the text to write instead. An empty value removes the text. unshackle applies the map
|
||
in order, before it sanitises the name, so a later entry also sees the result of an earlier
|
||
entry. You can also set `filename_replacements` for one service under `services`.
|
||
|
||
```yaml title="unshackle.yaml"
|
||
filename_replacements:
|
||
"&": and # Tom & Jerry -> Tom.and.Jerry, Tom&Jerry -> Tom.and.Jerry
|
||
```
|
||
|
||
Put quotes around text such as `"&"`: YAML reads a bare `&` as an anchor. When the text to
|
||
find has no letters or digits and the replacement is a word, unshackle puts a separator on each
|
||
side of the replacement, so `Tom&Jerry` gives `Tom.and.Jerry`. The map also changes text
|
||
inside a word: `AT&T` gives `AT.and.T`. An entry that does not map text to text stops
|
||
unshackle at startup with an error.
|
||
|
||
The map applies to the whole name that a template makes, and also to the title part of the
|
||
`dl --export` file name. Find only text that titles contain: an entry for `-` also changes
|
||
`WEB-DL` and the `-{tag}` separator. The ` & ` that unshackle writes for `/` and `;` in a
|
||
multi-episode name stays as it is, unless the map has an entry for `/` or `;`.
|
||
|
||
unshackle finds the text before it transliterates the name to ASCII. For a title that uses a
|
||
variant of a character, such as the fullwidth `&`, add an entry for that variant too.
|
||
|
||
## `tag_rules`
|
||
|
||
- **Type:** `list` · **Default:** `[]`
|
||
|
||
Conditionally replaces [`tag`](#tagging-naming-keys) for a given download. Each rule pairs a `when`
|
||
dict of conditions with the `tag` to use when they hold. unshackle evaluates the rules in
|
||
order and the first match wins. If no rule matches, the global `tag` stays.
|
||
|
||
```yaml title="unshackle.yaml"
|
||
tag_rules:
|
||
- when: { title_type: movie, lang_tag: SUBBED }
|
||
tag: SUBMOVIES
|
||
- when: { quality: 2160p, hdr: [DV, DV.HDR, DV.HDR10P, HDR, HDR10P] }
|
||
tag: UHDGROUP
|
||
```
|
||
|
||
Rule semantics:
|
||
|
||
- Every condition in `when` must hold (they are AND-ed).
|
||
- A value can be a scalar or a list. A list matches if **any** entry matches.
|
||
- Comparison is case-insensitive string equality.
|
||
- The keys of `when` are the filename template variables for the release itself:
|
||
`title_type`, `quality`, `resolution`, `source`, `video`, `hdr`, `hfr`, `3d`, `audio`,
|
||
`audio_channels`, `audio_full`, `atmos`, `dual`, `multi`, `dubbed`, `edition`, `repack`,
|
||
and `lang_tag`. Only these are available. unshackle adds the title's own fields (`title`,
|
||
`year`, `season`, `episode`, and so on) after it evaluates the rules, so a condition cannot
|
||
use them.
|
||
- An unknown key in `when` is a mistake: unshackle logs a warning that names the key
|
||
and skips that rule. unshackle also warns about a rule without conditions or without a `tag`, and skips it.
|
||
|
||
Put the more specific rules first, because unshackle stops at the first match.
|
||
|
||
!!! warning "Match `hdr` on the exact value"
|
||
Matching is exact, and `hdr` is a composite label for Dolby Vision titles: a DV title with
|
||
an HDR10 base layer gives `DV.HDR`, with an HDR10+ base layer `DV.HDR10P`, and with an HDR Vivid base
|
||
layer `DV.HDRVivid`. Plain `DV` does **not** match those. Name every variant you want, as the example above does. Note
|
||
also that HDR10 gives `HDR`, not `HDR10`, and so does a PQ video track with no HDR10
|
||
metadata. The full set of values is `HDR`, `HDR10P`, `DV`, `DV.HDR`, `DV.HDR10P`,
|
||
`DV.HDRVivid`, `HDRVivid`, and `HLG`, as listed in the
|
||
[variable table](#template-variables).
|
||
|
||
### Operators
|
||
|
||
A condition value can start with a comparison operator, which unshackle applies to the rest of
|
||
the value:
|
||
|
||
```yaml title="unshackle.yaml"
|
||
tag_rules:
|
||
- when: { resolution: "<1080" }
|
||
tag: SDGROUP
|
||
- when: { quality: ">=2160" }
|
||
tag: UHDGROUP
|
||
- when: { video: "!=H.265" }
|
||
tag: AVCGROUP
|
||
```
|
||
|
||
- `>`, `<`, `>=`, `<=` compare numbers. unshackle reads the first number out of the actual
|
||
value, so `">=2160"` matches a quality of `2160p`. If the actual value has no number, the
|
||
condition fails.
|
||
- `=`, `==`, and `!=` compare text, case-insensitively, when the operand is not a number.
|
||
With a numeric operand they compare numbers like the operators above. A value with no number
|
||
in it is never equal to a number, so `"!=2160"` holds for it and `"==2160"` does not.
|
||
- An ordering operator with a text operand (for example `">DV"`) is a mistake: unshackle logs
|
||
a warning and the condition fails. So does an operator with nothing after it (`">="`).
|
||
- A value with no operator keeps the plain equality behaviour described above.
|
||
|
||
!!! warning "Quote operator values in YAML"
|
||
Two of these operators break an unquoted YAML value, and both stop the config from
|
||
loading:
|
||
|
||
- `>` opens a folded block scalar, so `quality: >=2160` fails with a "while scanning a
|
||
block scalar" error.
|
||
- `!` starts a tag, so `hdr: !=DV` fails with a "could not determine a constructor"
|
||
error.
|
||
|
||
Quote every operator value: `quality: ">=2160"`, `resolution: "<1080"`, `video: "!=H.265"`.
|
||
|
||
!!! note "Keep a negation out of lists"
|
||
A list matches if any entry matches, so two or more `!=` entries in one list are always
|
||
true. Give a negation as a single value, not as a list entry.
|
||
|
||
`title_type` is the media kind of the title: `movie`, `series`, or `music`. It is useful to
|
||
give each kind its own group:
|
||
|
||
```yaml
|
||
tag_rules:
|
||
- when: { title_type: movie }
|
||
tag: MOVIEGRP
|
||
- when: { title_type: series }
|
||
tag: TVGRP
|
||
```
|
||
|
||
The resolved tag applies to the `{tag}` filename variable only. The `Group` metadata tag
|
||
written into MKV and music files always uses [`tag`](#tagging-naming-keys).
|
||
|
||
!!! note "`--tag` wins"
|
||
An explicit `dl --tag` on the command line disables the rules completely and uses the
|
||
given tag.
|