streaming: Add scanner lookup of stream metadata.
This adds support for looking up metada for all any any protocols the streaming backend will support. This should also ensure that file:// files get metadata.
This commit is contained in:
parent
1379c38370
commit
d9b704d0d8
@ -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):
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -8,3 +8,4 @@ protocols =
|
||||
rtmp
|
||||
rtmps
|
||||
rtsp
|
||||
timeout = 5000
|
||||
|
||||
Loading…
Reference in New Issue
Block a user