Skip to content

Commit

Permalink
Merge pull request #5 from n374/master
Browse files Browse the repository at this point in the history
Fix KeyError when proxy not set
  • Loading branch information
hwfan authored Jun 29, 2022
2 parents b64a3ff + 95a4637 commit 418469c
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions DriveDownloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
TimeRemainingColumn(),
refresh_per_second=10
)
url_scheme_env_key_map = {
"http": "http_proxy",
"https": "https_proxy",
}

def parse_args():
parser = argparse.ArgumentParser(description='Drive Downloader Args')
Expand All @@ -59,22 +63,19 @@ def parse_args():
args = parser.parse_args()
return args

def get_env(key):
value = os.environ.get(key)
if not value or len(value) == 0:
return None
return value;

def download_single_file(url, filename="", thread_number=1, force_back_google=False, list_suffix=None):
scheme = judge_scheme(url)
if scheme == 'http':
if len(os.environ["http_proxy"]) > 0:
proxy = os.environ["http_proxy"]
else:
proxy = None
elif scheme == 'https':
if len(os.environ["https_proxy"]) > 0:
proxy = os.environ["https_proxy"]
else:
proxy = None
else:
if scheme not in url_scheme_env_key_map.keys():
raise NotImplementedError(f"Unsupported scheme {scheme}")
used_proxy = proxy

env_key = url_scheme_env_key_map[scheme]
used_proxy = get_env(env_key)

session_name = judge_session(url)
session_func = get_session(session_name)
google_fix_logic = False
Expand All @@ -93,7 +94,7 @@ def download_single_file(url, filename="", thread_number=1, force_back_google=Fa
download_session = MultiThreadDownloader(progress_applied, session_func, used_proxy, download_session.filesize, thread_number)
interrupted = download_session.get(url, final_filename, force_back_google)
if interrupted:
return
return
download_session.concatenate(final_filename)
else:
with progress_applied:
Expand Down

0 comments on commit 418469c

Please sign in to comment.