From 574e38a287d845fd5ea57a7d15563a2bc1bb6b97 Mon Sep 17 00:00:00 2001 From: enduser420 <91022934+enduser420@users.noreply.github.com> Date: Thu, 18 Aug 2022 21:31:42 +0530 Subject: [PATCH] [kemonoparty] add 'favorites' option (#2826) (#2831) * [kemonoparty] add 'favorites' option (#2826) * [kemonoparty] add regex for the url parameter and fallback on the config option * [kemonoparty] simplify --- docs/configuration.rst | 12 ++++++++ gallery_dl/extractor/kemonoparty.py | 48 +++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 72ef42e1..e3ca0e78 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1550,6 +1550,18 @@ Description Extract a user's direct messages as ``dms`` metadata. +extractor.kemonoparty.favorites +--------------------------- +Type + ``string`` +Default + ``artist`` +Description + Determines the type of favorites to be downloaded. + + Available types are ``artist``, and ``post``. + + extractor.kemonoparty.files --------------------------- Type diff --git a/gallery_dl/extractor/kemonoparty.py b/gallery_dl/extractor/kemonoparty.py index f1eb79ff..816b561f 100644 --- a/gallery_dl/extractor/kemonoparty.py +++ b/gallery_dl/extractor/kemonoparty.py @@ -440,20 +440,44 @@ class KemonopartyDiscordServerExtractor(KemonopartyExtractor): class KemonopartyFavoriteExtractor(KemonopartyExtractor): """Extractor for kemono.party favorites""" subcategory = "favorite" - pattern = BASE_PATTERN + r"/favorites" - test = ("https://kemono.party/favorites", { - "pattern": KemonopartyUserExtractor.pattern, - "url": "f4b5b796979bcba824af84206578c79101c7f0e1", - "count": 3, - }) + pattern = BASE_PATTERN + r"/favorites(?:/?\?([^#]+))?" + test = ( + ("https://kemono.party/favorites", { + "pattern": KemonopartyUserExtractor.pattern, + "url": "f4b5b796979bcba824af84206578c79101c7f0e1", + "count": 3, + }), + ("https://kemono.party/favorites?type=post", { + "pattern": KemonopartyPostExtractor.pattern, + "url": "ecfccf5f0d50b8d14caa7bbdcf071de5c1e5b90f", + "count": 3, + }), + ) + + def __init__(self, match): + KemonopartyExtractor.__init__(self, match) + self.favorites = (text.parse_query(match.group(2)).get("type") or + self.config("favorites") or + "artist") def items(self): self._prepare_ddosguard_cookies() self.login() - users = self.request(self.root + "/api/favorites").json() - for user in users: - user["_extractor"] = KemonopartyUserExtractor - url = "{}/{}/user/{}".format( - self.root, user["service"], user["id"]) - yield Message.Queue, url, user + if self.favorites == "artist": + users = self.request( + self.root + "/api/v1/account/favorites?type=artist").json() + for user in users: + user["_extractor"] = KemonopartyUserExtractor + url = "{}/{}/user/{}".format( + self.root, user["service"], user["id"]) + yield Message.Queue, url, user + + elif self.favorites == "post": + posts = self.request( + self.root + "/api/v1/account/favorites?type=post").json() + for post in posts: + post["_extractor"] = KemonopartyPostExtractor + url = "{}/{}/user/{}/post/{}".format( + self.root, post["service"], post["user"], post["id"]) + yield Message.Queue, url, post