Skip to content

Commit

Permalink
stream backend: Add StreamBackend, fixes #151
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adamcik authored and jodal committed Mar 12, 2013
1 parent 1abab8c commit 795926c
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 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
57 changes: 57 additions & 0 deletions 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
25 changes: 25 additions & 0 deletions mopidy/settings.py
Expand Up @@ -20,10 +20,12 @@
#: BACKENDS = ( #: BACKENDS = (
#: u'mopidy.backends.local.LocalBackend', #: u'mopidy.backends.local.LocalBackend',
#: u'mopidy.backends.spotify.SpotifyBackend', #: u'mopidy.backends.spotify.SpotifyBackend',
#: u'mopidy.backends.spotify.StreamBackend',
#: ) #: )
BACKENDS = ( BACKENDS = (
'mopidy.backends.local.LocalBackend', 'mopidy.backends.local.LocalBackend',
'mopidy.backends.spotify.SpotifyBackend', 'mopidy.backends.spotify.SpotifyBackend',
'mopidy.backends.stream.StreamBackend',
) )


#: The log format used for informational logging. #: The log format used for informational logging.
Expand Down Expand Up @@ -301,3 +303,26 @@
#: #:
#: SPOTIFY_TIMEOUT = 10 #: SPOTIFY_TIMEOUT = 10
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',
)

0 comments on commit 795926c

Please sign in to comment.