curds: Pop empty playlists earlier during playlist.next()

Rather than waiting until the next next() call, we can detect and remove
them right away.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-12-16 10:26:08 -05:00
parent 99de9c0f7d
commit 1b88795d17
2 changed files with 10 additions and 4 deletions

View File

@ -27,13 +27,19 @@ def lookup(name):
def next():
global Track
with Lock:
Track = Current[0].next()
orig = Current[0]
Track = orig.next()
while Track == None and len(Current) > 1:
Current.pop(0).changed()
Current[0].changed()
Current.pop(0)
Track = Current[0].next()
if len(Current[0]) == 0 and len(Current) > 1:
Current.pop(0)
if orig != Current[0]:
orig.changed()
Current[0].changed()
Root.lookup("Previous").add(Track)
return Track

View File

@ -61,7 +61,7 @@ class TestPlaylist(unittest.TestCase):
track1 = playlist.next()
self.assertEqual(playlist.Track, track1)
self.assertEqual(playlist.Current, [ upnxt, clist ])
self.assertEqual(playlist.Current, [ clist ])
self.assertEqual(len(prev), 1)
self.assertEqual(prev[0], track1)