Format strings in gallery-dl follow the general rules of [`str.format()`](https://docs.python.org/3/library/string.html#format-string-syntax) ([PEP 3101](https://www.python.org/dev/peps/pep-3101/)) plus several extras.
The syntax for replacement fields is `{<field-name>!<conversion>:<format-specifiers>}`, where `!<conversion>` and `:<format-specifiers>` are both optional and can be used to specify how the value selected by `<field-name>` should be transformed.
## Field Names
Field names select the metadata value to use in a replacement field.
While simple names are usually enough, more complex forms like accessing values by attribute, element index, or slicing are also supported.
Conversion specifiers allow to *convert* the value to a different form or type. Such a specifier must only consist of 1 character. gallery-dl supports the default three (`s`, `r`, `a`) as well as several others:
<td>Convert value to <ahref="https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str"rel="nofollow"><code>str</code></a></td>
<td><code>{tags!s}</code></td>
<td><code>['sun', 'tree', 'water']</code></td>
</tr>
<tr>
<tdalign="center"><code>S</code></td>
<td>Convert value to <code>str</code> while providing a human-readable representation for lists</td>
<td><code>{tags!S}</code></td>
<td><code>sun, tree, water</code></td>
</tr>
<tr>
<tdalign="center"><code>r</code></td>
<td>Convert value to <code>str</code> using <ahref="https://docs.python.org/3/library/functions.html#repr"rel="nofollow"><code>repr()</code></a></td>
<td></td>
<td></td>
</tr>
<tr>
<tdalign="center"><code>a</code></td>
<td>Convert value to <code>str</code> using <ahref="https://docs.python.org/3/library/functions.html#ascii"rel="nofollow"><code>ascii()</code></a></td>
Format specifiers can be used for advanced formatting by using the options provided by Python (see [Format Specification Mini-Language](https://docs.python.org/3/library/string.html#format-specification-mini-language)) like zero-filling a number (`{num:>03}`) or formatting a [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime) object (`{date:%Y%m%d}`), or with gallery-dl's extra formatting specifiers:
<tdrowspan="2">Adds <code><start></code> and <code><end></code> to the actual value if it evaluates to <code>True</code>. Otherwise the whole replacement field becomes an empty string.</td>
<td>Applies a <ahref="https://python-reference.readthedocs.io/en/latest/docs/brackets/slicing.html">Slicing</a> operation to the current value, similar to <ahref="#field-names">Field Names</a></td>
<td>Same as above, but applies to the <ahref="https://docs.python.org/3/library/stdtypes.html#bytes"><code>bytes()</code></a> representation of a string in <ahref="https://docs.python.org/3/library/sys.html#sys.getfilesystemencoding">filesystem encoding</a></td>
<tdrowspan="2">Replaces the entire output with <code><repl></code> if its length exceeds <code><maxlen></code></td>
<td><code>{foo:L15/long/}</code></td>
<td><code>Foo Bar</code></td>
</tr>
<tr>
<td><code>{foo:L3/long/}</code></td>
<td><code>long</code></td>
</tr>
<tr>
<td><code>J<separator>/</code></td>
<td>Concatenates elements of a list with <code><separator></code> using <ahref="https://docs.python.org/3/library/stdtypes.html#str.join"rel="nofollow"><code>str.join()</code></a></td>
<td><code>{tags:J - /}</code></td>
<td><code>sun - tree - water</code></td>
</tr>
<tr>
<td><code>R<old>/<new>/</code></td>
<td>Replaces all occurrences of <code><old></code> with <code><new></code> using <ahref="https://docs.python.org/3/library/stdtypes.html#str.replace"rel="nofollow"><code>str.replace()</code></a></td>
<td>Sort a list. <code><order></code> can be either <strong>a</strong>scending or <strong>d</strong>escending/<strong>r</strong>everse. (default: <strong>a</strong>)</td>
<td>Parse a string value to a <code>datetime</code> object according to <ahref="https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes"><code><format></code></a></td>
<td>Path to a template file containing a regular format string</td>
<td><code>\fT ~/.templates/booru.txt</code></td>
</tr>
<tr>
<tdalign="center"><code>TF</code></td>
<td>Path to a template file containing an <ahref="https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals">f-string</a> literal</td>