0
>>> 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?

Daviid
  • 630
  • 4
  • 17
  • Why are you using `subprocess` for specific hosts? you can also use `requests.get('https://mega.nz/file....')`. no? – Danila Ganchar Jul 24 '23 at 13:05
  • 1
    Mega uses end-to-end encryption, is not as straight forward to download as regular file downloads. I could probably recreate the encryption/decryption with python but why would I do that if there already exists mega-cmd. – Daviid Jul 24 '23 at 15:52
  • 1
    @DanilaGanchar actually, I was looking at MEGAcmd which is a higher level implementation of Mega-sdk and this might be useful to me, https://github.com/meganz/sdk/blob/master/examples/python/megacli.py – Daviid Jul 24 '23 at 15:54
  • I see the repository is using [mega.py](https://pypi.org/project/mega.py/) package. So I think you can use `mega = Mega() mega.login() mega.download(file)` + [threading](https://docs.python.org/3/library/threading.html). no? – Danila Ganchar Jul 25 '23 at 08:15
  • 1
    What I linked is the official SDK/Client from Mega.nz.co, what you linked is a repository which is no longer maintained and links to the one I posted. My problem is still the fact that once the download starts it doesn't seem possible to get the progress of the download. – Daviid Jul 25 '23 at 08:28
  • I understand. The idea was to use `threads` instead of `processes`. You can try to [read stdout](https://stackoverflow.com/questions/18421757/live-output-from-subprocess-command). – Danila Ganchar Jul 25 '23 at 09:36

0 Answers0