Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature: show progress bar when downloading #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ requests>=0.10
pycryptodome>=3.9.6,<4.0.0
pathlib==1.0.1
tenacity>=5.1.5,<6.0.0
tqdm
6 changes: 6 additions & 0 deletions src/mega/mega.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import binascii
import tempfile
import shutil
from tqdm import *

import requests
from tenacity import retry, wait_exponential, retry_if_exception_type
Expand Down Expand Up @@ -694,6 +695,9 @@ def _download_file(self,

input_file = requests.get(file_url, stream=True).raw

total_size_in_bytes= int(input_file.headers.get('content-length', 0))
progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True)

if dest_path is None:
dest_path = ''
else:
Expand All @@ -715,6 +719,7 @@ def _download_file(self,
for chunk_start, chunk_size in get_chunks(file_size):
chunk = input_file.read(chunk_size)
chunk = aes.decrypt(chunk)
progress_bar.update(chunk_size)
temp_output_file.write(chunk)

encryptor = AES.new(k_str, AES.MODE_CBC, iv_str)
Expand All @@ -736,6 +741,7 @@ def _download_file(self,
file_info = os.stat(temp_output_file.name)
logger.info('%s of %s downloaded', file_info.st_size,
file_size)
progress_bar.close()
file_mac = str_to_a32(mac_str)
# check mac integrity
if (file_mac[0] ^ file_mac[1],
Expand Down