some fixes to downloader.

This commit is contained in:
ArabCoders 2024-03-29 00:56:09 +03:00
parent 3c84741e8a
commit 050012a1b2
2 changed files with 18 additions and 13 deletions

View file

@ -278,15 +278,19 @@ class Download:
""" """
while True: while True:
status = await self.loop.run_in_executor(None, self.status_queue.get) status = await self.loop.run_in_executor(None, self.status_queue.get)
if status.get('id') != self.id or len(status) < 2:
if status is None:
return return
if status.get('id') != self.id or len(status) < 2:
continue
if self.debug: if self.debug:
LOG.debug(f'Status Update: {self.info._id=} {status=}') LOG.debug(f'Status Update: {self.info._id=} {status=}')
if isinstance(status, str): if isinstance(status, str):
asyncio.create_task(self.notifier.updated(self.info)) asyncio.create_task(self.notifier.updated(self.info))
return continue
self.tmpfilename = status.get('tmpfilename') self.tmpfilename = status.get('tmpfilename')

View file

@ -388,19 +388,20 @@ class DownloadQueue:
async def __downloadFile(self, id: str, entry: Download): async def __downloadFile(self, id: str, entry: Download):
LOG.info(f'Queuing {id=} - {entry.info.title=} - {entry.info.url=} - {entry.info.folder=}.') LOG.info(f'Queuing {id=} - {entry.info.title=} - {entry.info.url=} - {entry.info.folder=}.')
await entry.start(self.notifier) try:
await entry.start(self.notifier)
if entry.info.status != 'finished': if entry.info.status != 'finished':
if entry.tmpfilename and os.path.isfile(entry.tmpfilename): if entry.tmpfilename and os.path.isfile(entry.tmpfilename):
try: try:
os.remove(entry.tmpfilename) os.remove(entry.tmpfilename)
entry.tmpfilename = None entry.tmpfilename = None
except: except:
pass pass
entry.info.status = 'error' entry.info.status = 'error'
finally:
entry.close() entry.close()
if self.queue.exists(key=id): if self.queue.exists(key=id):