Skip to content

Commit

Permalink
[gelbooru] fix --range for favorites (#3704)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 23, 2023
1 parent 1f82b00 commit d94aa1e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions gallery_dl/extractor/gelbooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,39 @@ class GelbooruFavoriteExtractor(GelbooruBase,
"count": 3,
})

skip = GelbooruBase._skip_offset

def posts(self):
# get number of favorites
params = {
"s" : "favorite",
"id" : self.favorite_id,
"limit": "1"
"limit": "1",
}
count = self._api_request(params, "@attributes")[0]["count"]

if count <= self.offset:
return
pnum, last = divmod(count + 1, self.per_page)

if self.offset >= last:
self.offset -= last
diff, self.offset = divmod(self.offset, self.per_page)
pnum -= diff + 1
skip = self.offset

# paginate over them in reverse
params["pid"] = count // self.per_page
params["pid"] = pnum
params["limit"] = self.per_page

while True:
favs = self._api_request(params, "favorite")

favs.reverse()
if skip:
favs = favs[skip:]
skip = 0

for fav in favs:
yield from self._api_request({"id": fav["favorite"]})

Expand Down

0 comments on commit d94aa1e

Please sign in to comment.