diff --git a/mopidy/audio/actor.py b/mopidy/audio/actor.py index 133c8424..6ef48a6b 100644 --- a/mopidy/audio/actor.py +++ b/mopidy/audio/actor.py @@ -244,20 +244,6 @@ class SoftwareMixer(object): self._mixer.trigger_mute_changed(self._last_mute) -def setup_proxy(element, config): - # TODO: reuse in scanner code - if not config.get('hostname'): - return - - proxy = "%s://%s:%d" % (config.get('scheme', 'http'), - config.get('hostname'), - config.get('port', 80)) - - element.set_property('proxy', proxy) - element.set_property('proxy-id', config.get('username')) - element.set_property('proxy-pw', config.get('password')) - - class _Handler(object): def __init__(self, audio): self._audio = audio @@ -531,8 +517,7 @@ class Audio(pykka.ThreadingActor): else: self._appsrc.reset() - if hasattr(source.props, 'proxy'): - setup_proxy(source, self._config['proxy']) + utils.setup_proxy(source, self._config['proxy']) def set_uri(self, uri): """ diff --git a/mopidy/audio/scan.py b/mopidy/audio/scan.py index 931a2e3a..38b86437 100644 --- a/mopidy/audio/scan.py +++ b/mopidy/audio/scan.py @@ -16,10 +16,11 @@ class Scanner(object): Helper to get tags and other relevant info from URIs. :param timeout: timeout for scanning a URI in ms + :param proxy_config: dictionary containing proxy config strings. :type event: int """ - def __init__(self, timeout=1000): + def __init__(self, timeout=1000, proxy_config=None): self._timeout_ms = timeout sink = gst.element_factory_make('fakesink') @@ -29,9 +30,13 @@ class Scanner(object): def pad_added(src, pad): return pad.link(sink.get_pad('sink')) + def source_setup(element, source): + utils.setup_proxy(source, proxy_config or {}) + self._uribin = gst.element_factory_make('uridecodebin') self._uribin.set_property('caps', audio_caps) self._uribin.connect('pad-added', pad_added) + self._uribin.connect('source-setup', source_setup) self._pipe = gst.element_factory_make('pipeline') self._pipe.add(self._uribin) diff --git a/mopidy/audio/utils.py b/mopidy/audio/utils.py index 8581fd61..1a8bf6a7 100644 --- a/mopidy/audio/utils.py +++ b/mopidy/audio/utils.py @@ -82,7 +82,8 @@ def _artists(tags, artist_name, artist_id=None): def convert_tags_to_track(tags): """Convert our normalized tags to a track. - :param :class:`dict` tags: dictionary of tag keys with a list of values + :param tags: dictionary of tag keys with a list of values + :type tags: :class:`dict` :rtype: :class:`mopidy.models.Track` """ album_kwargs = {} @@ -130,6 +131,26 @@ def convert_tags_to_track(tags): return Track(**track_kwargs) +def setup_proxy(element, config): + """Configure a GStreamer element with proxy settings. + + :param element: element to setup proxy in. + :type element: :class:`gst.GstElement` + :param config: proxy settings to use. + :type config: :class:`dict` + """ + if not hasattr(element.props, 'proxy') or not config.get('hostname'): + return + + proxy = "%s://%s:%d" % (config.get('scheme', 'http'), + config.get('hostname'), + config.get('port', 80)) + + element.set_property('proxy', proxy) + element.set_property('proxy-id', config.get('username')) + element.set_property('proxy-pw', config.get('password')) + + def convert_taglist(taglist): """Convert a :class:`gst.Taglist` to plain Python types. @@ -147,7 +168,8 @@ def convert_taglist(taglist): .. _GstTagList: http://gstreamer.freedesktop.org/data/doc/gstreamer/\ 0.10.36/gstreamer/html/gstreamer-GstTagList.html - :param gst.Taglist taglist: A GStreamer taglist to be converted. + :param taglist: A GStreamer taglist to be converted. + :type taglist: :class:`gst.Taglist` :rtype: dictionary of tag keys with a list of values. """ result = {}