refactor: optimized playlist logic
This commit is contained in:
@ -183,7 +183,7 @@ class CachedItemWrapper:
|
||||
return self.item().format_song_string(self.user)
|
||||
|
||||
def format_short_string(self):
|
||||
return self.item().format_short_string()
|
||||
return self.item().format_title()
|
||||
|
||||
def format_debug_string(self):
|
||||
return self.item().format_debug_string()
|
||||
|
@ -151,7 +151,7 @@ class FileItem(BaseItem):
|
||||
|
||||
def format_debug_string(self):
|
||||
return "[file] {descrip} ({path})".format(
|
||||
descrip=self.format_short_string(),
|
||||
descrip=self.format_title(),
|
||||
path=self.path
|
||||
)
|
||||
|
||||
@ -171,7 +171,7 @@ class FileItem(BaseItem):
|
||||
|
||||
return display
|
||||
|
||||
def format_short_string(self):
|
||||
def format_title(self):
|
||||
title = self.title if self.title else self.path
|
||||
if self.artist:
|
||||
return self.artist + " - " + title
|
||||
|
@ -95,7 +95,7 @@ class BaseItem:
|
||||
def format_current_playing(self, user):
|
||||
return self.id
|
||||
|
||||
def format_short_string(self):
|
||||
def format_title(self):
|
||||
return self.title
|
||||
|
||||
def format_debug_string(self):
|
||||
|
@ -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]
|
||||
|
@ -157,7 +157,7 @@ class RadioItem(BaseItem):
|
||||
def format_current_playing(self, user):
|
||||
return constants.strings("now_playing", item=self.format_song_string(user))
|
||||
|
||||
def format_short_string(self):
|
||||
def format_title(self):
|
||||
return self.title if self.title else self.url
|
||||
|
||||
def display_type(self):
|
||||
|
@ -242,7 +242,7 @@ class URLItem(BaseItem):
|
||||
|
||||
return display
|
||||
|
||||
def format_short_string(self):
|
||||
def format_title(self):
|
||||
return self.title if self.title.strip() else self.url
|
||||
|
||||
def display_type(self):
|
||||
|
Reference in New Issue
Block a user