From 78f78fe64b5aff27b103980aa05fb18f8d59147f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 20 Aug 2025 22:28:10 +0200 Subject: [PATCH] [gelbooru_v02] support using 'api-key' & 'user-id' (#8077) - detect API error messages - add default 1.0s request delay to 'rule34' --- docs/configuration.rst | 20 +++++++++++++++++++- docs/gallery-dl.conf | 6 ++++++ gallery_dl/extractor/gelbooru_v02.py | 21 +++++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index f77e4838..28dc6663 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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 `__ + 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`` diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 97b55640..4ecd300c 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -633,6 +633,12 @@ { "format": ["hd", "sd", "gif"] }, + "rule34": + { + "api-key": null, + "user-id": null, + "sleep-request": "1.0" + }, "rule34xyz": { "username": "", diff --git a/gallery_dl/extractor/gelbooru_v02.py b/gallery_dl/extractor/gelbooru_v02.py index c12a7a2e..33db4e4e 100644 --- a/gallery_dl/extractor/gelbooru_v02.py +++ b/gallery_dl/extractor/gelbooru_v02.py @@ -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": {