aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/gelbooru.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/extractor/gelbooru.py')
-rw-r--r--gallery_dl/extractor/gelbooru.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/gallery_dl/extractor/gelbooru.py b/gallery_dl/extractor/gelbooru.py
index f24b696..b152885 100644
--- a/gallery_dl/extractor/gelbooru.py
+++ b/gallery_dl/extractor/gelbooru.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright 2014-2023 Mike Fährmann
+# Copyright 2014-2025 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -26,11 +26,19 @@ class GelbooruBase():
def _api_request(self, params, key="post", log=False):
if "s" not in params:
params["s"] = "post"
+
params["api_key"] = self.api_key
params["user_id"] = self.user_id
url = self.root + "/index.php?page=dapi&q=index&json=1"
- data = self.request(url, params=params).json()
+ try:
+ data = self.request_json(url, params=params)
+ except exception.HttpError as exc:
+ if exc.status == 401:
+ raise exception.AuthorizationError(
+ f"'api-key' and 'user-id' required "
+ f"({exc.status}: {exc.response.reason})")
+ raise
if not key:
return data
@@ -73,7 +81,7 @@ class GelbooruBase():
if id:
tag = "id:" + op
tags = [t for t in tags if not t.startswith(tag)]
- tags = "{} id:{}".format(" ".join(tags), op)
+ tags = f"{' '.join(tags)} id:{op}"
while True:
posts = self._api_request(params)
@@ -113,7 +121,7 @@ class GelbooruBase():
post["_fallback"] = (url,)
md5 = post["md5"]
root = text.root_from_url(post["preview_url"])
- path = "/images/{}/{}/{}.webm".format(md5[0:2], md5[2:4], md5)
+ path = f"/images/{md5[0:2]}/{md5[2:4]}/{md5}.webm"
url = root + path
return url
@@ -292,7 +300,7 @@ class GelbooruRedirectExtractor(GelbooruBase, Extractor):
def __init__(self, match):
Extractor.__init__(self, match)
- self.url_base64 = match.group(1)
+ self.url_base64 = match[1]
def items(self):
url = text.ensure_http_scheme(binascii.a2b_base64(