From dce85aefe77795dca09cfc1abd31879bdf7beb02 Mon Sep 17 00:00:00 2001 From: Terry Geng Date: Wed, 5 Feb 2020 17:52:12 +0800 Subject: [PATCH] fix reshuffle problem --- media/playlist.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/media/playlist.py b/media/playlist.py index f67d91d..58aa1c9 100644 --- a/media/playlist.py +++ b/media/playlist.py @@ -1,5 +1,6 @@ import youtube_dl import variables as var +import random class PlayList: playlist = [] @@ -79,7 +80,14 @@ class PlayList: return self.playlist[index] def randomize(self): + # current_index will lose track after shuffling, thus we take current music out before shuffling + current = self.current_item() + del self.playlist[self.current_index] + random.shuffle(self.playlist) + + self.playlist.insert(0, current) + self.current_index = 0 self.version += 1 def clear(self):