From 633fa5a45e64590b2b45d86fa3c8bfb949f12347 Mon Sep 17 00:00:00 2001 From: Justin Donofrio Date: Tue, 14 Jan 2025 12:33:32 -0500 Subject: [PATCH] Fix web ui progress indicator and improve restart workers. --- src/onthespot/downloader.py | 5 +++-- src/onthespot/resources/web/download_queue.html | 8 +++++++- src/onthespot/web.py | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/onthespot/downloader.py b/src/onthespot/downloader.py index beed354..3bc122d 100644 --- a/src/onthespot/downloader.py +++ b/src/onthespot/downloader.py @@ -349,10 +349,11 @@ def run(self): downloaded += len(data) data_chunks += data - if self.gui and downloaded != total_size: + if downloaded != total_size: if item['item_status'] == 'Cancelled': raise Exception("Download cancelled by user.") - self.progress.emit(item, self.tr("Downloading"), int((downloaded / total_size) * 100)) + if self.gui: + self.progress.emit(item, self.tr("Downloading"), int((downloaded / total_size) * 100)) key = calcbfkey(song["SNG_ID"]) diff --git a/src/onthespot/resources/web/download_queue.html b/src/onthespot/resources/web/download_queue.html index 93dc180..f7812f0 100644 --- a/src/onthespot/resources/web/download_queue.html +++ b/src/onthespot/resources/web/download_queue.html @@ -96,7 +96,7 @@ copyButton = createButton('icons/link.png', 'Copy Link', `copyToClipboard('${item.item_url}')`); } - if (item.item_status === 'Waiting') { + if (!['Failed', 'Cancelled', 'Deleted', 'Already Exists', 'Downloaded'].includes(item.item_status)) { cancelButton = createButton('icons/stop.png', 'Stop Download', `handleCancel('${item.local_id}')`); } @@ -186,7 +186,13 @@ let cancelledCount = 0; for (let row of tableBody.rows) { + + {% if config.show_download_thumbnails %} const statusCell = row.cells[5]; + {% else %} + const statusCell = row.cells[4]; + {% endif %} + if (statusCell) { const statusText = statusCell.textContent.trim(); diff --git a/src/onthespot/web.py b/src/onthespot/web.py index 63b2872..3024b2c 100644 --- a/src/onthespot/web.py +++ b/src/onthespot/web.py @@ -181,6 +181,16 @@ def restart_workers(): download_workers.clear() + item_urls = [] + for key, value in download_queue.items(): + item_urls.append(value.get('item_url')) + + with download_queue_lock: + download_queue.clear() + + for url in item_urls: + parse_url(url) + for i in range(config.get('maximum_download_workers')): download_worker = DownloadWorker() download_worker.start()