stream: Allow for blacklisting of metadata lookups against URI patterns.
This commit is contained in:
parent
8f70899855
commit
50467fef78
@ -42,3 +42,10 @@ See :ref:`config` for general help on configuring Mopidy.
|
|||||||
.. confval:: stream/timeout
|
.. confval:: stream/timeout
|
||||||
|
|
||||||
Number of milliseconds before giving up looking up stream metadata.
|
Number of milliseconds before giving up looking up stream metadata.
|
||||||
|
|
||||||
|
.. confval:: stream/metadata_blacklist
|
||||||
|
|
||||||
|
List of URI globs to not fetch metadata from before playing. This feature
|
||||||
|
is typically needed for play once URIs provided by certain streaming
|
||||||
|
providers. Regular POSIX glob semantics apply, so ``http://*.example.com/*``
|
||||||
|
would match all example.com sub-domains.
|
||||||
|
|||||||
@ -19,6 +19,7 @@ class Extension(ext.Extension):
|
|||||||
def get_config_schema(self):
|
def get_config_schema(self):
|
||||||
schema = super(Extension, self).get_config_schema()
|
schema = super(Extension, self).get_config_schema()
|
||||||
schema['protocols'] = config.List()
|
schema['protocols'] = config.List()
|
||||||
|
schema['metadata_blacklist'] = config.List()
|
||||||
schema['timeout'] = config.Integer(
|
schema['timeout'] = config.Integer(
|
||||||
minimum=1000, maximum=1000 * 60 * 60)
|
minimum=1000, maximum=1000 * 60 * 60)
|
||||||
return schema
|
return schema
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import fnmatch
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
@ -17,7 +19,8 @@ class StreamBackend(pykka.ThreadingActor, backend.Backend):
|
|||||||
super(StreamBackend, self).__init__()
|
super(StreamBackend, self).__init__()
|
||||||
|
|
||||||
self.library = StreamLibraryProvider(
|
self.library = StreamLibraryProvider(
|
||||||
backend=self, timeout=config['stream']['timeout'])
|
backend=self, timeout=config['stream']['timeout'],
|
||||||
|
blacklist=config['stream']['metadata_blacklist'])
|
||||||
self.playback = backend.PlaybackProvider(audio=audio, backend=self)
|
self.playback = backend.PlaybackProvider(audio=audio, backend=self)
|
||||||
self.playlists = None
|
self.playlists = None
|
||||||
|
|
||||||
@ -26,19 +29,25 @@ class StreamBackend(pykka.ThreadingActor, backend.Backend):
|
|||||||
|
|
||||||
|
|
||||||
class StreamLibraryProvider(backend.LibraryProvider):
|
class StreamLibraryProvider(backend.LibraryProvider):
|
||||||
def __init__(self, backend, timeout):
|
def __init__(self, backend, timeout, blacklist):
|
||||||
super(StreamLibraryProvider, self).__init__(backend)
|
super(StreamLibraryProvider, self).__init__(backend)
|
||||||
self._scanner = scan.Scanner(min_duration=None, timeout=timeout)
|
self._scanner = scan.Scanner(min_duration=None, timeout=timeout)
|
||||||
|
self._blacklist_re = re.compile(
|
||||||
|
r'^(%s)$' % '|'.join(fnmatch.translate(u) for u in blacklist))
|
||||||
|
|
||||||
def lookup(self, uri):
|
def lookup(self, uri):
|
||||||
if urlparse.urlsplit(uri).scheme not in self.backend.uri_schemes:
|
if urlparse.urlsplit(uri).scheme not in self.backend.uri_schemes:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
if self._blacklist_re.match(uri):
|
||||||
|
logger.debug('URI matched metadata lookup blacklist: %s', uri)
|
||||||
|
return [Track(uri=uri)]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = self._scanner.scan(uri)
|
data = self._scanner.scan(uri)
|
||||||
track = scan.audio_data_to_track(data)
|
track = scan.audio_data_to_track(data)
|
||||||
except exceptions.ScannerError as e:
|
except exceptions.ScannerError as e:
|
||||||
logger.warning('Problem looking up %s: %s', uri, e)
|
logger.warning('Problem looking up %s: %s', uri, e)
|
||||||
track = Track(uri=uri, name=uri)
|
track = Track(uri=uri)
|
||||||
|
|
||||||
return [track]
|
return [track]
|
||||||
|
|||||||
@ -9,3 +9,4 @@ protocols =
|
|||||||
rtmps
|
rtmps
|
||||||
rtsp
|
rtsp
|
||||||
timeout = 5000
|
timeout = 5000
|
||||||
|
metadata_blacklist =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user