Debian Codegraph @

docs/plugins/smartplaylist.rst

raw
1 Smart Playlist Plugin
2 =====================
3
4 ``smartplaylist`` is a plugin to generate smart playlists in m3u format based on
5 beets queries every time your library changes. This plugin is specifically
6 created to work well with `MPD's`_ playlist functionality.
7
8 .. _mpd's: https://www.musicpd.org/
9
10 To use it, enable the ``smartplaylist`` plugin in your configuration (see
11 :ref:`using-plugins`). Then configure your smart playlists like the following
12 example:
13
14 ::
15
16 smartplaylist:
17 relative_to: ~/Music
18 playlist_dir: ~/.mpd/playlists
19 forward_slash: no
20 playlists:
21 - name: all.m3u
22 query: ''
23
24 - name: beatles.m3u
25 query: 'artist:Beatles'
26
27 You can generate as many playlists as you want by adding them to the
28 ``playlists`` section, using beets query syntax (see :doc:`/reference/query`)
29 for ``query`` and the file name to be generated for ``name``. The query will be
30 split using shell-like syntax, so if you need to use spaces in the query, be
31 sure to quote them (e.g., ``artist:"The Beatles"``). If you have existing files
32 with the same names, you should back them up---they will be overwritten when the
33 plugin runs.
34
35 For more advanced usage, you can use template syntax (see
36 :doc:`/reference/pathformat/`) in the ``name`` field. For example:
37
38 ::
39
40 - name: 'ReleasedIn$year.m3u'
41 query: 'year::201(0|1)'
42
43 This will query all the songs in 2010 and 2011 and generate the two playlist
44 files ``ReleasedIn2010.m3u`` and ``ReleasedIn2011.m3u`` using those songs.
45
46 You can also gather the results of several queries by putting them in a list.
47 (Items that match both queries are not included twice.) For example:
48
49 ::
50
51 - name: 'BeatlesUniverse.m3u'
52 query: ['artist:beatles', 'genre:"beatles cover"']
53
54 Note that since beets query syntax is in effect, you can also use sorting
55 directives:
56
57 ::
58
59 - name: 'Chronological Beatles'
60 query: 'artist:Beatles year+'
61 - name: 'Mixed Rock'
62 query: ['artist:Beatles year+', 'artist:"Led Zeppelin" bitrate+']
63
64 The former case behaves as expected, however please note that in the latter the
65 sorts will be merged: ``year+ bitrate+`` will apply to both the Beatles and Led
66 Zeppelin. If that bothers you, please get in touch.
67
68 For querying albums instead of items (mainly useful with extensible fields), use
69 the ``album_query`` field. ``query`` and ``album_query`` can be used at the same
70 time. The following example gathers single items but also items belonging to
71 albums that have a ``for_travel`` extensible field set to 1:
72
73 ::
74
75 - name: 'MyTravelPlaylist.m3u'
76 album_query: 'for_travel:1'
77 query: 'for_travel:1'
78
79 By default, each playlist is automatically regenerated at the end of the session
80 if an item or album it matches changed in the library database. To force
81 regeneration, you can invoke it manually from the command line:
82
83 ::
84
85 $ beet splupdate
86
87 This will regenerate all smart playlists. You can also specify which ones you
88 want to regenerate:
89
90 ::
91
92 $ beet splupdate BeatlesUniverse.m3u MyTravelPlaylist
93
94 You can also use this plugin together with the :doc:`mpdupdate`, in order to
95 automatically notify MPD of the playlist change, by adding ``mpdupdate`` to the
96 ``plugins`` line in your config file *after* the ``smartplaylist`` plugin.
97
98 Plugin Event
99 ------------
100
101 After writing updated playlist files, this plugin sends the
102 ``smartplaylist_update`` event. See :ref:`plugin_events` for its listener
103 parameters. The event is not sent in pretend mode.
104
105 While working on smart playlist queries in the beets configuration it can help
106 to use the ``--pretend`` option to find out if the edits work as expected before
107 writing changes. To list the tracks matching the query, switch to the DEBUG log
108 level.
109
110 ::
111
112 $ beet -v splupdate --pretend BeatlesUniverse.m3u
113
114 The ``format`` configuration option defaults to ``$artist - $title``, and can be
115 set up to a custom format string.
116
117 In case you want to export additional fields from the beets database into the
118 generated playlists, you can do so by specifying them within the ``fields``
119 configuration option and setting the ``output`` option to ``extm3u``. For
120 instance the following configuration exports the ``id`` and ``genre`` fields:
121
122 ::
123
124 smartplaylist:
125 playlist_dir: /data/playlists
126 relative_to: /data/playlists
127 output: extm3u
128 fields:
129 - id
130 - genres
131 playlists:
132 - name: all.m3u
133 query: ''
134
135 Values of additional fields are URL-encoded. A resulting ``all.m3u`` file could
136 look as follows:
137
138 ::
139
140 #EXTM3U
141 #EXTINF:805 id="1931" genres="Rock%3B%20Pop",Led Zeppelin - Stairway to Heaven
142 ../music/singles/Led Zeppelin/Stairway to Heaven.mp3
143
144 To give a usage example, the webm3u_ and Beetstream_ plugins read the exported
145 ``id`` field, allowing you to serve your local m3u playlists via HTTP.
146
147 .. _beetstream: https://github.com/BinaryBrain/Beetstream
148
149 .. _webm3u: https://github.com/mgoltzsche/beets-webm3u
150
151 Configuration
152 -------------
153
154 To configure the plugin, make a ``smartplaylist:`` section in your configuration
155 file. In addition to the ``playlists`` described above, the other configuration
156 options are:
157
158 - **auto**: Regenerate the playlist after every database change. Default:
159 ``yes``.
160 - **playlist_dir**: Where to put the generated playlist files. Default: The
161 current working directory (i.e., ``'.'``).
162 - **dest_regen**: Regenerate the destination path as ``move`` or ``convert``
163 commands would do. This operation will happen before ``relative_to`` and
164 ``prefix``. Helpful to generate playlists compatible with the ``convert``
165 plugin when items have been imported with the ``-C -M`` options. Default:
166 ``false``.
167 - **relative_to**: Generate paths in the playlist files relative to a base
168 directory. If you intend to use this plugin to generate playlists for MPD,
169 point this to your MPD music directory. Default: Use absolute paths.
170 - **forward_slash**: Forces forward slashes in the generated playlist files. If
171 you intend to use this plugin to generate playlists for MPD on Windows, set
172 this to yes. Default: Use system separator.
173 - **prefix**: Prepend this string to every path in the playlist file. For
174 example, you could use the URL for a server where the music is stored.
175 Default: empty string.
176 - **urlencode**: URL-encode all paths. Default: ``no``.
177 - **uri_format**: Template with an ``$id`` placeholder used generate a playlist
178 item URI, e.g. ``http://beets:8337/item/$id/file``. When this option is
179 specified, the local path-related options ``dest_regen``, ``prefix``,
180 ``relative_to``, ``forward_slash`` and ``urlencode`` are ignored.
181 - **output**: Specify the playlist format: m3u|extm3u. Default ``m3u``.
182 - **fields**: Specify the names of the additional item fields to export into the
183 playlist. This allows using e.g. the ``id`` field within other tools such as
184 the webm3u_ and Beetstream_ plugins. To use this option, you must set the
185 ``output`` option to ``extm3u``.
186 - **format**: Specify the format a playlist item is logged in ``DEBUG`` level.
187 Default: ``$artist - $title``.
188
189 For many configuration options, there is a corresponding CLI option, e.g.
190 ``--playlist-dir``, ``--dest-regen``, ``--relative-to``, ``--prefix``,
191 ``--forward-slash``, ``--urlencode``, ``--uri-format``, ``--output``,
192 ``--format``. CLI options take precedence over those specified within the
193 configuration file.