1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

[exhentai] use image-count as stop signal

This commit is contained in:
Mike Fährmann 2016-10-12 15:19:31 +02:00
parent 607f50effb
commit 492cb38391
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -31,7 +31,7 @@ class ExhentaiGalleryExtractor(Extractor):
def __init__(self, match):
Extractor.__init__(self)
self.key = {}
self.url = match.group(0)
self.count = 0
self.gid, self.token = match.groups()
self.original = config.interpolate(("extractor", "exhentai", "download-original"), True)
self.wait_min = config.interpolate(("extractor", "exhentai", "wait-min"), 3)
@ -45,10 +45,12 @@ class ExhentaiGalleryExtractor(Extractor):
yield Message.Headers, self.setup_headers()
yield Message.Cookies, self.session.cookies
page = self.request(self.url).text
url = "https://exhentai.org/g/{}/{}/".format(self.gid, self.token)
page = self.request(url).text
if page.startswith(("Key missing", "Gallery not found")):
raise exception.NotFoundError("gallery")
data = self.get_job_metadata(page)
self.count = int(data["count"])
yield Message.Directory, data
for url, image in self.get_images(page):
@ -120,27 +122,21 @@ class ExhentaiGalleryExtractor(Extractor):
def images_from_api(self):
"""Get image url and data from api calls"""
imgkey = self.key["start"]
nextkey = self.key["next" ]
request = {
"method" : "showpage",
"page" : 2,
"gid" : int(self.gid),
"imgkey" : nextkey,
"showkey": self.key["show"],
}
while True:
if imgkey == nextkey:
return
self.wait()
for request["page"] in range(2, self.count+1):
while True:
try:
self.wait()
page = self.session.post(self.api_url, json=request).json()
break
except requests.exceptions.ConnectionError as e:
self.wait((5, 10))
except requests.exceptions.ConnectionError:
pass
imgkey = nextkey
nextkey, pos = text.extract(page["i3"], "'", "'")
imgurl , pos = text.extract(page["i3"], '<img id="img" src="', '"', pos)
@ -151,7 +147,6 @@ class ExhentaiGalleryExtractor(Extractor):
"image-token": imgkey
})
request["imgkey"] = nextkey
request["page"] += 1
def wait(self, waittime=None):
"""Wait for a randomly chosen amount of seconds"""