[exhentai] improve image limits check
- check if current image is the '509 Bandwidth Exceeded' notification (https://ehgt.org/g/509.gif or https://exhentai.org/img/509.gif) - remove 'limits' option
This commit is contained in:
@@ -922,20 +922,6 @@ Description
|
|||||||
* ``"exhentai.org"``: Use ``exhentai.org`` for all URLs
|
* ``"exhentai.org"``: Use ``exhentai.org`` for all URLs
|
||||||
|
|
||||||
|
|
||||||
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.metadata
|
extractor.exhentai.metadata
|
||||||
---------------------------
|
---------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -79,7 +79,6 @@
|
|||||||
"username": null,
|
"username": null,
|
||||||
"password": null,
|
"password": null,
|
||||||
"domain": "auto",
|
"domain": "auto",
|
||||||
"limits": true,
|
|
||||||
"metadata": false,
|
"metadata": false,
|
||||||
"original": true,
|
"original": true,
|
||||||
"sleep-request": 5.0
|
"sleep-request": 5.0
|
||||||
|
|||||||
@@ -43,16 +43,8 @@ class ExhentaiExtractor(Extractor):
|
|||||||
self.cookiedomain = "." + domain
|
self.cookiedomain = "." + domain
|
||||||
|
|
||||||
Extractor.__init__(self, match)
|
Extractor.__init__(self, match)
|
||||||
self.limits = self.config("limits", True)
|
|
||||||
self.original = self.config("original", 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 + "/"
|
self.session.headers["Referer"] = self.root + "/"
|
||||||
if version != "ex":
|
if version != "ex":
|
||||||
self.session.cookies.set("nw", "1", domain=self.cookiedomain)
|
self.session.cookies.set("nw", "1", domain=self.cookiedomain)
|
||||||
@@ -77,7 +69,6 @@ class ExhentaiExtractor(Extractor):
|
|||||||
self.log.info("no username given; using e-hentai.org")
|
self.log.info("no username given; using e-hentai.org")
|
||||||
self.root = "https://e-hentai.org"
|
self.root = "https://e-hentai.org"
|
||||||
self.original = False
|
self.original = False
|
||||||
self.limits = False
|
|
||||||
self.session.cookies["nw"] = "1"
|
self.session.cookies["nw"] = "1"
|
||||||
|
|
||||||
@cache(maxage=90*24*3600, keyarg=1)
|
@cache(maxage=90*24*3600, keyarg=1)
|
||||||
@@ -206,8 +197,6 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
|
|||||||
(self.image_from_page(ipage),), self.images_from_api())
|
(self.image_from_page(ipage),), self.images_from_api())
|
||||||
for url, image in images:
|
for url, image in images:
|
||||||
data.update(image)
|
data.update(image)
|
||||||
if self.limits:
|
|
||||||
self._check_limits(data)
|
|
||||||
if "/fullimg.php" in url:
|
if "/fullimg.php" in url:
|
||||||
data["extension"] = ""
|
data["extension"] = ""
|
||||||
yield Message.Url, url, data
|
yield Message.Url, url, data
|
||||||
@@ -299,6 +288,8 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
|
|||||||
data["image_token"] = self.key["start"] = extr('var startkey="', '";')
|
data["image_token"] = self.key["start"] = extr('var startkey="', '";')
|
||||||
self.key["show"] = extr('var showkey="', '";')
|
self.key["show"] = extr('var showkey="', '";')
|
||||||
|
|
||||||
|
if iurl.endswith("g/509.gif"):
|
||||||
|
self._report_limits(data)
|
||||||
return url, text.nameext_from_url(iurl, data)
|
return url, text.nameext_from_url(iurl, data)
|
||||||
|
|
||||||
def images_from_api(self):
|
def images_from_api(self):
|
||||||
@@ -333,10 +324,20 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
|
|||||||
|
|
||||||
data["num"] = request["page"]
|
data["num"] = request["page"]
|
||||||
data["image_token"] = imgkey
|
data["image_token"] = imgkey
|
||||||
|
|
||||||
|
if imgurl.endswith("g/509.gif"):
|
||||||
|
self._report_limits(data)
|
||||||
yield url, text.nameext_from_url(imgurl, data)
|
yield url, text.nameext_from_url(imgurl, data)
|
||||||
|
|
||||||
request["imgkey"] = nextkey
|
request["imgkey"] = nextkey
|
||||||
|
|
||||||
|
def _report_limits(self, data):
|
||||||
|
ExhentaiExtractor.LIMIT = True
|
||||||
|
raise exception.StopExtraction(
|
||||||
|
"Image limit reached! "
|
||||||
|
"Continue with '%s/s/%s/%s-%s' as URL after resetting it.",
|
||||||
|
self.root, data["image_token"], self.gallery_id, data["num"])
|
||||||
|
|
||||||
def _gallery_page(self):
|
def _gallery_page(self):
|
||||||
url = "{}/g/{}/{}/".format(
|
url = "{}/g/{}/{}/".format(
|
||||||
self.root, self.gallery_id, self.gallery_token)
|
self.root, self.gallery_id, self.gallery_token)
|
||||||
@@ -360,35 +361,6 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
|
|||||||
raise exception.NotFoundError("image page")
|
raise exception.NotFoundError("image page")
|
||||||
return 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
|
@staticmethod
|
||||||
def _parse_image_info(url):
|
def _parse_image_info(url):
|
||||||
for part in url.split("/")[4:]:
|
for part in url.split("/")[4:]:
|
||||||
|
|||||||
Reference in New Issue
Block a user