Skip to content
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()
Comment thread
mirusu400 marked this conversation as resolved.
Outdated
length = int(r.headers.get('content-length'))
Comment thread
mirusu400 marked this conversation as resolved.
Outdated
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
Comment thread
mirusu400 marked this conversation as resolved.
Outdated
f.write(r.content)
Comment thread
mirusu400 marked this conversation as resolved.
Outdated
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