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 tqdm module #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions transferwee.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"""

from typing import List
from tqdm import tqdm
import os.path
import re
import urllib.parse
Expand Down Expand Up @@ -134,9 +135,19 @@ def download(url: str, file: str = '') -> None:
file = _file_unquote(urllib.parse.urlparse(dl_url).path.split('/')[-1])

r = requests.get(dl_url, stream=True)
r.raise_for_status()
mirusu400 marked this conversation as resolved.
Show resolved Hide resolved
length = int(r.headers.get('content-length'))
mirusu400 marked this conversation as resolved.
Show resolved Hide resolved
with open(file, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
f.write(chunk)
if r is None: # no content length header
mirusu400 marked this conversation as resolved.
Show resolved Hide resolved
f.write(r.content)
mirusu400 marked this conversation as resolved.
Show resolved Hide resolved
else:
dl = 0
progress_bar = tqdm(total=length, unit='iB', unit_scale=True)
for data in r.iter_content(chunk_size=1024):
dl += len(data)
f.write(data)
progress_bar.update(len(data))
progress_bar.close()


def _file_name_and_size(file: str) -> dict:
Expand Down