local: Add new library interface to local backend.
This forms the basis of our plugable local libraries that we intend to ship.
This commit is contained in:
parent
8a94d81c42
commit
4c0b54317b
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user