Skip to content

[ENH] io.UrlReader: Add support for google drive share urls #6201

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

Merged
merged 1 commit into from
Nov 21, 2022
Merged
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
13 changes: 13 additions & 0 deletions Orange/data/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def _resolve_redirects(self, url):
def _trim(cls, url):
URL_TRIMMERS = (
cls._trim_googlesheet,
cls._trim_googledrive,
cls._trim_dropbox,
)
for trim in URL_TRIMMERS:
Expand Down Expand Up @@ -488,6 +489,18 @@ def _trim_googlesheet(url):
url += '&gid=' + sheet
return url

@staticmethod
def _trim_googledrive(url):
parts = urlsplit(url)
if not parts.netloc.endswith("drive.google.com"):
raise ValueError
match = re.match(r'/file/d/(?P<id>[^/]+).*', parts.path)
if not match:
raise ValueError
id_ = match.group("id")
parts = parts._replace(path=f"uc?export=download&id={id_}", query=None)
return urlunsplit(parts)

@staticmethod
def _trim_dropbox(url):
parts = urlsplit(url)
Expand Down