File: backend.rst

package info (click to toggle)
mopidy 3.4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,616 kB
  • sloc: python: 16,656; sh: 159; makefile: 126
file content (104 lines) | stat: -rw-r--r-- 3,848 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
.. _backend-api:

*************************************
:mod:`mopidy.backend` --- Backend API
*************************************

.. module:: mopidy.backend
    :synopsis: The API implemented by backends

The backend API is the interface that must be implemented when you create a
backend. If you are working on a frontend and need to access the backends, see
the :ref:`core-api` instead.


URIs and routing of requests to the backend
===========================================

When Mopidy's core layer is processing a client request, it routes the request
to one or more appropriate backends based on the URIs of the objects the
request touches on. The objects' URIs are compared with the backends'
:attr:`~mopidy.backend.Backend.uri_schemes` to select the relevant backends.

An often used pattern when implementing Mopidy backends is to create your own
URI scheme which you use for all tracks, playlists, etc. related to your
backend. In most cases the Mopidy URI is translated to an actual URI that
GStreamer knows how to play right before playback. For example:

- Spotify already has its own URI scheme (``spotify:track:...``,
  ``spotify:playlist:...``, etc.) used throughout their applications, and thus
  Mopidy-Spotify simply uses the same URI scheme. Playback is handled by
  pushing raw audio data into a GStreamer ``appsrc`` element.

- Mopidy-SoundCloud created it's own URI scheme, after the model of Spotify,
  and uses URIs of the following forms: ``soundcloud:search``,
  ``soundcloud:user-...``, ``soundcloud:exp-...``, and ``soundcloud:set-...``.
  Playback is handled by converting the custom ``soundcloud:..`` URIs to
  ``http://`` URIs immediately before they are passed on to GStreamer for
  playback.

- Mopidy differentiates between ``file://...`` URIs handled by
  :ref:`ext-stream` and ``local:...`` URIs handled by Mopidy-Local.
  :ref:`ext-stream` can play ``file://...`` URIs pointing to tracks and
  playlists located anywhere on your system, but it doesn't know a thing about
  the object before you play it. On the other hand, Mopidy-Local scans a
  predefined :confval:`local/media_dir` to build a meta data library of all
  known tracks. It is thus limited to playing tracks residing in the media
  library, but can provide additional features like directory browsing and
  search. In other words, we have two different ways of playing local music,
  handled by two different backends, and have thus created two different URI
  schemes to separate their handling. The ``local:...`` URIs are converted to
  ``file://...`` URIs immediately before they are passed on to GStreamer for
  playback.

If there isn't an existing URI scheme that fits for your backend's purpose,
you should create your own, and name it after your extension's
:attr:`~mopidy.ext.Extension.ext_name`. Care should be taken not to conflict
with already in use URI schemes. It is also recommended to design the format
such that tracks, playlists and other entities can be distinguished easily.

However, it's important to note that outside of the backend that created them,
URIs are opaque values that neither Mopidy's core layer or Mopidy frontends
should attempt to derive any meaning from. The only valid exception to this is
checking the scheme.


Backend class
=============

.. autoclass:: mopidy.backend.Backend
    :members:


Playback provider
=================

.. autoclass:: mopidy.backend.PlaybackProvider
    :members:


Playlists provider
==================

.. autoclass:: mopidy.backend.PlaylistsProvider
    :members:


Library provider
================

.. autoclass:: mopidy.backend.LibraryProvider
    :members:


Backend listener
================

.. autoclass:: mopidy.backend.BackendListener
    :members:


Backend implementations
=======================

See the `extension registry <https://mopidy.com/ext/>`_.