From f225247670fd55a2ba8d757da1d5f7500472519f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 18 Jul 2022 18:46:31 +0200 Subject: [PATCH] [gelbooru] add support for `api_key` and `user_id` (#2767) --- docs/configuration.rst | 12 ++++++++++++ docs/gallery-dl.conf | 5 +++++ gallery_dl/extractor/gelbooru.py | 5 +++++ gallery_dl/extractor/gelbooru_v02.py | 3 +++ 4 files changed, 25 insertions(+) diff --git a/docs/configuration.rst b/docs/configuration.rst index 25ce8761..38f1fce8 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1313,6 +1313,18 @@ Description * ``"new"``: Expect the *new* site layout +extractor.gelbooru.api-key & .user-id +------------------------------------- +Type + ``string`` +Default + ``null`` +Description + Values from the API Access Credentials section found at the bottom of your + `Account Options `__ + page. + + extractor.generic.enabled ------------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 14926534..fc27f557 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -109,6 +109,11 @@ "include": "gallery", "layout": "auto" }, + "gelbooru": + { + "api-key": null, + "user-id": null + }, "gfycat": { "format": ["mp4", "webm", "mobile", "gif"] diff --git a/gallery_dl/extractor/gelbooru.py b/gallery_dl/extractor/gelbooru.py index e8bee378..7fb97a23 100644 --- a/gallery_dl/extractor/gelbooru.py +++ b/gallery_dl/extractor/gelbooru.py @@ -21,10 +21,15 @@ class GelbooruBase(): root = "https://gelbooru.com" def _api_request(self, params): + params["api_key"] = self.api_key + params["user_id"] = self.user_id + url = self.root + "/index.php?page=dapi&s=post&q=index&json=1" data = self.request(url, params=params).json() + if "post" not in data: return () + posts = data["post"] if not isinstance(posts, list): return (posts,) diff --git a/gallery_dl/extractor/gelbooru_v02.py b/gallery_dl/extractor/gelbooru_v02.py index 35a34484..0395f69d 100644 --- a/gallery_dl/extractor/gelbooru_v02.py +++ b/gallery_dl/extractor/gelbooru_v02.py @@ -21,6 +21,9 @@ class GelbooruV02Extractor(booru.BooruExtractor): def __init__(self, match): booru.BooruExtractor.__init__(self, match) + self.api_key = self.config("api-key") + self.user_id = self.config("user-id") + try: self.api_root = INSTANCES[self.category]["api_root"] except KeyError: