diff --git a/docs/configuration.rst b/docs/configuration.rst index 9c3782c3..51408d3c 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2017,6 +2017,20 @@ Description page. +extractor.gelbooru.favorite.order-posts +--------------------------------------- +Type + ``string`` +Default + ``"desc"`` +Description + Controls the order in which favorited posts are returned. + + * ``"asc"``: Ascending favorite date order (oldest first) + * ``"desc"``: Descending favorite date order (newest first) + * ``"reverse"``: Same as ``"asc"`` + + extractor.generic.enabled ------------------------- Type diff --git a/gallery_dl/extractor/gelbooru.py b/gallery_dl/extractor/gelbooru.py index e54a1fae..2459a61f 100644 --- a/gallery_dl/extractor/gelbooru.py +++ b/gallery_dl/extractor/gelbooru.py @@ -172,26 +172,31 @@ class GelbooruFavoriteExtractor(GelbooruBase, "id" : self.favorite_id, "limit": "2", } - data = self._api_request(params, None, True) count = data["@attributes"]["count"] - if count <= self.offset: - return () + self.log.debug("API reports %s favorite entries", count) favs = data["favorite"] try: order = 1 if favs[0]["id"] < favs[1]["id"] else -1 - except LookupError: - order = 0 + except LookupError as exc: + self.log.debug( + "Error when determining API favorite order (%s: %s)", + exc.__class__.__name__, exc) + order = -1 + else: + self.log.debug("API yields favorites in %sscending order", + "a" if order > 0 else "de") - if order > 0: - self.log.debug("API yields favorites in ascending order") + order_favs = self.config("order-posts") + if order_favs and order_favs[0] in ("r", "a"): self.log.debug("Returning them in reverse") - return self._pagination_reverse(params, count) + order = -order - self.log.debug("API yields favorites in descending order") - return self._pagination(params, count) + if order < 0: + return self._pagination(params, count) + return self._pagination_reverse(params, count) def _pagination(self, params, count): if self.offset: @@ -203,7 +208,7 @@ class GelbooruFavoriteExtractor(GelbooruBase, params["limit"] = self.per_page while True: - favs = self._api_request(params, "favorite", True) + favs = self._api_request(params, "favorite") if not favs: return @@ -232,7 +237,7 @@ class GelbooruFavoriteExtractor(GelbooruBase, params["limit"] = self.per_page while True: - favs = self._api_request(params, "favorite", True) + favs = self._api_request(params, "favorite") favs.reverse() if skip: diff --git a/test/results/gelbooru.py b/test/results/gelbooru.py index b2f99ed1..6302d56f 100644 --- a/test/results/gelbooru.py +++ b/test/results/gelbooru.py @@ -47,10 +47,30 @@ __tests__ = ( }, { - "#url" : "https://gelbooru.com/index.php?page=favorites&s=view&id=279415", + "#url" : "https://gelbooru.com/index.php?page=favorites&s=view&id=1435674", "#category": ("booru", "gelbooru", "favorite"), "#class" : gelbooru.GelbooruFavoriteExtractor, - "#count" : 3, + "#urls" : ( + "https://img3.gelbooru.com/images/5d/30/5d30fc056ed8668616b3c440df9bac89.jpg", + "https://img3.gelbooru.com/images/4c/2d/4c2da867ed643acdadd8105177dcdaf0.png", + "https://img3.gelbooru.com/images/c8/26/c826f3cb90d9aaca8d0632a96bf4abe8.jpg", + "https://img3.gelbooru.com/images/c1/fe/c1fe59c0bc8ce955dd353544b1015d0c.jpg", + "https://img3.gelbooru.com/images/e6/6d/e66d8883c184f5d3b2591dfcdf0d007c.jpg", + ), +}, + +{ + "#url" : "https://gelbooru.com/index.php?page=favorites&s=view&id=1435674", + "#category": ("booru", "gelbooru", "favorite"), + "#class" : gelbooru.GelbooruFavoriteExtractor, + "#options" : {"order-posts": "reverse"}, + "#urls" : ( + "https://img3.gelbooru.com/images/e6/6d/e66d8883c184f5d3b2591dfcdf0d007c.jpg", + "https://img3.gelbooru.com/images/c1/fe/c1fe59c0bc8ce955dd353544b1015d0c.jpg", + "https://img3.gelbooru.com/images/c8/26/c826f3cb90d9aaca8d0632a96bf4abe8.jpg", + "https://img3.gelbooru.com/images/4c/2d/4c2da867ed643acdadd8105177dcdaf0.png", + "https://img3.gelbooru.com/images/5d/30/5d30fc056ed8668616b3c440df9bac89.jpg", + ), }, {