feat: 'delete' command to remove files from library
This commit is contained in:
@ -80,7 +80,7 @@ class MusicCache(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, id):
|
||||
def free_and_delete(self, id):
|
||||
item = self.get_item_by_id(None, id)
|
||||
if item:
|
||||
self.log.debug("library: DELETE item from the database: %s" % item.format_debug_string())
|
||||
|
@ -110,6 +110,6 @@ class BaseItem:
|
||||
self.bot.send_msg(msg)
|
||||
|
||||
def to_dict(self):
|
||||
return {"type" : "base", "id": self.id, "ready": self.ready, "path": self.path, "tags": self.tags}
|
||||
return {"type" : self.type, "id": self.id, "ready": self.ready, "path": self.path, "tags": self.tags}
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@ import random
|
||||
import threading
|
||||
import logging
|
||||
import random
|
||||
import time
|
||||
|
||||
import variables as var
|
||||
from media.file import FileItem
|
||||
@ -325,6 +326,7 @@ class BasePlaylist(list):
|
||||
|
||||
def start_async_validating(self):
|
||||
if not self.validating_thread_lock.locked():
|
||||
time.sleep(0.1) # Just avoid validation finishes too fast and delete songs while something is reading it.
|
||||
th = threading.Thread(target=self._check_valid, name="Validating")
|
||||
th.daemon = True
|
||||
th.start()
|
||||
@ -337,7 +339,7 @@ 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.cache.delete(item.id)
|
||||
var.cache.free_and_delete(item.id)
|
||||
self.remove_by_id(item.id)
|
||||
|
||||
self.log.debug("playlist: validating finished.")
|
||||
|
@ -83,7 +83,7 @@ def get_radio_title(url):
|
||||
requests.exceptions.Timeout) as e:
|
||||
error_traceback = traceback.format_exc()
|
||||
error = error_traceback.rstrip().split("\n")[-1]
|
||||
log.debug("radio: unsuccessful attempts on fetching radio title (icy): " + e)
|
||||
log.debug("radio: unsuccessful attempts on fetching radio title (icy): " + error)
|
||||
return url
|
||||
|
||||
|
||||
|
@ -224,7 +224,7 @@ class URLItem(BaseItem):
|
||||
def format_song_string(self, user):
|
||||
if self.ready in ['validated', 'yes']:
|
||||
return constants.strings("url_item",
|
||||
title=self.title,
|
||||
title=self.title if self.title else "??",
|
||||
url=self.url,
|
||||
user=user)
|
||||
return self.url
|
||||
|
Reference in New Issue
Block a user