Skip to content

Commit

Permalink
Fix non-latin folder and file names
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Oct 20, 2021
1 parent 3f33393 commit 40622d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ def download(
return

if gdrive_file_id and is_gdrive_download_link:
m = re.search('filename="(.*)"', res.headers["Content-Disposition"])
content_disposition = six.moves.urllib_parse.unquote(
res.headers["Content-Disposition"]
)
m = re.search(r"filename\*=UTF-8''(.*)", content_disposition)
filename_from_url = m.groups()[0]
else:
filename_from_url = osp.basename(url)
Expand Down
9 changes: 6 additions & 3 deletions gdown/download_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,15 @@ def parse_google_drive_file(folder, content, use_cookies=True):
folder_contents = [] if folder_arr[0] is None else folder_arr[0]

gdrive_file = GoogleDriveFile(
id=folder[39:],
name=folder_soup.title.contents[0][:-15],
id=folder.split("/")[-1],
name=" - ".join(folder_soup.title.contents[0].split(" - ")[:-1]),
type=folder_type,
)

id_name_type_iter = ((e[0], e[2], e[3]) for e in folder_contents)
id_name_type_iter = [
(e[0], e[2].encode("raw_unicode_escape").decode("utf-8"), e[3])
for e in folder_contents
]

return gdrive_file, id_name_type_iter

Expand Down

0 comments on commit 40622d8

Please sign in to comment.