[gelbooru_v02] support using 'api-key' & 'user-id' (#8077)

- detect API error messages
- add default 1.0s request delay to 'rule34'
This commit is contained in:
Mike Fährmann
2025-08-20 22:28:10 +02:00
parent 55a2633196
commit 78f78fe64b
3 changed files with 44 additions and 3 deletions

View File

@@ -445,6 +445,7 @@ Default
``zerochan``
* ``"1.0"``
``furaffinity``
``rule34``
* ``"1.0-2.0"``
``flickr``,
``pexels``,
@@ -4650,8 +4651,25 @@ Description
restrict it to only one possible format.
extractor.rule34.api-key & .user-id
-----------------------------------
Type
``string``
Default
``null``
Description
Values from the `API Access Credentials` section
found near the bottom of your account's
`Options <https://rule34.xxx/index.php?page=account&s=options>`__
page.
Enable `Generate New Key?` and click `Save`
if the value after ``&api_key=`` is empty,
e.g. ``&api_key=&user_id=12345``
extractor.rule34xyz.format
---------------------------
--------------------------
Type
* ``string``
* ``list`` of ``strings``

View File

@@ -633,6 +633,12 @@
{
"format": ["hd", "sd", "gif"]
},
"rule34":
{
"api-key": null,
"user-id": null,
"sleep-request": "1.0"
},
"rule34xyz":
{
"username": "",

View File

@@ -16,17 +16,33 @@ import collections
class GelbooruV02Extractor(booru.BooruExtractor):
basecategory = "gelbooru_v02"
def __init__(self, match):
booru.BooruExtractor.__init__(self, match)
self.request_interval = self.config_instance("request-interval", 0.0)
self.root_api = self.config_instance("root-api") or self.root
def _init(self):
self.api_key = self.config("api-key")
self.user_id = self.config("user-id")
self.root_api = self.config_instance("root-api") or self.root
if self.category == "rule34":
self._file_url = self._file_url_rule34
def _api_request(self, params):
params["api_key"] = self.api_key
params["user_id"] = self.user_id
url = self.root_api + "/index.php?page=dapi&s=post&q=index"
return self.request_xml(url, params=params)
root = self.request_xml(url, params=params)
if root.tag == "error":
msg = root.text
if msg.lower().startswith("missing authentication"):
raise exception.AuthRequired(
"'api-key' & 'user-id'", "the API", msg)
raise exception.AbortExtraction(f"'{msg}'")
return root
def _pagination(self, params):
params["pid"] = self.page_start
@@ -148,6 +164,7 @@ BASE_PATTERN = GelbooruV02Extractor.update({
"rule34": {
"root": "https://rule34.xxx",
"root-api": "https://api.rule34.xxx",
"request-interval": 1.0,
"pattern": r"(?:www\.)?rule34\.xxx",
},
"safebooru": {