From 9314f2df5c6b434982df7a0156b1e5257fd07000 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 1 Jan 2013 17:25:07 +0100 Subject: [PATCH] audio: Move supported URI checking to mopidy.audio.utils In order to avoid gstreamer imports leaking into more of our code I'm moving this to a new utils class in audio. --- mopidy/audio/utils.py | 23 +++++++++++++++++++++++ mopidy/backends/stream/actor.py | 16 +++------------- 2 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 mopidy/audio/utils.py diff --git a/mopidy/audio/utils.py b/mopidy/audio/utils.py new file mode 100644 index 00000000..3f5f685e --- /dev/null +++ b/mopidy/audio/utils.py @@ -0,0 +1,23 @@ +from __future__ import unicode_literals + +import pygst +pygst.require('0.10') +import gst + + +def supported_uri_schemes(uri_schemes): + """Determine which URIs we can actually support from provided whitelist. + + :param uri_schemes: list/set of URIs to check support for. + :type uri_schemes: list or set or URI schemes as strings. + :rtype: set of URI schemes we can support via this GStreamer install. + """ + supported_schemes= 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 uri_schemes: + supported_schemes.add(uri) + + return supported_schemes diff --git a/mopidy/backends/stream/actor.py b/mopidy/backends/stream/actor.py index cdf777af..0c91f291 100644 --- a/mopidy/backends/stream/actor.py +++ b/mopidy/backends/stream/actor.py @@ -1,15 +1,12 @@ 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.audio import utils from mopidy.backends import base from mopidy.models import SearchResult, Track @@ -24,15 +21,8 @@ class StreamBackend(pykka.ThreadingActor, base.Backend): 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) + self.uri_schemes = utils.supported_uri_schemes( + settings.STREAM_PROTOCOLS) # TODO: Should we consider letting lookup know how to expand common playlist