Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smartplaylist: Respect sort terms in queries. #1138

Merged
merged 2 commits into from
Dec 12, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions beetsplug/smartplaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from beets.plugins import BeetsPlugin
from beets import config, ui, library
from beets import dbcore
from beets.util import normpath, syspath
import os

Expand All @@ -36,23 +35,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