Skip to content

Commit

Permalink
[imgbb] improve redirect handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Apr 20, 2020
1 parent 6cc800a commit 9219141
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions gallery_dl/extractor/imgbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ def __init__(self, match):

def items(self):
self.login()
response = self.request(self.page_url, params={"sort": self.sort})
if response.history and response.url.startswith(self.root):
raise exception.NotFoundError(self.subcategory)

url = self.page_url
params = {"sort": self.sort}
while True:
response = self.request(url, params=params, allow_redirects=False)
if response.status_code < 300:
break
url = response.headers["location"]
if url.startswith(self.root):
raise exception.NotFoundError(self.subcategory)

page = response.text
data = self.metadata(page)
first = True
Expand Down Expand Up @@ -151,12 +159,15 @@ def metadata(self, page):
}

def images(self, page):
url = text.extract(page, '"og:url" content="', '"')[0]
album_id = url.rpartition("/")[2].partition("?")[0]

return self._pagination(page, "https://ibb.co/json", {
"from" : "album",
"albumid" : self.album_id,
"albumid" : album_id,
"params_hidden[list]" : "images",
"params_hidden[from]" : "album",
"params_hidden[albumid]": self.album_id,
"params_hidden[albumid]": album_id,
})


Expand Down

0 comments on commit 9219141

Please sign in to comment.