From 3d4d7885ec4e88b8fa9e9f55824d210a7102a23b Mon Sep 17 00:00:00 2001 From: William Culhane Date: Tue, 31 Dec 2024 22:29:55 -0600 Subject: [PATCH] Add download progress bar with tqdm --- legendary/downloader/mp/manager.py | 15 +++++---------- requirements.txt | 1 + setup.py | 3 ++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/legendary/downloader/mp/manager.py b/legendary/downloader/mp/manager.py index 90ab37a3..02892c4d 100644 --- a/legendary/downloader/mp/manager.py +++ b/legendary/downloader/mp/manager.py @@ -13,6 +13,7 @@ from queue import Empty from sys import exit from threading import Condition, Thread +from tqdm import tqdm from legendary.downloader.mp.workers import DLWorker, FileWorker from legendary.models.downloading import * @@ -705,6 +706,8 @@ def run_real(self): last_update = time.time() + progress_bar = tqdm(total=num_chunk_tasks, unit="chunk", dynamic_ncols=True) + while processed_tasks < num_tasks: delta = time.time() - last_update if not delta: @@ -747,16 +750,7 @@ def run_real(self): hours = minutes = seconds = 0 rt_hours = rt_minutes = rt_seconds = 0 - self.log.info(f'= Progress: {perc:.02f}% ({processed_chunks}/{num_chunk_tasks}), ' - f'Running for {rt_hours:02d}:{rt_minutes:02d}:{rt_seconds:02d}, ' - f'ETA: {hours:02d}:{minutes:02d}:{seconds:02d}') - self.log.info(f' - Downloaded: {total_dl / 1024 / 1024:.02f} MiB, ' - f'Written: {total_write / 1024 / 1024:.02f} MiB') - self.log.info(f' - Cache usage: {total_used:.02f} MiB, active tasks: {self.active_tasks}') - self.log.info(f' + Download\t- {dl_speed / 1024 / 1024:.02f} MiB/s (raw) ' - f'/ {dl_unc_speed / 1024 / 1024:.02f} MiB/s (decompressed)') - self.log.info(f' + Disk\t- {w_speed / 1024 / 1024:.02f} MiB/s (write) / ' - f'{r_speed / 1024 / 1024:.02f} MiB/s (read)') + progress_bar.update(processed_chunks) # send status update to back to instantiator (if queue exists) if self.status_queue: @@ -770,6 +764,7 @@ def run_real(self): time.sleep(self.update_interval) + progress_bar.close() for i in range(self.max_workers): self.dl_worker_queue.put_nowait(TerminateWorkerTask()) diff --git a/requirements.txt b/requirements.txt index 481d0450..bf672259 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ requests<3.0 filelock +tqdm==4.67.1 diff --git a/setup.py b/setup.py index d4f7e051..ce84e018 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,8 @@ 'requests<3.0', 'setuptools', 'wheel', - 'filelock' + 'filelock', + 'tqdm==4.67.1' ], extras_require=dict( webview=['pywebview>=3.4'],