parent
f67e55618c
commit
2bc3db0d0e
@ -35,6 +35,10 @@ v1.0.0 (UNRELEASED)
|
|||||||
which allows for simpler lookup of multiple URIs. (Fixes: :issue:`1008`,
|
which allows for simpler lookup of multiple URIs. (Fixes: :issue:`1008`,
|
||||||
PR: :issue:`1047`)
|
PR: :issue:`1047`)
|
||||||
|
|
||||||
|
- Add ``uris`` argument to :method:`mopidy.core.TracklistController.add`
|
||||||
|
which allows for simpler addition of multiple URIs to the tracklist. (Fixes:
|
||||||
|
:issue:`1060`, PR: :issue:`1065`)
|
||||||
|
|
||||||
- **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`)
|
||||||
|
|
||||||
|
|||||||
@ -299,13 +299,16 @@ class TracklistController(object):
|
|||||||
|
|
||||||
return self.get_tl_tracks()[position - 1]
|
return self.get_tl_tracks()[position - 1]
|
||||||
|
|
||||||
def add(self, tracks=None, at_position=None, uri=None):
|
def add(self, tracks=None, at_position=None, uri=None, uris=None):
|
||||||
"""
|
"""
|
||||||
Add the track or list of tracks to the tracklist.
|
Add the track or list of tracks to the tracklist.
|
||||||
|
|
||||||
If ``uri`` is given instead of ``tracks``, the URI is looked up in the
|
If ``uri`` is given instead of ``tracks``, the URI is looked up in the
|
||||||
library and the resulting tracks are added to the tracklist.
|
library and the resulting tracks are added to the tracklist.
|
||||||
|
|
||||||
|
If ``uris`` is given instead of ``tracks``, the URIs are looked up in
|
||||||
|
the library and the resulting tracks are added to the tracklist.
|
||||||
|
|
||||||
If ``at_position`` is given, the tracks placed at the given position in
|
If ``at_position`` is given, the tracks placed at the given position in
|
||||||
the tracklist. If ``at_position`` is not given, the tracks are appended
|
the tracklist. If ``at_position`` is not given, the tracks are appended
|
||||||
to the end of the tracklist.
|
to the end of the tracklist.
|
||||||
@ -319,12 +322,24 @@ class TracklistController(object):
|
|||||||
:param uri: URI for tracks to add
|
:param uri: URI for tracks to add
|
||||||
:type uri: string
|
:type uri: string
|
||||||
:rtype: list of :class:`mopidy.models.TlTrack`
|
:rtype: list of :class:`mopidy.models.TlTrack`
|
||||||
"""
|
|
||||||
assert tracks is not None or uri is not None, \
|
|
||||||
'tracks or uri must be provided'
|
|
||||||
|
|
||||||
if tracks is None and uri is not None:
|
.. versionadded:: 1.0
|
||||||
tracks = self.core.library.lookup(uri)
|
The ``uris`` argument.
|
||||||
|
|
||||||
|
.. deprecated:: 1.0
|
||||||
|
The ``tracks`` and ``uri`` arguments. Use ``uris``.
|
||||||
|
"""
|
||||||
|
assert tracks is not None or uri is not None or uris is not None, \
|
||||||
|
'tracks, uri or uris must be provided'
|
||||||
|
|
||||||
|
if tracks is None:
|
||||||
|
if uri is not None:
|
||||||
|
tracks = self.core.library.lookup(uri=uri)
|
||||||
|
elif uris is not None:
|
||||||
|
tracks = []
|
||||||
|
track_map = self.core.library.lookup(uris=uris)
|
||||||
|
for uri in uris:
|
||||||
|
tracks.extend(track_map[uri])
|
||||||
|
|
||||||
tl_tracks = []
|
tl_tracks = []
|
||||||
|
|
||||||
|
|||||||
@ -26,8 +26,7 @@ class TracklistTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_add_by_uri_looks_up_uri_in_library(self):
|
def test_add_by_uri_looks_up_uri_in_library(self):
|
||||||
track = Track(uri='dummy1:x', name='x')
|
track = Track(uri='dummy1:x', name='x')
|
||||||
self.library.lookup().get.return_value = [track]
|
self.library.lookup.return_value.get.return_value = [track]
|
||||||
self.library.lookup.reset_mock()
|
|
||||||
|
|
||||||
tl_tracks = self.core.tracklist.add(uri='dummy1:x')
|
tl_tracks = self.core.tracklist.add(uri='dummy1:x')
|
||||||
|
|
||||||
@ -36,6 +35,26 @@ class TracklistTest(unittest.TestCase):
|
|||||||
self.assertEqual(track, tl_tracks[0].track)
|
self.assertEqual(track, tl_tracks[0].track)
|
||||||
self.assertEqual(tl_tracks, self.core.tracklist.tl_tracks[-1:])
|
self.assertEqual(tl_tracks, self.core.tracklist.tl_tracks[-1:])
|
||||||
|
|
||||||
|
def test_add_by_uris_looks_up_uris_in_library(self):
|
||||||
|
track1 = Track(uri='dummy1:x', name='x')
|
||||||
|
track2 = Track(uri='dummy1:y1', name='y1')
|
||||||
|
track3 = Track(uri='dummy1:y2', name='y2')
|
||||||
|
self.library.lookup.return_value.get.side_effect = [
|
||||||
|
[track1], [track2, track3]]
|
||||||
|
|
||||||
|
tl_tracks = self.core.tracklist.add(uris=['dummy1:x', 'dummy1:y'])
|
||||||
|
|
||||||
|
self.library.lookup.assert_has_calls([
|
||||||
|
mock.call('dummy1:x'),
|
||||||
|
mock.call('dummy1:y'),
|
||||||
|
])
|
||||||
|
self.assertEqual(3, len(tl_tracks))
|
||||||
|
self.assertEqual(track1, tl_tracks[0].track)
|
||||||
|
self.assertEqual(track2, tl_tracks[1].track)
|
||||||
|
self.assertEqual(track3, tl_tracks[2].track)
|
||||||
|
self.assertEqual(
|
||||||
|
tl_tracks, self.core.tracklist.tl_tracks[-len(tl_tracks):])
|
||||||
|
|
||||||
def test_remove_removes_tl_tracks_matching_query(self):
|
def test_remove_removes_tl_tracks_matching_query(self):
|
||||||
tl_tracks = self.core.tracklist.remove(name=['foo'])
|
tl_tracks = self.core.tracklist.remove(name=['foo'])
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user