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

Display progress while downloading #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions epic_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import sys
import warnings
from tqdm import tqdm

try:
import urllib.request
Expand Down Expand Up @@ -69,11 +70,22 @@ def download_file(url, output_path):

try:
with urllib.request.urlopen(url) as response, open(output_path, 'wb') as output_file:

total_size = int(response.info().get('Content-Length', 0))
block_size = 8192

print('Downloading\nfrom {}\nto {}'.format(url, output_path))
shutil.copyfileobj(response, output_file)
except Exception as e:
print('Could not download file from {}\nError: {}'.format(url, str(e)))
with tqdm(total=total_size, unit='B', unit_scale=True, desc=f'{os.path.basename(output_path)}') as pbar:
while True:
buffer = response.read(block_size)
if not buffer:
break

output_file.write(buffer)
pbar.update(len(buffer))

except Exception as e:
print(f'Could not download file from {url}\nError: {str(e)}')
@staticmethod
def parse_bool(b):
return b.lower().strip() in ['true', 'yes', 'y']
Expand Down