Plugin play uses default item sort in album mode

Offer library.get_default_{item,album}_sort for that purpose.
This commit is contained in:
Bruno Cauet 2015-02-16 12:19:05 +01:00
parent c47221555f
commit 39a6145d2d
3 changed files with 21 additions and 14 deletions

View file

@ -1188,21 +1188,27 @@ class Library(dbcore.Database):
model_cls, query, sort
)
def get_default_album_sort(self):
"""Get a :class:`Sort` object for albums from the config option.
"""
return dbcore.sort_from_strings(
Album, beets.config['sort_album'].as_str_seq())
def get_default_item_sort(self):
"""Get a :class:`Sort` object for items from the config option.
"""
return dbcore.sort_from_strings(
Item, beets.config['sort_item'].as_str_seq())
def albums(self, query=None, sort=None):
"""Get :class:`Album` objects matching the query.
"""
sort = sort or dbcore.sort_from_strings(
Album, beets.config['sort_album'].as_str_seq()
)
return self._fetch(Album, query, sort)
return self._fetch(Album, query, sort or self.get_default_album_sort())
def items(self, query=None, sort=None):
"""Get :class:`Item` objects matching the query.
"""
sort = sort or dbcore.sort_from_strings(
Item, beets.config['sort_item'].as_str_seq()
)
return self._fetch(Item, query, sort)
return self._fetch(Item, query, sort or self.get_default_item_sort())
# Convenience accessors.

View file

@ -60,23 +60,22 @@ class PlayPlugin(BeetsPlugin):
if relative_to:
relative_to = util.normpath(relative_to)
# Preform search by album and add folders rather than tracks to
# Perform search by album and add folders rather than tracks to
# playlist.
if opts.album:
selection = lib.albums(ui.decargs(args))
paths = []
sort = lib.get_default_album_sort()
for album in selection:
if use_folders:
paths.append(album.item_dir())
else:
# TODO use core's sorting functionality
paths.extend([item.path for item in sorted(
album.items(),
key=lambda item: (item.disc, item.track))])
paths.extend(item.path
for item in sort.sort(album.items()))
item_type = 'album'
# Preform item query and add tracks to playlist.
# Perform item query and add tracks to playlist.
else:
selection = lib.items(ui.decargs(args))
paths = [item.path for item in selection]

View file

@ -6,6 +6,8 @@ Changelog
Features:
* :doc:`/plugins/play` will sort items according to the configured option when
used in album mode.
* :doc:`/plugins/play` gives full interaction with the command invoked.
:bug:`1321`
* The summary shown to compare duplicate albums during import now displays