1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[bilibili] add workarounds for getting rate-limited (#6443)

- set 3-6 second request_interval by default
- retry request after waiting 5 minutes
This commit is contained in:
Mike Fährmann 2024-11-14 23:06:26 +01:00
parent 5bc3657c59
commit e763efd36c
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 17 additions and 4 deletions

View File

@ -394,7 +394,11 @@ Default
* ``"2.0-4.0"`` * ``"2.0-4.0"``
``behance``, ``imagefap``, ``[Nijie]`` ``behance``, ``imagefap``, ``[Nijie]``
* ``"3.0-6.0"`` * ``"3.0-6.0"``
``exhentai``, ``idolcomplex``, ``[reactor]``, ``readcomiconline`` ``bilibili``,
``exhentai``,
``idolcomplex``,
``[reactor]``,
``readcomiconline``
* ``"6.0-6.1"`` * ``"6.0-6.1"``
``twibooru`` ``twibooru``
* ``"6.0-12.0"`` * ``"6.0-12.0"``

View File

@ -14,6 +14,7 @@ class BilibiliExtractor(Extractor):
"""Base class for bilibili extractors""" """Base class for bilibili extractors"""
category = "bilibili" category = "bilibili"
root = "https://www.bilibili.com" root = "https://www.bilibili.com"
request_interval = (3.0, 6.0)
def _init(self): def _init(self):
self.api = BilibiliAPI(self) self.api = BilibiliAPI(self)
@ -102,6 +103,14 @@ class BilibiliAPI():
def article(self, article_id): def article(self, article_id):
url = "https://www.bilibili.com/opus/" + article_id url = "https://www.bilibili.com/opus/" + article_id
response = self.extractor.request(url)
while True:
page = self.extractor.request(url).text
try:
return util.json_loads(text.extr( return util.json_loads(text.extr(
response.text, "window.__INITIAL_STATE__=", "};") + "}") page, "window.__INITIAL_STATE__=", "};") + "}")
except Exception:
if "window._riskdata_" not in page:
raise exception.StopExtraction(
"%s: Unable to extract INITIAL_STATE data", article_id)
self.extractor.wait(seconds=300)