From 4c0b54317bd06c2f8cfd33f9e588cbd1d54f8e0d Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Mon, 23 Dec 2013 22:16:03 +0100 Subject: [PATCH] local: Add new library interface to local backend. This forms the basis of our plugable local libraries that we intend to ship. --- mopidy/backends/local/__init__.py | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index 5caa6826..e0e917f7 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -37,3 +37,78 @@ class Extension(ext.Extension): def get_command(self): from .commands import LocalCommand return LocalCommand() + + +class Library(object): + #: Name of the local library implementation. + name = None + + def __init__(self, config): + self._config = config + + def load(self): + """ + Initialize whatever resources are needed for this library. + + This is where you load the tracks into memory, setup a database + conection etc. + + :rtype: :class:`int` representing number of tracks in library. + """ + return 0 + + def add(self, track): + """ + Add the given track to library. + + :param track: Track to add to the library/ + :type track: :class:`mopidy.models.Track` + """ + raise NotImplementedError + + def remove(self, uri): + """ + Remove the given track from the library. + + :param uri: URI to remove from the library/ + :type uri: string + """ + raise NotImplementedError + + def commit(self): + """ + Persist any changes to the library. + + This is where you write your data file to disk, commit transactions + etc. depending on the requirements of your library implementation. + """ + pass + + def lookup(self, uri): + """ + Lookup the given URI. + + If the URI expands to multiple tracks, the returned list will contain + them all. + + :param uri: track URI + :type uri: string + :rtype: list of :class:`mopidy.models.Track` + """ + raise NotImplementedError + + # TODO: support case with returning all tracks? + # TODO: remove uris? + def search(self, query=None, exact=False, uris=None): + """ + Search the library for tracks where ``field`` contains ``values``. + + :param query: one or more queries to search for + :type query: dict + :param exact: look for exact matches? + :type query: boolean + :param uris: zero or more URI roots to limit the search to + :type uris: list of strings or :class:`None` + :rtype: :class:`mopidy.models.SearchResult` + """ + raise NotImplementedError