| 1 |
Rewrite Plugin |
| 2 |
============== |
| 3 |
|
| 4 |
The ``rewrite`` plugin lets you easily substitute values in your templates and |
| 5 |
path formats. Specifically, it is intended to let you *canonicalize* names such |
| 6 |
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 |
To use field rewriting, first enable the ``rewrite`` plugin (see |
| 10 |
:ref:`using-plugins`). Then, make a ``rewrite:`` section in your config file to |
| 11 |
contain your rewrite rules. Each rule consists of a field name, a regular |
| 12 |
expression pattern, and a replacement value. Rules are written ``fieldname |
| 13 |
regex: replacement``. For example, this line implements the Jimi Hendrix example |
| 14 |
above: |
| 15 |
|
| 16 |
:: |
| 17 |
|
| 18 |
rewrite: |
| 19 |
artist The Jimi Hendrix Experience: Jimi Hendrix |
| 20 |
|
| 21 |
This will make ``$artist`` in your templates expand to "Jimi Hendrix" where it |
| 22 |
would otherwise be "The Jimi Hendrix Experience". |
| 23 |
|
| 24 |
The pattern is a case-insensitive regular expression. This means you can use |
| 25 |
ordinary regular expression syntax to match multiple artists. For example, you |
| 26 |
might use: |
| 27 |
|
| 28 |
:: |
| 29 |
|
| 30 |
rewrite: |
| 31 |
artist .*jimi hendrix.*: Jimi Hendrix |
| 32 |
|
| 33 |
Rules also apply to matching elements in multi-valued fields. For example, this |
| 34 |
rewrites the ``rock`` entry in ``genres`` while leaving other genre values |
| 35 |
unchanged: |
| 36 |
|
| 37 |
:: |
| 38 |
|
| 39 |
rewrite: |
| 40 |
genres rock: Classic Rock |
| 41 |
|
| 42 |
Rules are applied in the order they appear in the config. This means a |
| 43 |
multi-valued field can have several entries rewritten by different rules: |
| 44 |
|
| 45 |
:: |
| 46 |
|
| 47 |
rewrite: |
| 48 |
genres rock: Classic Rock |
| 49 |
genres pop: Pop |
| 50 |
|
| 51 |
With this configuration, a ``genres`` value such as ``rock; pop; techno`` is |
| 52 |
rewritten to ``Classic Rock; Pop; techno``. |
| 53 |
|
| 54 |
As a convenience, the plugin applies patterns for the ``artist`` field to the |
| 55 |
``albumartist`` field as well. (Otherwise, you would probably want to duplicate |
| 56 |
every rule for ``artist`` and ``albumartist``.) |
| 57 |
|
| 58 |
A word of warning: This plugin theoretically only applies to templates and path |
| 59 |
formats; it initially does not modify files' metadata tags or the values tracked |
| 60 |
by beets' library database, but since it *rewrites all field lookups*, it |
| 61 |
modifies the file's metadata anyway. See comments in issue :bug:`2786`. |
| 62 |
|
| 63 |
As an alternative to this plugin the :doc:`/plugins/substitute` could be used. |