mirror of
https://github.com/beetbox/beets.git
synced 2025-12-09 10:05:35 +01:00
Merge branch 'spl_multi_query' of https://github.com/brilnius/beets into brilnius-spl_multi_query
This commit is contained in:
commit
f9b9ab5db8
2 changed files with 25 additions and 4 deletions
|
|
@ -35,7 +35,18 @@ def update_playlists(lib):
|
|||
relative_to = normpath(relative_to)
|
||||
|
||||
for playlist in playlists:
|
||||
items = lib.items(library.get_query(playlist['query'], library.Item))
|
||||
# Default is to not keep_duplicate
|
||||
keep_duplicate = playlist.has_key('keep_duplicate') and \
|
||||
playlist['keep_duplicate']
|
||||
|
||||
# Query attribute could be a single query or a list of queries
|
||||
queries = playlist['query']
|
||||
if not isinstance(queries, (list, tuple)):
|
||||
queries = [queries]
|
||||
items = []
|
||||
for query in queries:
|
||||
items.extend(lib.items(library.get_query(query, library.Item)))
|
||||
|
||||
m3us = {}
|
||||
basename = playlist['name'].encode('utf8')
|
||||
# As we allow tags in the m3u names, we'll need to iterate through
|
||||
|
|
@ -44,10 +55,12 @@ def update_playlists(lib):
|
|||
m3u_name = item.evaluate_template(basename, True)
|
||||
if not (m3u_name in m3us):
|
||||
m3us[m3u_name] = []
|
||||
item_path = item.path
|
||||
if relative_to:
|
||||
m3us[m3u_name].append(os.path.relpath(item.path, relative_to))
|
||||
else:
|
||||
m3us[m3u_name].append(item.path)
|
||||
item_path = os.path.relpath(item.path, relative_to)
|
||||
# Check if we want to add the item.
|
||||
if keep_duplicate or 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))
|
||||
|
|
|
|||
|
|
@ -44,6 +44,14 @@ For more advanced usage, you can use template syntax (see
|
|||
This will query all the songs in 2010 and 2011 and generate the two playlist
|
||||
files `ReleasedIn2010.m3u` and `ReleasedIn2011.m3u` using those songs.
|
||||
|
||||
You can also gather the results of several queries by putting them in a list. By
|
||||
default duplicates are removed, but you can keep all of them with the
|
||||
``keep_duplicate: yes`` additional directive. For example::
|
||||
|
||||
- query: ['artist:beatles', 'genre:"beatles cover"']
|
||||
name: 'BeatlesUniverse.m3u'
|
||||
keep_duplicate: yes
|
||||
|
||||
By default, all playlists are regenerated after every beets command that
|
||||
changes the library database. To force regeneration, you can invoke it manually
|
||||
from the command line::
|
||||
|
|
|
|||
Loading…
Reference in a new issue