diff --git a/mopidy/backends/stream/__init__.py b/mopidy/backends/stream/__init__.py index 061ac5d0..28e2deba 100644 --- a/mopidy/backends/stream/__init__.py +++ b/mopidy/backends/stream/__init__.py @@ -19,6 +19,8 @@ class Extension(ext.Extension): def get_config_schema(self): schema = super(Extension, self).get_config_schema() schema['protocols'] = config.List() + schema['timeout'] = config.Integer( + minimum=1000, maximum=1000*60*60) return schema def validate_environment(self): diff --git a/mopidy/backends/stream/actor.py b/mopidy/backends/stream/actor.py index 86df447d..49034191 100644 --- a/mopidy/backends/stream/actor.py +++ b/mopidy/backends/stream/actor.py @@ -5,7 +5,8 @@ import urlparse import pykka -from mopidy import audio as audio_lib +from mopidy import audio as audio_lib, exceptions +from mopidy.audio import scan from mopidy.backends import base from mopidy.models import Track @@ -16,7 +17,8 @@ class StreamBackend(pykka.ThreadingActor, base.Backend): def __init__(self, config, audio): super(StreamBackend, self).__init__() - self.library = StreamLibraryProvider(backend=self) + self.library = StreamLibraryProvider( + backend=self, timeout=config['stream']['timeout']) self.playback = base.BasePlaybackProvider(audio=audio, backend=self) self.playlists = None @@ -24,14 +26,20 @@ class StreamBackend(pykka.ThreadingActor, base.Backend): config['stream']['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 __init__(self, backend, timeout): + super(StreamLibraryProvider, self).__init__(backend) + self._scanner = scan.Scanner(min_duration=None, timeout=timeout) + 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)] + + try: + data = self._scanner.scan(uri) + track = scan.audio_data_to_track(data) + except exceptions.ScannerError as e: + logger.warning('Problem looking up %s - %s', uri, e) + track = Track(uri=uri, name=uri) + + return [track] diff --git a/mopidy/backends/stream/ext.conf b/mopidy/backends/stream/ext.conf index dc0287da..811dec88 100644 --- a/mopidy/backends/stream/ext.conf +++ b/mopidy/backends/stream/ext.conf @@ -8,3 +8,4 @@ protocols = rtmp rtmps rtsp +timeout = 5000