From f0dec94a60fe4ea392f655878880af801eac6c09 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Fri, 29 Mar 2024 21:05:26 +0300 Subject: [PATCH] Fixes --- app/DownloadQueue.py | 39 +++++++++++++++++++++------------------ app/main.py | 4 ++-- frontend/src/App.vue | 13 +++++++++++++ 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/app/DownloadQueue.py b/app/DownloadQueue.py index 6902d67d..f2dcdae0 100644 --- a/app/DownloadQueue.py +++ b/app/DownloadQueue.py @@ -41,7 +41,8 @@ class DownloadQueue: LOG.info(f'Using {self.config.max_workers} workers for downloading.') asyncio.create_task( - self.__download_pool() if self.config.max_workers > 1 else self.__download() + self.__download_pool() if self.config.max_workers > 1 else self.__download(), + name='download_pool' if self.config.max_workers > 1 else 'download_worker' ) async def __add_entry( @@ -172,7 +173,9 @@ class DownloadQueue: itemDownload = self.queue.put(dlInfo) self.event.set() - asyncio.create_task(self.notifier.emit(NotifyEvent, itemDownload.info)) + asyncio.create_task( + self.notifier.emit(NotifyEvent, itemDownload.info), + name=f'notifier-{NotifyEvent}-{itemDownload.info.id}') return { 'status': 'ok' @@ -227,16 +230,15 @@ class DownloadQueue: started = time.perf_counter() LOG.debug(f'extract_info: checking {url=}') - with ThreadPoolExecutor(1) as executor: - entry = await asyncio.wait_for( - fut=asyncio.get_running_loop().run_in_executor( - executor, - ExtractInfo, - mergeConfig(self.config.ytdl_options, ytdlp_config), - url, - bool(self.config.ytdl_debug) - ), - timeout=self.config.extract_info_timeout) + entry = await asyncio.wait_for( + fut=asyncio.get_running_loop().run_in_executor( + None, + ExtractInfo, + mergeConfig(self.config.ytdl_options, ytdlp_config), + url, + bool(self.config.ytdl_debug) + ), + timeout=self.config.extract_info_timeout) if not entry: return {'status': 'error', 'msg': 'Unable to extract info check logs.'} @@ -277,17 +279,18 @@ class DownloadQueue: itemMessage = f"{id=} {item.info.id=} {item.info.title=}" - if item.started() is True: + if item.running(): LOG.debug(f'Canceling {itemMessage}') item.cancel() LOG.info(f'Cancelled {itemMessage}') + item.close() else: item.close() LOG.debug(f'Deleting from queue {itemMessage}') self.queue.delete(id) - asyncio.create_task(self.notifier.canceled(id)) + asyncio.create_task(self.notifier.canceled(id), name=f'notifier-c-{id}') self.done.put(item) - asyncio.create_task(self.notifier.completed(item)) + asyncio.create_task(self.notifier.completed(item), name=f'notifier-d-{id}') LOG.info(f'Deleted from queue {itemMessage}') status[id] = 'ok' @@ -309,7 +312,7 @@ class DownloadQueue: itemMessage = f"{id=} {item.info.id=} {item.info.title=}" LOG.debug(f'Deleting completed download {itemMessage}') self.done.delete(id) - asyncio.create_task(self.notifier.cleared(id)) + asyncio.create_task(self.notifier.cleared(id), name=f'notifier-c-{id}') LOG.info(f'Deleted completed download {itemMessage}') status[id] = 'ok' @@ -408,12 +411,12 @@ class DownloadQueue: self.queue.delete(key=id) if entry.is_canceled() is True: - asyncio.create_task(self.notifier.canceled(id)) + asyncio.create_task(self.notifier.canceled(id), name=f'notifier-c-{id}') entry.info.status = 'canceled' entry.info.error = 'Canceled by user.' self.done.put(value=entry) - asyncio.create_task(self.notifier.completed(entry.info)) + asyncio.create_task(self.notifier.completed(entry.info), name=f'notifier-d-{id}') self.event.set() diff --git a/app/main.py b/app/main.py index 65cc68f1..5e5a4edc 100644 --- a/app/main.py +++ b/app/main.py @@ -106,6 +106,7 @@ class Main: self.start() def start(self): + start: str = f'YTPTube v{self.config.version} - listening on http://{self.config.host}:{self.config.port}' web.run_app( self.app, host=self.config.host, @@ -113,8 +114,7 @@ class Main: reuse_port=True, loop=self.loop, access_log=None, - print=lambda _: print( - f'YTPTube v{self.config.version} - listening on http://{self.config.host}:{self.config.port}'), + print=lambda _: LOG.info(start) ) async def connect(self, sid, _): diff --git a/frontend/src/App.vue b/frontend/src/App.vue index cf1b2d52..9e836951 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -148,6 +148,19 @@ const deleteItem = (type, item) => { headers: { 'Content-Type': 'application/json' } + }).then(resp => resp.json()).then(json => { + for (const key in items) { + const itemId = items[key]; + if (itemId in json && json[itemId] === 'ok') { + if (true === (itemId in completed)) { + delete completed[itemId]; + } + if (true === (itemId in downloading)) { + toast.info('Download canceled: ' + downloading[itemId]?.title); + delete downloading[itemId]; + } + } + } }).catch((error) => { console.log(error); toast.error('Failed to delete/cancel item/s. ' + error);