spotify: Define extension

This commit is contained in:
Stein Magnus Jodal 2013-04-01 13:38:51 +02:00
parent 257d3d6332
commit 7060a75072
2 changed files with 71 additions and 9 deletions

View File

@ -1,4 +1,39 @@
"""A backend for playing music from Spotify
from __future__ import unicode_literals
import mopidy
from mopidy import ext
from mopidy.exceptions import ExtensionError
from mopidy.utils.formatting import indent
config = """
[spotify]
# If the Spotify extension should be enabled or not
enabled = true
# Your Spotify Premium username
username =
# Your Spotify Premium password
password =
# The preferred audio bitrate. Valid values are 96, 160, 320
bitrate = 160
# Max number of seconds to wait for Spotify operations to complete
timeout = 10
# Path to the Spotify data cache. Cannot be shared with other Spotify apps
cache_path = $XDG_CACHE_DIR/mopidy/spotify
# Connect to Spotify through a proxy
proxy_host =
proxy_username =
proxy_password =
"""
__doc__ = """A backend for playing music from Spotify
`Spotify <http://www.spotify.com/>`_ is a music streaming service. The backend
uses the official `libspotify
@ -22,14 +57,39 @@ https://github.com/mopidy/mopidy/issues?labels=Spotify+backend
.. literalinclude:: ../../../requirements/spotify.txt
**Settings:**
**Default config:**
- :attr:`mopidy.settings.SPOTIFY_CACHE_PATH`
- :attr:`mopidy.settings.SPOTIFY_USERNAME`
- :attr:`mopidy.settings.SPOTIFY_PASSWORD`
"""
.. code-block:: ini
from __future__ import unicode_literals
%(config)s
""" % {'config': indent(config)}
# flake8: noqa
# TODO Move import into method when BACKENDS setting is removed
from .actor import SpotifyBackend
class Extension(ext.Extension):
name = 'Mopidy-Spotify'
version = mopidy.__version__
def get_default_config(self):
return config
def validate_config(self, config):
if not config.getboolean('spotify', 'enabled'):
return
if not config.get('spotify', 'username'):
raise ExtensionError('Config spotify.username not set')
if not config.get('spotify', 'password'):
raise ExtensionError('Config spotify.password not set')
def validate_environment(self):
try:
import spotify # noqa
except ImportError as e:
raise ExtensionError('pyspotify library not found', e)
def get_backend_classes(self):
return [SpotifyBackend]

View File

@ -44,7 +44,9 @@ setup(
'mopidy = mopidy.__main__:main',
'mopidy-scan = mopidy.scanner:main',
],
b'mopidy.extension': [],
b'mopidy.extension': [
'spotify = mopidy.backends.spotify:Extension',
],
},
classifiers=[
'Development Status :: 4 - Beta',