summaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/gelbooru_v02.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2024-01-23 23:35:00 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2024-01-23 23:35:00 -0500
commit12e23f1195164dcb740d6d4a4287e762c9e5e534 (patch)
treee6b13483475c510ea2f685c21363271f23745c56 /gallery_dl/extractor/gelbooru_v02.py
parente949aaf6f6ac93896947d5b736e48e7911926efb (diff)
New upstream version 1.26.7.upstream/1.26.7
Diffstat (limited to 'gallery_dl/extractor/gelbooru_v02.py')
-rw-r--r--gallery_dl/extractor/gelbooru_v02.py40
1 files changed, 7 insertions, 33 deletions
diff --git a/gallery_dl/extractor/gelbooru_v02.py b/gallery_dl/extractor/gelbooru_v02.py
index 0c8af3d..7ab6d02 100644
--- a/gallery_dl/extractor/gelbooru_v02.py
+++ b/gallery_dl/extractor/gelbooru_v02.py
@@ -22,14 +22,10 @@ class GelbooruV02Extractor(booru.BooruExtractor):
def _init(self):
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:
- self.api_root = self.root
+ self.api_root = self.config_instance("api_root") or self.root
if self.category == "realbooru":
- self.items = self._items_realbooru
+ self._file_url = self._file_url_realbooru
self._tags = self._tags_realbooru
def _api_request(self, params):
@@ -128,28 +124,6 @@ class GelbooruV02Extractor(booru.BooruExtractor):
self.root, md5[0:2], md5[2:4], md5, url.rpartition(".")[2])
return url
- def _items_realbooru(self):
- from .common import Message
- data = self.metadata()
-
- for post in self.posts():
- try:
- html = self._html(post)
- url = post["file_url"] = text.rextract(
- html, 'href="', '"', html.index(">Original<"))[0]
- except Exception:
- self.log.debug("Unable to fetch download URL for post %s "
- "(md5: %s)", post.get("id"), post.get("md5"))
- continue
-
- text.nameext_from_url(url, post)
- post.update(data)
- self._prepare(post)
- self._tags(post, html)
-
- yield Message.Directory, post
- yield Message.Url, url, post
-
def _tags_realbooru(self, post, page):
tag_container = text.extr(page, 'id="tagLink"', '</div>')
tags = collections.defaultdict(list)
@@ -161,7 +135,7 @@ class GelbooruV02Extractor(booru.BooruExtractor):
post["tags_" + key] = " ".join(value)
-INSTANCES = {
+BASE_PATTERN = GelbooruV02Extractor.update({
"realbooru": {
"root": "https://realbooru.com",
"pattern": r"realbooru\.com",
@@ -187,16 +161,14 @@ INSTANCES = {
"root": "https://xbooru.com",
"pattern": r"xbooru\.com",
},
-}
-
-BASE_PATTERN = GelbooruV02Extractor.update(INSTANCES)
+})
class GelbooruV02TagExtractor(GelbooruV02Extractor):
subcategory = "tag"
directory_fmt = ("{category}", "{search_tags}")
archive_fmt = "t_{search_tags}_{id}"
- pattern = BASE_PATTERN + r"/index\.php\?page=post&s=list&tags=([^&#]+)"
+ pattern = BASE_PATTERN + r"/index\.php\?page=post&s=list&tags=([^&#]*)"
example = "https://safebooru.org/index.php?page=post&s=list&tags=TAG"
def __init__(self, match):
@@ -208,6 +180,8 @@ class GelbooruV02TagExtractor(GelbooruV02Extractor):
return {"search_tags": self.tags}
def posts(self):
+ if self.tags == "all":
+ self.tags = ""
return self._pagination({"tags": self.tags})