diff options
| author | 2025-09-23 07:44:44 -0400 | |
|---|---|---|
| committer | 2025-09-23 07:44:44 -0400 | |
| commit | 291c04af647559317fc9f9f392ad43841ec509ad (patch) | |
| tree | 13a72906223927180001b362d086c82401cb7843 /gallery_dl/extractor/kemono.py | |
| parent | 065386e00c7a6c8bbe4bb23a545a7fc7b2c09a4a (diff) | |
| parent | 42b62671fabfdcf983a9575221420d85f7fbcac1 (diff) | |
Update upstream source from tag 'upstream/1.30.8'
Update to upstream version '1.30.8'
with Debian dir 51367313d3355f7d0d16a754c5c63135fb3c72e2
Diffstat (limited to 'gallery_dl/extractor/kemono.py')
| -rw-r--r-- | gallery_dl/extractor/kemono.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/gallery_dl/extractor/kemono.py b/gallery_dl/extractor/kemono.py index fc5972c..1f70031 100644 --- a/gallery_dl/extractor/kemono.py +++ b/gallery_dl/extractor/kemono.py @@ -407,7 +407,11 @@ class KemonoDiscordExtractor(KemonoExtractor): r"(/[A-Za-z0-9-._~:/?#\[\]@!$&'()*+,;%=]+)").findall find_hash = util.re(HASH_PATTERN).match - posts = self.api.discord_channel(channel_id) + if (order := self.config("order-posts")) and order[0] in ("r", "d"): + posts = self.api.discord_channel(channel_id, channel["post_count"]) + else: + posts = self.api.discord_channel(channel_id) + if max_posts := self.config("max-posts"): posts = itertools.islice(posts, max_posts) @@ -627,9 +631,12 @@ class KemonoAPI(): endpoint = f"/{service}/user/{creator_id}/tags" return self._call(endpoint) - def discord_channel(self, channel_id): + def discord_channel(self, channel_id, post_count=None): endpoint = f"/discord/channel/{channel_id}" - return self._pagination(endpoint, {}, 150) + if post_count is None: + return self._pagination(endpoint, {}, 150) + else: + return self._pagination_reverse(endpoint, {}, 150, post_count) def discord_channel_lookup(self, server_id): endpoint = f"/discord/channel/lookup/{server_id}" @@ -670,3 +677,18 @@ class KemonoAPI(): if len(data) < batch: return params["o"] += batch + + def _pagination_reverse(self, endpoint, params, batch, count): + params["o"] = count // batch * batch + + while True: + data = self._call(endpoint, params) + + if not data: + return + data.reverse() + yield from data + + if not params["o"]: + return + params["o"] -= batch |
