Skip to content

Commit

Permalink
smartplaylist: Respect sort terms in queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
djl committed Dec 12, 2014
1 parent 165ee80 commit 11c60ce
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions beetsplug/smartplaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,21 @@ def _items_for_query(lib, playlist, album=False):
if key not in playlist:
return []

# Parse quer(ies). If it's a list, join the queries with OR.
# Parse quer(ies). If it's a list, perform the queries and manually
# concatenate the results
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.parse_query_string(q, model)[0] 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)
results = []
for q in query_strings:
querystr, sort = library.parse_query_string(q, model)
if album:
new = lib.albums(querystr, sort)
else:
new = lib.items(querystr, sort)
results.extend(new)
return results


def update_playlists(lib):
Expand Down

0 comments on commit 11c60ce

Please sign in to comment.