mirror of
https://github.com/beetbox/beets.git
synced 2025-12-30 20:42:37 +01:00
Added ability to also include in playlist result from query based on albums (album_query parameter).
This commit is contained in:
parent
1f486fc9b0
commit
05d54b4f23
2 changed files with 38 additions and 16 deletions
|
|
@ -36,13 +36,25 @@ def update_playlists(lib):
|
|||
relative_to = normpath(relative_to)
|
||||
|
||||
for playlist in playlists:
|
||||
# Parse the query. If it's a list, join the queries with OR.
|
||||
query_strings = playlist['query']
|
||||
if not isinstance(query_strings, (list, tuple)):
|
||||
query_strings = [query_strings]
|
||||
items = lib.items(dbcore.OrQuery(
|
||||
[library.get_query(q, library.Item) for q in query_strings]
|
||||
))
|
||||
items = []
|
||||
# Parse album quer(ies). If it's a list, join the queries with OR.
|
||||
if playlist.has_key('album_query'):
|
||||
query_strings = playlist['album_query']
|
||||
if not isinstance(query_strings, (list, tuple)):
|
||||
query_strings = [query_strings]
|
||||
matching_albums = lib.albums(dbcore.OrQuery(
|
||||
[library.get_query(q, library.Album) for q in query_strings]
|
||||
))
|
||||
for album in matching_albums:
|
||||
items.extend(album.items())
|
||||
# Parse item quer(ies). If it's a list, join the queries with OR.
|
||||
if playlist.has_key('query'):
|
||||
query_strings = playlist['query']
|
||||
if not isinstance(query_strings, (list, tuple)):
|
||||
query_strings = [query_strings]
|
||||
items.extend(lib.items(dbcore.OrQuery(
|
||||
[library.get_query(q, library.Item) for q in query_strings]
|
||||
)))
|
||||
|
||||
m3us = {}
|
||||
basename = playlist['name'].encode('utf8')
|
||||
|
|
@ -55,7 +67,8 @@ def update_playlists(lib):
|
|||
item_path = item.path
|
||||
if relative_to:
|
||||
item_path = os.path.relpath(item.path, relative_to)
|
||||
m3us[m3u_name].append(item_path)
|
||||
if not item_path in m3us[m3u_name]:
|
||||
m3us[m3u_name].append(item_path)
|
||||
# Now iterate through the m3us that we need to generate
|
||||
for m3u in m3us:
|
||||
m3u_path = normpath(os.path.join(playlist_dir, m3u))
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ following example::
|
|||
relative_to: ~/Music
|
||||
playlist_dir: ~/.mpd/playlists
|
||||
playlists:
|
||||
- query: ''
|
||||
name: all.m3u
|
||||
- name: all.m3u
|
||||
query: ''
|
||||
|
||||
- query: 'artist:Beatles'
|
||||
name: beatles.m3u
|
||||
- name: beatles.m3u
|
||||
query: 'artist:Beatles'
|
||||
|
||||
If you intend to use this plugin to generate playlists for MPD, you should set
|
||||
``relative_to`` to your MPD music directory (by default, ``relative_to`` is
|
||||
|
|
@ -38,8 +38,8 @@ will be overwritten when the plugin runs.
|
|||
For more advanced usage, you can use template syntax (see
|
||||
:doc:`/reference/pathformat/`) in the ``name`` field. For example::
|
||||
|
||||
- query: 'year::201(0|1)'
|
||||
name: 'ReleasedIn$year.m3u'
|
||||
- name: 'ReleasedIn$year.m3u'
|
||||
query: 'year::201(0|1)'
|
||||
|
||||
This will query all the songs in 2010 and 2011 and generate the two playlist
|
||||
files `ReleasedIn2010.m3u` and `ReleasedIn2011.m3u` using those songs.
|
||||
|
|
@ -47,8 +47,17 @@ files `ReleasedIn2010.m3u` and `ReleasedIn2011.m3u` using those songs.
|
|||
You can also gather the results of several queries by putting them in a list.
|
||||
(Items that match both queries are not included twice.) For example::
|
||||
|
||||
- query: ['artist:beatles', 'genre:"beatles cover"']
|
||||
name: 'BeatlesUniverse.m3u'
|
||||
- name: 'BeatlesUniverse.m3u'
|
||||
query: ['artist:beatles', 'genre:"beatles cover"']
|
||||
|
||||
For querying albums instead of items (mainly useful with extensible fields),
|
||||
use the ``album_query`` field. ``query`` and ``album_query`` can be used at the
|
||||
same time. The following example gathers single items but also items belonging
|
||||
to albums that have a ``for_travel`` extensible field set to 1::
|
||||
|
||||
- name: 'MyTravelPlaylist.m3u'
|
||||
album_query: 'for_travel:1'
|
||||
query: 'for_travel:1'
|
||||
|
||||
By default, all playlists are regenerated after every beets command that
|
||||
changes the library database. To force regeneration, you can invoke it manually
|
||||
|
|
|
|||
Loading…
Reference in a new issue