replace 'wait-min/-max' with 'sleep-request'

on exhentai, idolcomplex, reactor
This commit is contained in:
Mike Fährmann
2021-03-02 22:55:45 +01:00
parent e165e6c265
commit bae874f370
4 changed files with 5 additions and 70 deletions

View File

@@ -12,8 +12,6 @@ from .common import Extractor, Message
from .. import text, util, exception
from ..cache import cache
import itertools
import random
import time
import math
BASE_PATTERN = r"(?:https?://)?(e[x-]|g\.e-)hentai\.org"
@@ -29,6 +27,7 @@ class ExhentaiExtractor(Extractor):
cookienames = ("ipb_member_id", "ipb_pass_hash")
cookiedomain = ".exhentai.org"
root = "https://exhentai.org"
request_interval = 5.0
LIMIT = False
@@ -46,8 +45,6 @@ class ExhentaiExtractor(Extractor):
Extractor.__init__(self, match)
self.limits = self.config("limits", True)
self.original = self.config("original", True)
self.wait_min = self.config("wait-min", 3)
self.wait_max = self.config("wait-max", 6)
if type(self.limits) is int:
self._limit_max = self.limits
@@ -56,8 +53,6 @@ class ExhentaiExtractor(Extractor):
self._limit_max = 0
self._remaining = 0
if self.wait_max < self.wait_min:
self.wait_max = self.wait_min
self.session.headers["Referer"] = self.root + "/"
if version != "ex":
self.session.cookies.set("nw", "1", domain=self.cookiedomain)
@@ -69,14 +64,6 @@ class ExhentaiExtractor(Extractor):
raise exception.AuthorizationError()
return response
def wait(self, waittime=None):
"""Wait for a randomly chosen amount of seconds"""
if not waittime:
waittime = random.uniform(self.wait_min, self.wait_max)
else:
waittime = random.uniform(waittime * 0.66, waittime * 1.33)
time.sleep(waittime)
def login(self):
"""Login and set necessary cookies"""
if self.LIMIT:
@@ -200,7 +187,6 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
self.log.error("Failed to extract initial image token")
self.log.debug("Page content:\n%s", gpage)
return
self.wait()
ipage = self._image_page()
else:
ipage = self._image_page()
@@ -210,7 +196,6 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
self.log.debug("Page content:\n%s", ipage)
return
self.gallery_token = part.split("/")[1]
self.wait()
gpage = self._gallery_page()
data = self.get_metadata(gpage)
@@ -225,7 +210,6 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
self._check_limits(data)
if "/fullimg.php" in url:
data["extension"] = ""
self.wait(self.wait_max / 4)
yield Message.Url, url, data
def get_metadata(self, page):
@@ -322,7 +306,6 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
"showkey": self.key["show"],
}
for request["page"] in range(self.image_num + 1, self.count + 1):
self.wait()
page = self.request(api_url, method="POST", json=request).json()
imgkey = nextkey
nextkey, pos = text.extract(page["i3"], "'", "'")
@@ -372,7 +355,7 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
return page
def _check_limits(self, data):
if not self._remaining or data["num"] % 20 == 0:
if not self._remaining or data["num"] % 25 == 0:
self._update_limits()
self._remaining -= data["cost"]
@@ -455,7 +438,6 @@ class ExhentaiSearchExtractor(ExhentaiExtractor):
def items(self):
self.login()
yield Message.Version, 1
data = {"_extractor": ExhentaiGalleryExtractor}
while True:
@@ -472,7 +454,6 @@ class ExhentaiSearchExtractor(ExhentaiExtractor):
if 'class="ptdd">&gt;<' in page or ">No hits found</p>" in page:
return
self.params["page"] += 1
self.wait()
class ExhentaiFavoriteExtractor(ExhentaiSearchExtractor):