diff --git a/beets/library.py b/beets/library.py index 8d95561f7..c05206dea 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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. diff --git a/beetsplug/play.py b/beetsplug/play.py index db3348210..8a912505c 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -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] diff --git a/docs/changelog.rst b/docs/changelog.rst index d68b92812..d65d1e416 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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