core: Add library.list_distinct for getting distinct field values

This commit is contained in:
Thomas Adamcik 2015-03-01 22:46:18 +01:00
parent 0634de6e28
commit 00b2b9538e
3 changed files with 34 additions and 0 deletions

View File

@ -36,6 +36,9 @@ v0.20.0 (UNRELEASED)
- When seeking in paused state, do not change to playing state. (Fixed
:issue:`939`)
- Add :meth:`mopidy.core.LibraryController.list_distinct` for getting unique
values for a given field. (Fixes: :issue:`913`)
**Commands**
- Make the ``mopidy`` command print a friendly error message if the

View File

@ -92,6 +92,16 @@ class LibraryProvider(object):
"""
return []
def list_distinct(self, field, query=None):
"""
See :meth:`mopidy.core.LibraryController.list_distinct`.
*MAY be implemented by subclass.*
Default implementation will simply return an empty set.
"""
return set()
def get_images(self, uris):
"""
See :meth:`mopidy.core.LibraryController.get_images`.

View File

@ -72,6 +72,27 @@ class LibraryController(object):
return []
return backend.library.browse(uri).get()
def list_distinct(self, field, query=None):
"""
List distinct values for a given field from the library.
This has mainly been added to support the list commands the MPD
protocol supports in a more sane fashion. Other frontends are not
recommended to use this method.
:param string field: One of ``artist``, ``albumartist``, ``album``,
``composer``, ``performer``, ``date``or ``genre``.
:param dict query: Query to use for limiting results, see
:method:`search` for details about the query format.
:rtype: set of values corresponding to the requested field type.
"""
futures = [b.library.list_distinct(field, query)
for b in self.backends.with_library.values()]
result = set()
for r in pykka.get_all(futures):
result.update(r)
return result
def get_images(self, uris):
"""Lookup the images for the given URIs