From 050012a1b2dbfdd6e445d27d3a4a2a09fbff4e5f Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Fri, 29 Mar 2024 00:56:09 +0300 Subject: [PATCH] some fixes to downloader. --- app/Download.py | 8 ++++++-- app/DownloadQueue.py | 23 ++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/Download.py b/app/Download.py index c8bcaeaa..b86d8e23 100644 --- a/app/Download.py +++ b/app/Download.py @@ -278,15 +278,19 @@ class Download: """ while True: 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 + if status.get('id') != self.id or len(status) < 2: + continue + if self.debug: LOG.debug(f'Status Update: {self.info._id=} {status=}') if isinstance(status, str): asyncio.create_task(self.notifier.updated(self.info)) - return + continue self.tmpfilename = status.get('tmpfilename') diff --git a/app/DownloadQueue.py b/app/DownloadQueue.py index 11ffbf57..6902d67d 100644 --- a/app/DownloadQueue.py +++ b/app/DownloadQueue.py @@ -388,19 +388,20 @@ class DownloadQueue: async def __downloadFile(self, id: str, entry: Download): 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.tmpfilename and os.path.isfile(entry.tmpfilename): - try: - os.remove(entry.tmpfilename) - entry.tmpfilename = None - except: - pass + if entry.info.status != 'finished': + if entry.tmpfilename and os.path.isfile(entry.tmpfilename): + try: + os.remove(entry.tmpfilename) + entry.tmpfilename = None + except: + pass - entry.info.status = 'error' - - entry.close() + entry.info.status = 'error' + finally: + entry.close() if self.queue.exists(key=id):