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.
This commit is contained in:
Thomas Adamcik 2013-01-01 17:25:07 +01:00
parent f1bd092e63
commit ca82565b08
2 changed files with 26 additions and 13 deletions

23
mopidy/audio/utils.py Normal file
View File

@ -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

View File

@ -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