From 795926cfa80ddd2a4a405570f7f50959fc9dd720 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 27 Dec 2012 03:21:20 +0100 Subject: [PATCH] stream backend: Add StreamBackend, fixes #151 Adds a basic streaming backend simply handles streaming audio and nothing else. I.e. no metadata beyond the URI we where given. #270 still needs to be solved for actual metadata to make sense in this backend. --- mopidy/backends/stream/__init__.py | 23 ++++++++++++ mopidy/backends/stream/actor.py | 57 ++++++++++++++++++++++++++++++ mopidy/settings.py | 25 +++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 mopidy/backends/stream/__init__.py create mode 100644 mopidy/backends/stream/actor.py diff --git a/mopidy/backends/stream/__init__.py b/mopidy/backends/stream/__init__.py new file mode 100644 index 0000000000..8275554054 --- /dev/null +++ b/mopidy/backends/stream/__init__.py @@ -0,0 +1,23 @@ +"""A backend for playing music for streaming music. + +This backend will handle streaming of URIs in +:attr:`mopidy.settings.STREAM_PROTOCOLS` assuming the right plugins are +installed. + +**Issues:** + +https://github.com/mopidy/mopidy/issues?labels=Stream+backend + +**Dependencies:** + +- None + +**Settings:** + +- :attr:`mopidy.settings.STREAM_PROTOCOLS` +""" + +from __future__ import unicode_literals + +# flake8: noqa +from .actor import StreamBackend diff --git a/mopidy/backends/stream/actor.py b/mopidy/backends/stream/actor.py new file mode 100644 index 0000000000..7fc287112e --- /dev/null +++ b/mopidy/backends/stream/actor.py @@ -0,0 +1,57 @@ +from __future__ import unicode_literals + +import pygst +pygst.require('0.10') +import gst + +import logging +import urlparse + +import pykka + +from mopidy import settings +from mopidy.backends import base +from mopidy.models import SearchResult, Track + +logger = logging.getLogger('mopidy.backends.stream') + + +class StreamBackend(pykka.ThreadingActor, base.Backend): + def __init__(self, audio): + super(StreamBackend, self).__init__() + + self.library = StreamLibraryProvider(backend=self) + self.playback = base.BasePlaybackProvider(audio=audio, backend=self) + self.playlists = None + + available_protocols = set() + + registry = gst.registry_get_default() + for factory in registry.get_feature_list(gst.TYPE_ELEMENT_FACTORY): + for uri in factory.get_uri_protocols(): + if uri in settings.STREAM_PROTOCOLS: + available_protocols.add(uri) + + self.uri_schemes = list(available_protocols) + + +# TODO: Should we consider letting lookup know how to expand common playlist +# formats (m3u, pls, etc) for http(s) URIs? +class StreamLibraryProvider(base.BaseLibraryProvider): + def lookup(self, uri): + if urlparse.urlsplit(uri).scheme not in self.backend.uri_schemes: + return [] + # TODO: actually lookup the stream metadata by getting tags in same + # way as we do for updating the local library with mopidy.scanner + # Note that we would only want the stream metadata at this stage, + # not the currently playing track's. + return [Track(uri=uri, name=uri)] + + def find_exact(self, **query): + return SearchResult() + + def search(self, **query): + return SearchResult() + + def refresh(self, uri=None): + pass diff --git a/mopidy/settings.py b/mopidy/settings.py index c2081e27ae..9d99a7cbbf 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -20,10 +20,12 @@ #: BACKENDS = ( #: u'mopidy.backends.local.LocalBackend', #: u'mopidy.backends.spotify.SpotifyBackend', +#: u'mopidy.backends.spotify.StreamBackend', #: ) BACKENDS = ( 'mopidy.backends.local.LocalBackend', 'mopidy.backends.spotify.SpotifyBackend', + 'mopidy.backends.stream.StreamBackend', ) #: The log format used for informational logging. @@ -301,3 +303,26 @@ #: #: SPOTIFY_TIMEOUT = 10 SPOTIFY_TIMEOUT = 10 + +#: Whitelist of URIs to support streaming from. +#: +#: Used by :mod:`mopidy.backends.stream` +#: +#: Default:: +#: +#: STREAM_PROTOCOLS = ( +#: u'http', +#: u'https', +#: u'mms', +#: u'rtmp', +#: u'rtmps', +#: u'rtsp', +#: ) +STREAM_PROTOCOLS = ( + 'http', + 'https', + 'mms', + 'rtmp', + 'rtmps', + 'rtsp', +)