File: rewrite.rst

package info (click to toggle)
beets 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,988 kB
  • sloc: python: 46,429; javascript: 8,018; xml: 334; sh: 261; makefile: 125
file content (42 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Rewrite Plugin
==============

The ``rewrite`` plugin lets you easily substitute values in your templates and
path formats. Specifically, it is intended to let you *canonicalize* names such
as artists: for example, perhaps you want albums from The Jimi Hendrix
Experience to be sorted into the same folder as solo Hendrix albums.

To use field rewriting, first enable the ``rewrite`` plugin (see
:ref:`using-plugins`). Then, make a ``rewrite:`` section in your config file to
contain your rewrite rules. Each rule consists of a field name, a regular
expression pattern, and a replacement value. Rules are written ``fieldname
regex: replacement``. For example, this line implements the Jimi Hendrix example
above:

::

    rewrite:
        artist The Jimi Hendrix Experience: Jimi Hendrix

This will make ``$artist`` in your templates expand to "Jimi Hendrix" where it
would otherwise be "The Jimi Hendrix Experience".

The pattern is a case-insensitive regular expression. This means you can use
ordinary regular expression syntax to match multiple artists. For example, you
might use:

::

    rewrite:
        artist .*jimi hendrix.*: Jimi Hendrix

As a convenience, the plugin applies patterns for the ``artist`` field to the
``albumartist`` field as well. (Otherwise, you would probably want to duplicate
every rule for ``artist`` and ``albumartist``.)

A word of warning: This plugin theoretically only applies to templates and path
formats; it initially does not modify files' metadata tags or the values tracked
by beets' library database, but since it *rewrites all field lookups*, it
modifies the file's metadata anyway. See comments in issue :bug:`2786`.

As an alternative to this plugin the :doc:`/plugins/substitute` could be used.