mopidy.local – Local backend

For details on how to use Mopidy’s local backend, see Mopidy-Local.

class mopidy.local.Library(config)[source]

Local library interface.

Extensions that wish to provide an alternate local library storage backend need to sub-class this class and install and configure it with an extension. Both scanning and library calls will use the active local library.

Parameters:config – Config dictionary
ROOT_DIRECTORY_URI = u'local:directory'

URI of the local backend’s root directory.

This constant should be used by libraries implementing the Library.browse() method.

add(track)[source]

Add the given track to library.

Parameters:track (Track) – Track to add to the library
begin()[source]

Prepare library for accepting updates. Exactly what this means is highly implementation depended. This must however return an iterator that generates all tracks in the library for efficient scanning.

Return type:Track iterator
browse(uri)[source]

Browse directories and tracks at the given URI.

The URI for the root directory is a constant available at Library.ROOT_DIRECTORY_URI.

Parameters:path (string) – URI to browse.
Return type:List of Ref tracks and directories.
clear()[source]

Clear out whatever data storage is used by this backend.

Return type:Boolean indicating if state was cleared.
close()[source]

Close any resources used for updating, commit outstanding work etc.

flush()[source]

Called for every n-th track indicating that work should be committed. Sub-classes are free to ignore these hints.

Return type:Boolean indicating if state was flushed.
load()[source]

(Re)load any tracks stored in memory, if any, otherwise just return number of available tracks currently available. Will be called at startup for both library and update use cases, so if you plan to store tracks in memory this is when the should be (re)loaded.

Return type:int representing number of tracks in library.
lookup(uri)[source]

Lookup the given URI.

Unlike the core APIs, local tracks uris can only be resolved to a single track.

Parameters:uri (string) – track URI
Return type:Track
name = None

Name of the local library implementation, must be overriden.

remove(uri)[source]

Remove the given track from the library.

Parameters:uri (str) – URI to remove from the library/
search(query=None, limit=100, offset=0, exact=False, uris=None)[source]

Search the library for tracks where field contains values.

Parameters:
  • query (dict) – one or more queries to search for
  • limit (int) – maximum number of results to return
  • offset (int) – offset into result set to use.
  • exact (bool) – whether to look for exact matches
  • uris (list of strings or None) – zero or more URI roots to limit the search to
Return type:

SearchResult