From e9ec91c811ac34620e9d4b0e12c0e9237336bf14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 29 Mar 2021 19:01:13 +0200 Subject: [PATCH] [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 --- docs/configuration.rst | 14 --------- docs/gallery-dl.conf | 1 - gallery_dl/extractor/exhentai.py | 52 ++++++++------------------------ 3 files changed, 12 insertions(+), 55 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 1f32bb87..f695d28b 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -922,20 +922,6 @@ Description * ``"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 --------------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 7702e4a9..8a3d9e2a 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -79,7 +79,6 @@ "username": null, "password": null, "domain": "auto", - "limits": true, "metadata": false, "original": true, "sleep-request": 5.0 diff --git a/gallery_dl/extractor/exhentai.py b/gallery_dl/extractor/exhentai.py index cbdf2da7..872a338d 100644 --- a/gallery_dl/extractor/exhentai.py +++ b/gallery_dl/extractor/exhentai.py @@ -43,16 +43,8 @@ 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) @@ -77,7 +69,6 @@ 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) @@ -206,8 +197,6 @@ 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"] = "" yield Message.Url, url, data @@ -299,6 +288,8 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor): data["image_token"] = self.key["start"] = extr('var startkey="', '";') self.key["show"] = extr('var showkey="', '";') + if iurl.endswith("g/509.gif"): + self._report_limits(data) return url, text.nameext_from_url(iurl, data) def images_from_api(self): @@ -333,10 +324,20 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor): data["num"] = request["page"] data["image_token"] = imgkey + + if imgurl.endswith("g/509.gif"): + self._report_limits(data) yield url, text.nameext_from_url(imgurl, data) 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): url = "{}/g/{}/{}/".format( self.root, self.gallery_id, self.gallery_token) @@ -360,35 +361,6 @@ 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, "", "") - maximum, pos = text.extract(page, "", "", 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:]: