[e621] implement delay via '_request_interval_min'
This commit is contained in:
parent
93ce7466e2
commit
c57a918f4a
@ -34,6 +34,7 @@ class Extractor():
|
||||
test = None
|
||||
_request_last = 0
|
||||
_request_interval = 0
|
||||
_request_interval_min = 0
|
||||
|
||||
def __init__(self, match):
|
||||
self.session = requests.Session()
|
||||
@ -54,6 +55,8 @@ class Extractor():
|
||||
|
||||
if self._retries < 0:
|
||||
self._retries = float("inf")
|
||||
if self._request_interval < self._request_interval_min:
|
||||
self._request_interval = self._request_interval_min
|
||||
|
||||
if self.basecategory:
|
||||
self.config = self._config_shared
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
from .common import Extractor, Message
|
||||
from . import danbooru
|
||||
import time
|
||||
|
||||
|
||||
BASE_PATTERN = r"(?:https?://)?e(621|926)\.net"
|
||||
@ -23,22 +22,16 @@ class E621Extractor(danbooru.DanbooruExtractor):
|
||||
page_limit = 750
|
||||
page_start = None
|
||||
per_page = 320
|
||||
_last_request = 0
|
||||
_request_interval_min = 1.0
|
||||
|
||||
def __init__(self, match):
|
||||
super().__init__(match)
|
||||
self.root = "https://e{}.net".format(match.group(1))
|
||||
self.headers = {"User-Agent": "gallery-dl/1.14.0 (by mikf)"}
|
||||
|
||||
def request(self, url, **kwargs):
|
||||
diff = time.time() - E621Extractor._last_request
|
||||
if diff < 1.0:
|
||||
delay = 1.0 - diff
|
||||
self.log.debug("Sleeping for %s seconds", delay)
|
||||
time.sleep(delay)
|
||||
kwargs["headers"] = {"User-Agent": "gallery-dl/1.14.0 (by mikf)"}
|
||||
response = Extractor.request(self, url, **kwargs)
|
||||
E621Extractor._last_request = time.time()
|
||||
return response
|
||||
kwargs["headers"] = self.headers
|
||||
return Extractor.request(self, url, **kwargs)
|
||||
|
||||
def items(self):
|
||||
data = self.metadata()
|
||||
|
Loading…
x
Reference in New Issue
Block a user