fix: delete item keyerror #91
This commit is contained in:
parent
da6b028e2c
commit
e10059a76e
@ -287,7 +287,7 @@ def cmd_play_url(bot, user, text, command, parameter):
|
||||
var.playlist.append(music_wrapper)
|
||||
|
||||
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
||||
bot.send_msg(constants.strings('file_added', item=music_wrapper.format_song_string()), text)
|
||||
bot.send_msg(constants.strings('file_added', item=music_wrapper.format_short_string()), text)
|
||||
if len(var.playlist) == 2:
|
||||
# If I am the second item on the playlist. (I am the next one!)
|
||||
bot.async_download_next()
|
||||
|
@ -86,6 +86,7 @@ class BaseItem:
|
||||
return ""
|
||||
|
||||
def send_client_message(self, msg):
|
||||
if self.bot:
|
||||
self.bot.send_msg(msg)
|
||||
|
||||
def to_dict(self):
|
||||
|
@ -73,7 +73,9 @@ class MusicLibrary(dict):
|
||||
self.log.debug("library: music save into database: %s" % self[id].format_debug_string())
|
||||
self.db.insert_music(self[id].to_dict())
|
||||
|
||||
def delete(self, item):
|
||||
def delete(self, id):
|
||||
try:
|
||||
item = self.get_item_by_id(None, id)
|
||||
self.log.debug("library: DELETE item from the database: %s" % item.format_debug_string())
|
||||
|
||||
if item.type == 'file' and item.path in self.file_id_lookup:
|
||||
@ -85,6 +87,8 @@ class MusicLibrary(dict):
|
||||
if item.id in self:
|
||||
del self[item.id]
|
||||
self.db.delete_music(id=item.id)
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
def free(self, id):
|
||||
if id in self:
|
||||
|
@ -235,8 +235,6 @@ class BasePlaylist(list):
|
||||
for index in to_be_removed:
|
||||
self.remove(index)
|
||||
|
||||
var.library.free(id)
|
||||
|
||||
def current_item(self):
|
||||
if len(self) == 0:
|
||||
return False
|
||||
@ -318,8 +316,8 @@ class BasePlaylist(list):
|
||||
self.log.debug("playlist: validating %s" % item.format_debug_string())
|
||||
if not item.validate() or item.is_failed():
|
||||
self.log.debug("playlist: validating failed.")
|
||||
var.library.delete(item.id)
|
||||
self.remove_by_id(item.id)
|
||||
var.library.delete(item.item())
|
||||
|
||||
self.log.debug("playlist: validating finished.")
|
||||
self.validating_thread_lock.release()
|
||||
@ -332,9 +330,11 @@ class OneshotPlaylist(BasePlaylist):
|
||||
self.current_index = -1
|
||||
|
||||
def from_list(self, _list, current_index):
|
||||
if len(_list) > 0:
|
||||
for i in range(current_index):
|
||||
_list.pop()
|
||||
return super().from_list(_list, -1)
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
if len(self) == 0:
|
||||
|
@ -68,15 +68,18 @@ class URLItem(BaseItem):
|
||||
return True
|
||||
|
||||
def validate(self):
|
||||
self.validating_lock.acquire()
|
||||
if self.ready in ['yes', 'validated']:
|
||||
return True
|
||||
|
||||
if self.ready == 'failed':
|
||||
return False
|
||||
|
||||
if os.path.exists(self.path):
|
||||
self.ready = "yes"
|
||||
return True
|
||||
|
||||
# avoid multiple process validating in the meantime
|
||||
self.validating_lock.acquire()
|
||||
info = self._get_info_from_url()
|
||||
self.validating_lock.release()
|
||||
|
||||
@ -232,7 +235,7 @@ class URLItem(BaseItem):
|
||||
return display
|
||||
|
||||
def format_short_string(self):
|
||||
return self.title if self.title else self.url
|
||||
return self.title if self.title.strip() else self.url
|
||||
|
||||
def display_type(self):
|
||||
return constants.strings("url")
|
||||
|
@ -347,7 +347,7 @@ class MumbleBot:
|
||||
break
|
||||
else:
|
||||
var.playlist.remove_by_id(next.id)
|
||||
var.library.delete(next.item())
|
||||
var.library.delete(next.id)
|
||||
|
||||
|
||||
# =======================
|
||||
@ -407,7 +407,7 @@ class MumbleBot:
|
||||
self.send_msg(constants.strings('download_in_progress', item=current.format_short_string()))
|
||||
else:
|
||||
var.playlist.remove_by_id(current.id)
|
||||
var.library.delete(current.item())
|
||||
var.library.delete(current.id)
|
||||
else:
|
||||
self._loop_status = 'Empty queue'
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user