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()
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}
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())
-
- 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)
+ 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.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:
for index in to_be_removed:
self.remove(index)
- var.library.free(id)
-
def current_item(self):
if len(self) == 0:
return False
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()
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:
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()
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")
break
else:
var.playlist.remove_by_id(next.id)
- var.library.delete(next.item())
+ var.library.delete(next.id)
# =======================
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: