[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:
@@ -445,6 +445,7 @@ Default
|
|||||||
``zerochan``
|
``zerochan``
|
||||||
* ``"1.0"``
|
* ``"1.0"``
|
||||||
``furaffinity``
|
``furaffinity``
|
||||||
|
``rule34``
|
||||||
* ``"1.0-2.0"``
|
* ``"1.0-2.0"``
|
||||||
``flickr``,
|
``flickr``,
|
||||||
``pexels``,
|
``pexels``,
|
||||||
@@ -4650,8 +4651,25 @@ Description
|
|||||||
restrict it to only one possible format.
|
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
|
extractor.rule34xyz.format
|
||||||
---------------------------
|
--------------------------
|
||||||
Type
|
Type
|
||||||
* ``string``
|
* ``string``
|
||||||
* ``list`` of ``strings``
|
* ``list`` of ``strings``
|
||||||
|
|||||||
@@ -633,6 +633,12 @@
|
|||||||
{
|
{
|
||||||
"format": ["hd", "sd", "gif"]
|
"format": ["hd", "sd", "gif"]
|
||||||
},
|
},
|
||||||
|
"rule34":
|
||||||
|
{
|
||||||
|
"api-key": null,
|
||||||
|
"user-id": null,
|
||||||
|
"sleep-request": "1.0"
|
||||||
|
},
|
||||||
"rule34xyz":
|
"rule34xyz":
|
||||||
{
|
{
|
||||||
"username": "",
|
"username": "",
|
||||||
|
|||||||
@@ -16,17 +16,33 @@ import collections
|
|||||||
class GelbooruV02Extractor(booru.BooruExtractor):
|
class GelbooruV02Extractor(booru.BooruExtractor):
|
||||||
basecategory = "gelbooru_v02"
|
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):
|
def _init(self):
|
||||||
self.api_key = self.config("api-key")
|
self.api_key = self.config("api-key")
|
||||||
self.user_id = self.config("user-id")
|
self.user_id = self.config("user-id")
|
||||||
self.root_api = self.config_instance("root-api") or self.root
|
|
||||||
|
|
||||||
if self.category == "rule34":
|
if self.category == "rule34":
|
||||||
self._file_url = self._file_url_rule34
|
self._file_url = self._file_url_rule34
|
||||||
|
|
||||||
def _api_request(self, params):
|
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"
|
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):
|
def _pagination(self, params):
|
||||||
params["pid"] = self.page_start
|
params["pid"] = self.page_start
|
||||||
@@ -148,6 +164,7 @@ BASE_PATTERN = GelbooruV02Extractor.update({
|
|||||||
"rule34": {
|
"rule34": {
|
||||||
"root": "https://rule34.xxx",
|
"root": "https://rule34.xxx",
|
||||||
"root-api": "https://api.rule34.xxx",
|
"root-api": "https://api.rule34.xxx",
|
||||||
|
"request-interval": 1.0,
|
||||||
"pattern": r"(?:www\.)?rule34\.xxx",
|
"pattern": r"(?:www\.)?rule34\.xxx",
|
||||||
},
|
},
|
||||||
"safebooru": {
|
"safebooru": {
|
||||||
|
|||||||
Reference in New Issue
Block a user