Skip to content

Commit

Permalink
Retry with canonicalized url if the original url is not a google driv…
Browse files Browse the repository at this point in the history
…e url
  • Loading branch information
wkentaro committed Jan 26, 2024
1 parent a080c9a commit 579f3dd
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions gdown/download_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .download import _get_session
from .download import download
from .exceptions import FolderContentsMaximumLimitError
from .parse_url import is_google_drive_url

MAX_NUMBER_FILES = 50

Expand Down Expand Up @@ -99,16 +100,26 @@ def _download_and_parse_google_drive_link(

return_code = True

# canonicalize the language into English
if "?" in url:
url += "&hl=en"
else:
url += "?hl=en"
for _ in range(2):
if is_google_drive_url(url):
# canonicalize the language into English
if "?" in url:
url += "&hl=en"
else:
url += "?hl=en"

res = sess.get(url, verify=verify)
if res.status_code != 200:
return False, None

res = sess.get(url, verify=verify)
if is_google_drive_url(url):
break

if not is_google_drive_url(res.url):
break

if res.status_code != 200:
return False, None
# need to try with canonicalized url if the original url redirects to gdrive
url = res.url

gdrive_file, id_name_type_iter = _parse_google_drive_file(
url=url,
Expand Down

0 comments on commit 579f3dd

Please sign in to comment.