Skip to content

Commit

Permalink
Merge pull request #6201 from ales-erjavec/io-google-drive
Browse files Browse the repository at this point in the history
[ENH] io.UrlReader: Add support for google drive share urls
  • Loading branch information
VesnaT authored Nov 21, 2022
2 parents 0d3e3ee + 955a38d commit 90af889
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit 90af889

Please sign in to comment.