summaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/gelbooru_v02.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2024-08-03 20:27:44 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2024-08-03 20:27:44 -0400
commit032e5bed275a253e122ed9ac86dac7b8c4204172 (patch)
treeb4eda52ebfe00c4d22e9d633b1ab2d158a9f0573 /gallery_dl/extractor/gelbooru_v02.py
parent80e39a8fc7de105510cbbdca8507f2a4b8c9e01d (diff)
New upstream version 1.27.2.upstream/1.27.2
Diffstat (limited to 'gallery_dl/extractor/gelbooru_v02.py')
-rw-r--r--gallery_dl/extractor/gelbooru_v02.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/gallery_dl/extractor/gelbooru_v02.py b/gallery_dl/extractor/gelbooru_v02.py
index 8d8b8ad..fbbd26c 100644
--- a/gallery_dl/extractor/gelbooru_v02.py
+++ b/gallery_dl/extractor/gelbooru_v02.py
@@ -36,7 +36,9 @@ class GelbooruV02Extractor(booru.BooruExtractor):
params["pid"] = self.page_start
params["limit"] = self.per_page
- post = None
+ post = total = None
+ count = 0
+
while True:
try:
root = self._api_request(params)
@@ -50,12 +52,29 @@ class GelbooruV02Extractor(booru.BooruExtractor):
params["pid"] = 0
continue
+ if total is None:
+ try:
+ total = int(root.attrib["count"])
+ self.log.debug("%s posts in total", total)
+ except Exception as exc:
+ total = 0
+ self.log.debug(
+ "Failed to get total number of posts (%s: %s)",
+ exc.__class__.__name__, exc)
+
post = None
for post in root:
yield post.attrib
- if len(root) < self.per_page:
- return
+ num = len(root)
+ count += num
+ if num < self.per_page:
+ if not total or count >= total:
+ return
+ if not num:
+ self.log.debug("Empty response - Retrying")
+ continue
+
params["pid"] += 1
def _pagination_html(self, params):