changelog & style tweaks for album_query (#595)

This commit is contained in:
Adrian Sampson 2014-03-09 13:22:34 -07:00
parent aa01906761
commit fb038ecc30
2 changed files with 29 additions and 22 deletions

View file

@ -27,27 +27,33 @@ import os
database_changed = False
def query_from_parameter(lib, playlist, parameter, album=False):
if playlist.has_key(parameter):
# Parse quer(ies). If it's a list, join the queries with OR.
query_strings = playlist[parameter]
if not isinstance(query_strings, (list, tuple)):
query_strings = [query_strings]
model = library.Album if album else library.Item
query = dbcore.OrQuery(
[library.get_query(q, model) for q in query_strings]
)
# Execute query, depending on type
if album:
result = []
for album in lib.albums(query):
result.extend(album.items())
return result
else:
return lib.items(query)
else:
def _items_for_query(lib, playlist, album=False):
"""Get the matching items for a playlist's configured queries.
`album` indicates whether to process the item-level query or the
album-level query (if any).
"""
key = 'album_query' if album else 'query'
if key not in playlist:
return []
# Parse quer(ies). If it's a list, join the queries with OR.
query_strings = playlist[key]
if not isinstance(query_strings, (list, tuple)):
query_strings = [query_strings]
model = library.Album if album else library.Item
query = dbcore.OrQuery(
[library.get_query(q, model) for q in query_strings]
)
# Execute query, depending on type.
if album:
result = []
for album in lib.albums(query):
result.extend(album.items())
return result
else:
return lib.items(query)
def update_playlists(lib):
ui.print_("Updating smart playlists...")
@ -59,8 +65,8 @@ def update_playlists(lib):
for playlist in playlists:
items = []
items.extend(query_from_parameter(lib, playlist, 'album_query', True))
items.extend(query_from_parameter(lib, playlist, 'query', False))
items.extend(_items_for_query(lib, playlist, True))
items.extend(_items_for_query(lib, playlist, False))
m3us = {}
basename = playlist['name'].encode('utf8')

View file

@ -20,7 +20,8 @@ New stuff:
* The importer interface now shows the URL for MusicBrainz matches. Thanks to
johtso.
* :doc:`/plugins/smartplaylist`: Playlists can now be generated from multiple
queries (combined with "or" logic). Thanks to brilnius.
queries (combined with "or" logic). Album-level queries are also now
possible. Thanks to brilnius.
* :doc:`/plugins/echonest`: Echo Nest similarity now weights the tempo in
better proportion to other metrics. Also, options were added to specify
custom thresholds and output formats. Thanks to Adam M.