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:
parent
692bcae8e4
commit
9314f2df5c
23
mopidy/audio/utils.py
Normal file
23
mopidy/audio/utils.py
Normal 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
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user