| 1 |
Substitute Plugin |
| 2 |
================= |
| 3 |
|
| 4 |
The ``substitute`` plugin lets you easily substitute values in your templates |
| 5 |
and path formats. Specifically, it is intended to let you *canonicalize* names |
| 6 |
such as artists: For example, perhaps you want albums from The Jimi Hendrix |
| 7 |
Experience to be sorted into the same folder as solo Hendrix albums. |
| 8 |
|
| 9 |
This plugin is intended as a replacement for the ``rewrite`` plugin. While the |
| 10 |
``rewrite`` plugin modifies the metadata, this plugin does not. |
| 11 |
|
| 12 |
Enable the ``substitute`` plugin (see :ref:`using-plugins`), then make a |
| 13 |
``substitute:`` section in your config file to contain your rules. Each rule |
| 14 |
consists of a case-insensitive regular expression pattern, and a replacement |
| 15 |
string. For example, you might use: |
| 16 |
|
| 17 |
.. code-block:: yaml |
| 18 |
|
| 19 |
substitute: |
| 20 |
.*jimi hendrix.*: Jimi Hendrix |
| 21 |
|
| 22 |
The replacement can be an expression utilising the matched regex, allowing us to |
| 23 |
create more general rules. Say for example, we want to sort all albums by |
| 24 |
multiple artists into the directory of the first artist. We can thus capture |
| 25 |
everything before the first ``,``, ``&`` or ``and``, and use this capture group |
| 26 |
in the output, discarding the rest of the string. |
| 27 |
|
| 28 |
.. code-block:: yaml |
| 29 |
|
| 30 |
substitute: |
| 31 |
^(.*?)(,| &| and).*: \1 |
| 32 |
|
| 33 |
This would handle all the below cases in a single rule: |
| 34 |
|
| 35 |
| Bob Dylan and The Band -> Bob Dylan |
| 36 |
| Neil Young & Crazy Horse -> Neil Young |
| 37 |
| James Yorkston, Nina Persson & The Second Hand Orchestra -> James |
| 38 |
Yorkston |
| 39 |
|
| 40 |
To apply the substitution, you have to call the function ``%substitute{}`` in |
| 41 |
the paths section. For example: |
| 42 |
|
| 43 |
.. code-block:: yaml |
| 44 |
|
| 45 |
paths: |
| 46 |
default: \%substitute{$albumartist}/$year - $album\%aunique{}/$track - $title |