m3u: Add playlists.as_list()
This commit is contained in:
parent
5693b454ee
commit
4bae9c874c
@ -8,7 +8,7 @@ import sys
|
|||||||
|
|
||||||
from mopidy import backend
|
from mopidy import backend
|
||||||
from mopidy.m3u import translator
|
from mopidy.m3u import translator
|
||||||
from mopidy.models import Playlist
|
from mopidy.models import Playlist, Ref
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -22,6 +22,12 @@ class M3UPlaylistsProvider(backend.PlaylistsProvider):
|
|||||||
self._playlists = {}
|
self._playlists = {}
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
|
def as_list(self):
|
||||||
|
refs = [
|
||||||
|
Ref.playlist(uri=pl.uri, name=pl.name)
|
||||||
|
for pl in self._playlists.values()]
|
||||||
|
return sorted(refs, key=operator.attrgetter('name'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def playlists(self):
|
def playlists(self):
|
||||||
return sorted(
|
return sorted(
|
||||||
|
|||||||
@ -146,8 +146,8 @@ class M3UPlaylistsProviderTest(unittest.TestCase):
|
|||||||
self.assert_(self.core.playlists.playlists)
|
self.assert_(self.core.playlists.playlists)
|
||||||
self.assertIn(playlist, self.core.playlists.playlists)
|
self.assertIn(playlist, self.core.playlists.playlists)
|
||||||
|
|
||||||
def test_playlists_empty_to_start_with(self):
|
def test_as_list_empty_to_start_with(self):
|
||||||
self.assert_(not self.core.playlists.playlists)
|
self.assertEqual(len(self.core.playlists.as_list()), 0)
|
||||||
|
|
||||||
def test_delete_non_existant_playlist(self):
|
def test_delete_non_existant_playlist(self):
|
||||||
self.core.playlists.delete('m3u:unknown')
|
self.core.playlists.delete('m3u:unknown')
|
||||||
@ -249,12 +249,11 @@ class M3UPlaylistsProviderTest(unittest.TestCase):
|
|||||||
|
|
||||||
backend = self.backend_class(config=self.config, audio=self.audio)
|
backend = self.backend_class(config=self.config, audio=self.audio)
|
||||||
|
|
||||||
self.assert_(backend.playlists.playlists)
|
self.assertEqual(len(backend.playlists.as_list()), 1)
|
||||||
self.assertEqual('m3u:test.m3u', backend.playlists.playlists[0].uri)
|
result = backend.playlists.lookup('m3u:test.m3u')
|
||||||
self.assertEqual(
|
self.assertEqual('m3u:test.m3u', result.uri)
|
||||||
playlist.name, backend.playlists.playlists[0].name)
|
self.assertEqual(playlist.name, result.name)
|
||||||
self.assertEqual(
|
self.assertEqual(track.uri, result.tracks[0].uri)
|
||||||
track.uri, backend.playlists.playlists[0].tracks[0].uri)
|
|
||||||
|
|
||||||
def test_playlist_sort_order(self):
|
def test_playlist_sort_order(self):
|
||||||
def check_order(playlists, names):
|
def check_order(playlists, names):
|
||||||
@ -264,18 +263,18 @@ class M3UPlaylistsProviderTest(unittest.TestCase):
|
|||||||
self.core.playlists.create('a')
|
self.core.playlists.create('a')
|
||||||
self.core.playlists.create('b')
|
self.core.playlists.create('b')
|
||||||
|
|
||||||
check_order(self.core.playlists.playlists, ['a', 'b', 'c'])
|
check_order(self.core.playlists.as_list(), ['a', 'b', 'c'])
|
||||||
|
|
||||||
self.core.playlists.refresh()
|
self.core.playlists.refresh()
|
||||||
|
|
||||||
check_order(self.core.playlists.playlists, ['a', 'b', 'c'])
|
check_order(self.core.playlists.as_list(), ['a', 'b', 'c'])
|
||||||
|
|
||||||
playlist = self.core.playlists.lookup('m3u:a.m3u')
|
playlist = self.core.playlists.lookup('m3u:a.m3u')
|
||||||
playlist = playlist.copy(name='d')
|
playlist = playlist.copy(name='d')
|
||||||
playlist = self.core.playlists.save(playlist)
|
playlist = self.core.playlists.save(playlist)
|
||||||
|
|
||||||
check_order(self.core.playlists.playlists, ['b', 'c', 'd'])
|
check_order(self.core.playlists.as_list(), ['b', 'c', 'd'])
|
||||||
|
|
||||||
self.core.playlists.delete('m3u:c.m3u')
|
self.core.playlists.delete('m3u:c.m3u')
|
||||||
|
|
||||||
check_order(self.core.playlists.playlists, ['b', 'd'])
|
check_order(self.core.playlists.as_list(), ['b', 'd'])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user