-
Notifications
You must be signed in to change notification settings - Fork 7.1k
resolve redirection for HTTP resources #5151
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
Changes from all commits
eea25cc
d47990f
383e693
c372606
cb4d9aa
0417f01
d573acc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
extract_archive, | ||
_decompress, | ||
download_file_from_google_drive, | ||
_get_redirect_url, | ||
_get_google_drive_file_id, | ||
) | ||
|
||
|
||
|
@@ -134,9 +136,41 @@ def __init__( | |
super().__init__(file_name=file_name or pathlib.Path(urlparse(url).path).name, **kwargs) | ||
self.url = url | ||
self.mirrors = mirrors | ||
self._resolved = False | ||
|
||
def resolve(self) -> OnlineResource: | ||
if self._resolved: | ||
return self | ||
|
||
redirect_url = _get_redirect_url(self.url) | ||
if redirect_url == self.url: | ||
self._resolved = True | ||
return self | ||
|
||
meta = { | ||
attr.lstrip("_"): getattr(self, attr) | ||
for attr in ( | ||
"file_name", | ||
"sha256", | ||
"_preprocess", | ||
"_loader", | ||
) | ||
} | ||
|
||
gdrive_id = _get_google_drive_file_id(redirect_url) | ||
if gdrive_id: | ||
return GDriveResource(gdrive_id, **meta) | ||
|
||
http_resource = HttpResource(redirect_url, **meta) | ||
http_resource._resolved = True | ||
return http_resource | ||
NicolasHug marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def _download(self, root: pathlib.Path) -> None: | ||
if not self._resolved: | ||
return self.resolve()._download(root) | ||
|
||
for url in itertools.chain((self.url,), self.mirrors): | ||
|
||
try: | ||
download_url(url, str(root), filename=self.file_name, md5=None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In your first comment you wrote
Could we instead do the redirection here and handle the mirrors? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, but that would make stuff more complicated. Given that the plan is to refactor this anyway with |
||
# TODO: make this more precise | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have current cases where an HTTP resource redirects to a Google drive?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It is one of the datasets not yet ported to prototype. I've also hit this while doing #5154.