Skip to content

Commit

Permalink
stream: Hook stream scanner up to proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcik committed Feb 12, 2015
1 parent 96572ea commit 0e4e872
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Expand Up @@ -124,6 +124,9 @@ v0.20.0 (UNRELEASED)

- Add basic tests for the stream library provider.

- Add support for proxies when doing initial metadata lookup for stream.
(Fixes :issue:`390`)

**Mopidy.js client library**

This version has been released to npm as Mopidy.js v0.5.0.
Expand Down
7 changes: 4 additions & 3 deletions mopidy/stream/actor.py
Expand Up @@ -20,7 +20,8 @@ def __init__(self, config, audio):

self.library = StreamLibraryProvider(
backend=self, timeout=config['stream']['timeout'],
blacklist=config['stream']['metadata_blacklist'])
blacklist=config['stream']['metadata_blacklist'],
proxy=config['proxy'])
self.playback = backend.PlaybackProvider(audio=audio, backend=self)
self.playlists = None

Expand All @@ -29,9 +30,9 @@ def __init__(self, config, audio):


class StreamLibraryProvider(backend.LibraryProvider):
def __init__(self, backend, timeout, blacklist):
def __init__(self, backend, timeout, blacklist, proxy):
super(StreamLibraryProvider, self).__init__(backend)
self._scanner = scan.Scanner(timeout=timeout)
self._scanner = scan.Scanner(timeout=timeout, proxy_config=proxy)
self._blacklist_re = re.compile(
r'^(%s)$' % '|'.join(fnmatch.translate(u) for u in blacklist))

Expand Down
8 changes: 4 additions & 4 deletions tests/stream/test_library.py
Expand Up @@ -25,19 +25,19 @@ def setUp(self): # noqa: N802
self.uri = path_to_uri(path_to_data_dir('song1.wav'))

def test_lookup_ignores_unknown_scheme(self):
library = actor.StreamLibraryProvider(self.backend, 1000, [])
library = actor.StreamLibraryProvider(self.backend, 1000, [], {})
self.assertFalse(library.lookup('http://example.com'))

def test_lookup_respects_blacklist(self):
library = actor.StreamLibraryProvider(self.backend, 100, [self.uri])
library = actor.StreamLibraryProvider(self.backend, 10, [self.uri], {})
self.assertEqual([Track(uri=self.uri)], library.lookup(self.uri))

def test_lookup_respects_blacklist_globbing(self):
blacklist = [path_to_uri(path_to_data_dir('')) + '*']
library = actor.StreamLibraryProvider(self.backend, 100, blacklist)
library = actor.StreamLibraryProvider(self.backend, 100, blacklist, {})
self.assertEqual([Track(uri=self.uri)], library.lookup(self.uri))

def test_lookup_converts_uri_metadata_to_track(self):
library = actor.StreamLibraryProvider(self.backend, 100, [])
library = actor.StreamLibraryProvider(self.backend, 100, [], {})
self.assertEqual([Track(length=4406, uri=self.uri)],
library.lookup(self.uri))

0 comments on commit 0e4e872

Please sign in to comment.