Skip to content

Commit

Permalink
Add download progress bar with tqdm
Browse files Browse the repository at this point in the history
  • Loading branch information
w-culhane committed Jan 1, 2025
1 parent 3963382 commit 3d4d788
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
15 changes: 5 additions & 10 deletions legendary/downloader/mp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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())

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests<3.0
filelock
tqdm==4.67.1
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
'requests<3.0',
'setuptools',
'wheel',
'filelock'
'filelock',
'tqdm==4.67.1'
],
extras_require=dict(
webview=['pywebview>=3.4'],
Expand Down

0 comments on commit 3d4d788

Please sign in to comment.