From 51301e0c31773467551b8832687884302cffff9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 23 Feb 2023 00:35:37 +0100 Subject: [PATCH] replace remaining time.sleep() calls with Extractor.sleep() or request_interval --- gallery_dl/extractor/deviantart.py | 6 ++---- gallery_dl/extractor/erome.py | 3 +-- gallery_dl/extractor/plurk.py | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index 15bdd3a2..aed2872a 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -366,9 +366,7 @@ class DeviantartExtractor(Extractor): kwargs["fatal"] = None diff = time.time() - DeviantartExtractor._last_request if diff < 2.0: - delay = 2.0 - diff - self.log.debug("Sleeping %.2f seconds", delay) - time.sleep(delay) + self.sleep(2.0 - diff, "request") while True: response = self.request(url, **kwargs) @@ -1496,7 +1494,7 @@ class DeviantartOAuthAPI(): while True: if self.delay: - time.sleep(self.delay) + self.extractor.sleep(self.delay, "api") self.authenticate(None if public else self.refresh_token_key) kwargs["headers"] = self.headers diff --git a/gallery_dl/extractor/erome.py b/gallery_dl/extractor/erome.py index ad3f16ba..03307f89 100644 --- a/gallery_dl/extractor/erome.py +++ b/gallery_dl/extractor/erome.py @@ -12,7 +12,6 @@ from .common import Extractor, Message from .. import text, util, exception from ..cache import cache import itertools -import time BASE_PATTERN = r"(?:https?://)?(?:www\.)?erome\.com" @@ -75,7 +74,7 @@ class EromeExtractor(Extractor): if response.content.find( b"Please wait a few moments", 0, 600) < 0: return response - time.sleep(5) + self.sleep(5.0, "check") def _pagination(self, url, params): for params["page"] in itertools.count(1): diff --git a/gallery_dl/extractor/plurk.py b/gallery_dl/extractor/plurk.py index 1c24b5bb..41352597 100644 --- a/gallery_dl/extractor/plurk.py +++ b/gallery_dl/extractor/plurk.py @@ -11,7 +11,6 @@ from .common import Extractor, Message from .. import text, util, exception import datetime -import time import re @@ -19,6 +18,7 @@ class PlurkExtractor(Extractor): """Base class for plurk extractors""" category = "plurk" root = "https://www.plurk.com" + request_interval = 1.0 def items(self): urls = self._urls_ex if self.config("comments", False) else self._urls @@ -58,7 +58,6 @@ class PlurkExtractor(Extractor): return elif info["has_newer"] < 200: del data["count"] - time.sleep(1) data["from_response_id"] = info["responses"][-1]["id"] + 1 @staticmethod