curds: Move playlist peeking into the Playlist class

It makes more sense to do it here than in the PlaylistManager

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-18 11:48:23 -04:00
parent 277aabb7bd
commit dbc7683ccd
3 changed files with 36 additions and 14 deletions

View File

@ -34,25 +34,12 @@ class PlaylistManager(node.PlaylistNode):
self.__current_changed(old)
return self.track
def __peek_pl(self, plist, n):
cur = plist.current
res = [ ]
for i in range(n):
t = plist.next()
if t == None:
break
res.append(t)
plist.current = cur
return res
def peek(self, n):
state = random.getstate()
res = [ ]
for pl in self.current:
tracks = self.__peek_pl(pl, n)
tracks = pl.peek(n)
res += tracks
n -= len(tracks)
if n == 0:

View File

@ -62,6 +62,19 @@ class Playlist(node.PlaylistNode):
return None
return self.list[self.current]
def peek(self, n):
cur = self.current
res = [ ]
for i in range(n):
track = self.next()
if track == None:
break
res.append(track)
self.current = cur
return res
def reset(self):
self.list.clear()
self.current = -1

View File

@ -215,6 +215,28 @@ class TestPlaylist(unittest.TestCase):
self.assertEqual(plist.next(), track)
self.assertEqual(plist.current, 0)
def test_playlist_peek(self):
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
plist = playlist.Playlist("Test Playlist")
tracks = [ ]
for i in range(1, 5):
track = tags.Track.lookup(os.path.join(path, f"0{i} - Test Track 0{i}.ogg"))
tracks.append(track)
plist.add(track)
peek = plist.peek(0)
self.assertEqual(peek, [ ])
self.assertEqual(plist.current, -1)
peek = plist.peek(2)
self.assertEqual(peek, tracks[:2])
self.assertEqual(plist.current, -1)
peek = plist.peek(10)
self.assertEqual(peek, tracks)
self.assertEqual(plist.current, -1)
def test_playlist_list(self):
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
plist = playlist.Playlist("Test Playlist")