refactor: optimized playlist logic

This commit is contained in:
Terry Geng
2020-03-25 11:38:49 +08:00
parent 3d3c55a0fb
commit b2e5efec93
12 changed files with 242 additions and 144 deletions

View File

@ -90,8 +90,6 @@ class BasePlaylist(list):
if len(self) == 0:
return False
self.version += 1
if self.current_index < len(self) - 1:
self.current_index += 1
return self[self.current_index]
@ -99,7 +97,6 @@ class BasePlaylist(list):
return False
def point_to(self, index):
self.version += 1
if -1 <= index < len(self):
self.current_index = index
@ -134,12 +131,14 @@ class BasePlaylist(list):
return removed
def remove_by_id(self, id):
self.version += 1
to_be_removed = []
for index, wrapper in enumerate(self):
if wrapper.id == id:
to_be_removed.append(index)
if to_be_removed:
self.version += 1
for index in to_be_removed:
self.remove(index)
@ -312,8 +311,6 @@ class RepeatPlaylist(BasePlaylist):
if len(self) == 0:
return False
self.version += 1
if self.current_index < len(self) - 1:
self.current_index += 1
return self[self.current_index]
@ -345,12 +342,11 @@ class RandomPlaylist(BasePlaylist):
if len(self) == 0:
return False
self.version += 1
if self.current_index < len(self) - 1:
self.current_index += 1
return self[self.current_index]
else:
self.version += 1
self.randomize()
self.current_index = 0
return self[0]