fix: delete item keyerror #91
This commit is contained in:
@ -86,7 +86,8 @@ class BaseItem:
|
||||
return ""
|
||||
|
||||
def send_client_message(self, msg):
|
||||
self.bot.send_msg(msg)
|
||||
if self.bot:
|
||||
self.bot.send_msg(msg)
|
||||
|
||||
def to_dict(self):
|
||||
return {"type" : "base", "id": self.id, "ready": self.ready, "path": self.path, "tags": self.tags}
|
||||
|
@ -73,18 +73,22 @@ 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):
|
||||
self.log.debug("library: DELETE item from the database: %s" % item.format_debug_string())
|
||||
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:
|
||||
if item.path in self.file_id_lookup:
|
||||
del self.file_id_lookup[item.path]
|
||||
self.files.remove(item.path)
|
||||
self.save_dir_cache()
|
||||
if item.type == 'file' and item.path in self.file_id_lookup:
|
||||
if item.path in self.file_id_lookup:
|
||||
del self.file_id_lookup[item.path]
|
||||
self.files.remove(item.path)
|
||||
self.save_dir_cache()
|
||||
|
||||
if item.id in self:
|
||||
del self[item.id]
|
||||
self.db.delete_music(id=item.id)
|
||||
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):
|
||||
for i in range(current_index):
|
||||
_list.pop()
|
||||
return super().from_list(_list, -1)
|
||||
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")
|
||||
|
Reference in New Issue
Block a user