change some code that may cause errors

This commit is contained in:
xerdream 2025-08-20 08:19:41 +08:00
parent c4f3468b6c
commit 2b2a2e69f3

View file

@ -33,7 +33,7 @@ class DownloadQueueNotifier:
class DownloadInfo: class DownloadInfo:
def __init__(self, id, title, url, quality, format, folder, custom_name_prefix, error): def __init__(self, id, title, url, quality, format, folder, custom_name_prefix, error):
self.id = id if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{id}' self.id = id if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{id}'
self.id = f'{id}.{format}' self.id = f'{self.id}.{format}'
self.title = title if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{title}' self.title = title if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{title}'
self.url = url self.url = url
self.quality = quality self.quality = quality
@ -205,18 +205,21 @@ class Download:
self.info.filename = filename self.info.filename = filename
def delete_tmpfile(self): def delete_tmpfile(self):
if not self.tmpfilename: if not self.tmpfilename or not self.download_dir:
return return
if not os.path.isdir(self.download_dir):
return
tmpfilename = self.tmpfilename.rsplit('.')[0] tmpfilename = self.tmpfilename.rsplit('.')[0]
def is_tmpfile(filename): def is_tmpfile(filename):
return filename.startswith(tmpfilename) return filename.startswith(tmpfilename)
tmpfiles = filter(is_tmpfile ,os.listdir(self.download_dir))
try: try:
tmpfiles = filter(is_tmpfile, os.listdir(self.download_dir))
for tmpfile in tmpfiles: for tmpfile in tmpfiles:
os.remove(tmpfile) os.remove(os.path.join(self.download_dir, tmpfile))
except: except Exception as e:
pass log.warning(f"Error deleting temporary files: {e}")
class PersistentQueue: class PersistentQueue:
def __init__(self, path): def __init__(self, path):