[exhentai] restore limit config (#1487)

This partially reverts commit e9ec91c8
This commit is contained in:
Renan Vedovato Traba
2021-04-22 16:21:41 -03:00
committed by GitHub
parent cb86bb9cc9
commit 9322c5e43b
3 changed files with 56 additions and 0 deletions

View File

@@ -920,6 +920,20 @@ Description
Minimum wait time in seconds before API requests.
extractor.exhentai.limits
-------------------------
Type
``bool`` or ``integer``
Default
``true``
Description
Check image download limits
and stop extraction when they are exceeded.
If this value is an ``integer``, it gets used as the limit maximum
instead of the value listed on ``https://e-hentai.org/home.php``
extractor.exhentai.domain
-------------------------
Type

View File

@@ -80,6 +80,7 @@
"username": null,
"password": null,
"domain": "auto",
"limits": true,
"metadata": false,
"original": true,
"sleep-request": 5.0

View File

@@ -43,8 +43,17 @@ class ExhentaiExtractor(Extractor):
self.cookiedomain = "." + domain
Extractor.__init__(self, match)
self.limits = self.config("limits", True)
self.original = self.config("original", True)
if type(self.limits) is int:
self._limit_max = self.limits
self.limits = True
else:
self._limit_max = 0
self._remaining = 0
self.session.headers["Referer"] = self.root + "/"
if version != "ex":
self.session.cookies.set("nw", "1", domain=self.cookiedomain)
@@ -69,6 +78,7 @@ class ExhentaiExtractor(Extractor):
self.log.info("no username given; using e-hentai.org")
self.root = "https://e-hentai.org"
self.original = False
self.limits = False
self.session.cookies["nw"] = "1"
@cache(maxage=90*24*3600, keyarg=1)
@@ -204,6 +214,8 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
(self.image_from_page(ipage),), self.images_from_api())
for url, image in images:
data.update(image)
if self.limits:
self._check_limits(data)
if "/fullimg.php" in url:
data["extension"] = ""
data["_http_validate"] = _validate_response
@@ -369,6 +381,35 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
raise exception.NotFoundError("image page")
return page
def _check_limits(self, data):
if not self._remaining or data["num"] % 25 == 0:
self._update_limits()
self._remaining -= data["cost"]
if self._remaining <= 0:
ExhentaiExtractor.LIMIT = True
url = "{}/s/{}/{}-{}".format(
self.root, data["image_token"], self.gallery_id, data["num"])
raise exception.StopExtraction(
"Image limit reached! Continue with '%s' "
"as URL after resetting it.", url)
def _update_limits(self):
url = "https://e-hentai.org/home.php"
cookies = {
cookie.name: cookie.value
for cookie in self.session.cookies
if cookie.domain == self.cookiedomain and cookie.name != "igneous"
}
page = self.request(url, cookies=cookies).text
current, pos = text.extract(page, "<strong>", "</strong>")
maximum, pos = text.extract(page, "<strong>", "</strong>", pos)
if self._limit_max:
maximum = self._limit_max
self.log.debug("Image Limits: %s/%s", current, maximum)
self._remaining = text.parse_int(maximum) - text.parse_int(current)
@staticmethod
def _parse_image_info(url):
for part in url.split("/")[4:]: