Merge pull request #1047 from adamcik/fix/1008-add-uris-to-lookup
core: Add uris argument to library.lookup (Fixes #1008)
This commit is contained in:
commit
dc982cd880
@ -31,6 +31,10 @@ v1.0.0 (UNRELEASED)
|
|||||||
- Add :class:`mopidy.core.MixerController` which keeps track of volume and
|
- Add :class:`mopidy.core.MixerController` which keeps track of volume and
|
||||||
mute. (Fixes: :issue:`962`)
|
mute. (Fixes: :issue:`962`)
|
||||||
|
|
||||||
|
- Add ``uris`` argument to :method:`mopidy.core.LibraryController.lookup`
|
||||||
|
which allows for simpler lookup of multiple URIs. (Fixes: :issue:`1008`,
|
||||||
|
PR: :issue:`1047`)
|
||||||
|
|
||||||
- **Deprecated:** The old methods on :class:`mopidy.core.PlaybackController` for
|
- **Deprecated:** The old methods on :class:`mopidy.core.PlaybackController` for
|
||||||
volume and mute management have been deprecated. (Fixes: :issue:`962`)
|
volume and mute management have been deprecated. (Fixes: :issue:`962`)
|
||||||
|
|
||||||
|
|||||||
@ -162,7 +162,7 @@ class LibraryController(object):
|
|||||||
in self._get_backends_to_uris(uris).items()]
|
in self._get_backends_to_uris(uris).items()]
|
||||||
return [result for result in pykka.get_all(futures) if result]
|
return [result for result in pykka.get_all(futures) if result]
|
||||||
|
|
||||||
def lookup(self, uri):
|
def lookup(self, uri=None, uris=None):
|
||||||
"""
|
"""
|
||||||
Lookup the given URI.
|
Lookup the given URI.
|
||||||
|
|
||||||
@ -170,14 +170,39 @@ class LibraryController(object):
|
|||||||
them all.
|
them all.
|
||||||
|
|
||||||
:param uri: track URI
|
:param uri: track URI
|
||||||
:type uri: string
|
:type uri: string or :class:`None`
|
||||||
:rtype: list of :class:`mopidy.models.Track`
|
:param uris: track URIs
|
||||||
|
:type uris: list of string or :class:`None`
|
||||||
|
:rtype: list of :class:`mopidy.models.Track` if uri was set or
|
||||||
|
a {uri: list of :class:`mopidy.models.Track`} if uris was set.
|
||||||
|
|
||||||
|
.. versionadded:: 1.0
|
||||||
|
The ``uris`` argument.
|
||||||
|
|
||||||
|
.. deprecated:: 1.0
|
||||||
|
The ``uri`` argument. Use ``uris`` instead.
|
||||||
"""
|
"""
|
||||||
backend = self._get_backend(uri)
|
none_set = uri is None and uris is None
|
||||||
if backend:
|
both_set = uri is not None and uris is not None
|
||||||
return backend.library.lookup(uri).get()
|
|
||||||
else:
|
if none_set or both_set:
|
||||||
return []
|
raise ValueError("One of 'uri' or 'uris' must be set")
|
||||||
|
|
||||||
|
futures = {}
|
||||||
|
result = {}
|
||||||
|
backends = self._get_backends_to_uris([uri] if uri else uris)
|
||||||
|
|
||||||
|
# TODO: lookup(uris) to backend APIs
|
||||||
|
for backend, backend_uris in backends.items():
|
||||||
|
for u in backend_uris or []:
|
||||||
|
futures[u] = backend.library.lookup(u)
|
||||||
|
|
||||||
|
for u, future in futures.items():
|
||||||
|
result[u] = future.get()
|
||||||
|
|
||||||
|
if uri:
|
||||||
|
return result.get(uri, [])
|
||||||
|
return result
|
||||||
|
|
||||||
def refresh(self, uri=None):
|
def refresh(self, uri=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -157,6 +157,17 @@ class CoreLibraryTest(unittest.TestCase):
|
|||||||
self.assertFalse(self.library1.lookup.called)
|
self.assertFalse(self.library1.lookup.called)
|
||||||
self.library2.lookup.assert_called_once_with('dummy2:a')
|
self.library2.lookup.assert_called_once_with('dummy2:a')
|
||||||
|
|
||||||
|
def test_lookup_fails_with_uri_and_uris_set(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
self.core.library.lookup('dummy1:a', ['dummy2:a'])
|
||||||
|
|
||||||
|
def test_lookup_can_handle_uris(self):
|
||||||
|
self.library1.lookup().get.return_value = [1234]
|
||||||
|
self.library2.lookup().get.return_value = [5678]
|
||||||
|
|
||||||
|
result = self.core.library.lookup(uris=['dummy1:a', 'dummy2:a'])
|
||||||
|
self.assertEqual(result, {'dummy2:a': [5678], 'dummy1:a': [1234]})
|
||||||
|
|
||||||
def test_lookup_returns_nothing_for_dummy3_track(self):
|
def test_lookup_returns_nothing_for_dummy3_track(self):
|
||||||
result = self.core.library.lookup('dummy3:a')
|
result = self.core.library.lookup('dummy3:a')
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user