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

Provide the ability to customize which tqdm object is used #389

Open
wants to merge 1 commit into
base: main
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
11 changes: 9 additions & 2 deletions gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import bs4
import requests
import tqdm

from ._indent import indent
from .exceptions import FileURLRetrievalError
Expand Down Expand Up @@ -124,6 +123,8 @@ def download(
format=None,
user_agent=None,
log_messages=None,
*,
tqdm=None
):
"""Download file from URL.

Expand Down Expand Up @@ -165,6 +166,9 @@ def download(
Log messages to customize. Currently it supports:
- 'start': the message to show the start of the download
- 'output': the message to show the output filename
tqdm: tqdm-like
A tqdm-like object to help report progress. If not provided
the default terminal based progress bar will be used.

Returns
-------
Expand Down Expand Up @@ -363,7 +367,10 @@ def download(
if total is not None:
total = int(total) + start_size
if not quiet:
pbar = tqdm.tqdm(total=total, unit="B", initial=start_size, unit_scale=True)
if tqdm is None:
# Use the default terminal based progress bar
from tqdm import tqdm
pbar = tqdm(total=total, unit="B", initial=start_size, unit_scale=True)
t_start = time.time()
for chunk in res.iter_content(chunk_size=CHUNK_SIZE):
f.write(chunk)
Expand Down
Loading