>>> import os
>>> import subprocess
>>> process = subprocess.run(["mega-get", "https://mega.nz/file/xxxxx#xxxxxxxxxxxxxxxxxxxx", "./"])
TRANSFERRING ||##################################################################################################################################################||(163/163 MB: 100.00 %)
Download finished: /mnt/downloads/games/./game-pc.zip
TRANSFERRING ||##################################################################################################################################################||(163/163 MB: 100.00 %)
>>> process
CompletedProcess(args=['mega-get', 'https://mega.nz/file/xxxxx#xxxxxxxxxxxxxxxxxxxx', './'], returncode=0)
Once I do subprocess.run I can only watch as the download progresses, I want to use celery to run the download tasks but how would I know what's the progress?
For other hosts I can do this:
total_size = int(response.headers.get('content-length', 0))
downloaded_size = 0
with open(temp_path, "wb") as file:
for chunk in response.iter_content(chunk_size=4096):
if chunk:
file.write(chunk)
downloaded_size += len(chunk)
# Calculate the progress percentage
progress = int((downloaded_size / total_size) * 100)
current_task.update_state(state='PROGRESS', meta={'progress': progress})
Do I just parse the progress bar output? Or is there other ways?