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

Fix proxy usage in quiet mode #370

Open
wants to merge 1 commit into
base: main
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
6 changes: 4 additions & 2 deletions gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ def _get_modified_time_from_response(response):
return email.utils.parsedate_to_datetime(raw)


def _get_session(proxy, use_cookies, user_agent, return_cookies_file=False):
def _get_session(proxy, use_cookies, user_agent, return_cookies_file=False, quiet=False):
sess = requests.session()

sess.headers.update({"User-Agent": user_agent})

if proxy is not None:
sess.proxies = {"http": proxy, "https": proxy}
print("Using proxy:", proxy, file=sys.stderr)
if not quiet:
print("Using proxy:", proxy, file=sys.stderr)

# Load cookies if exists
cookies_file = osp.join(home, ".cache/gdown/cookies.txt")
Expand Down Expand Up @@ -188,6 +189,7 @@ def download(
use_cookies=use_cookies,
user_agent=user_agent,
return_cookies_file=True,
quiet=quiet
)

gdrive_file_id, is_gdrive_download_link = parse_url(url, warning=not fuzzy)
Expand Down
2 changes: 1 addition & 1 deletion gdown/download_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def download_folder(
# We need to use different user agent for folder download c.f., file
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36" # NOQA: E501

sess = _get_session(proxy=proxy, use_cookies=use_cookies, user_agent=user_agent)
sess = _get_session(proxy=proxy, use_cookies=use_cookies, user_agent=user_agent, quiet=quiet)

if not quiet:
print("Retrieving folder contents", file=sys.stderr)
Expand Down