Skip to content

Commit

Permalink
[kemonoparty:favorite] support 'sort' and 'order' query params (#5375)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 26, 2024
1 parent d1d017a commit 72ac2c7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
16 changes: 15 additions & 1 deletion gallery_dl/extractor/kemonoparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,17 +494,26 @@ class KemonopartyFavoriteExtractor(KemonopartyExtractor):

def __init__(self, match):
KemonopartyExtractor.__init__(self, match)
self.favorites = (text.parse_query(match.group(3)).get("type") or
self.params = text.parse_query(match.group(3))
self.favorites = (self.params.get("type") or
self.config("favorites") or
"artist")

def items(self):
self._prepare_ddosguard_cookies()
self.login()

sort = self.params.get("sort")
order = self.params.get("order") or "desc"

if self.favorites == "artist":
users = self.request(
self.root + "/api/v1/account/favorites?type=artist").json()

if not sort:
sort = "updated"
users.sort(key=lambda x: x[sort], reverse=(order == "desc"))

for user in users:
user["_extractor"] = KemonopartyUserExtractor
url = "{}/{}/user/{}".format(
Expand All @@ -514,6 +523,11 @@ def items(self):
elif self.favorites == "post":
posts = self.request(
self.root + "/api/v1/account/favorites?type=post").json()

if not sort:
sort = "faved_seq"
posts.sort(key=lambda x: x[sort], reverse=(order == "desc"))

for post in posts:
post["_extractor"] = KemonopartyPostExtractor
url = "{}/{}/user/{}/post/{}".format(
Expand Down
40 changes: 36 additions & 4 deletions test/results/kemonoparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,24 @@
"#class" : kemonoparty.KemonopartyFavoriteExtractor,
"#pattern" : kemonoparty.KemonopartyUserExtractor.pattern,
"#auth" : True,
"#count" : 3,
"#sha1_url": "902c656c8002a3257ef9e255cb69bca1937373d4",
"#urls" : (
"https://kemono.su/patreon/user/881792",
"https://kemono.su/fanbox/user/6993449",
"https://kemono.su/subscribestar/user/alcorart",
),
},

{
"#url" : "https://kemono.su/favorites?type=artist&sort=faved_seq&order=asc",
"#category": ("", "kemonoparty", "favorite"),
"#class" : kemonoparty.KemonopartyFavoriteExtractor,
"#pattern" : kemonoparty.KemonopartyUserExtractor.pattern,
"#auth" : True,
"#urls" : (
"https://kemono.su/fanbox/user/6993449",
"https://kemono.su/patreon/user/881792",
"https://kemono.su/subscribestar/user/alcorart",
),
},

{
Expand All @@ -362,8 +378,24 @@
"#class" : kemonoparty.KemonopartyFavoriteExtractor,
"#pattern" : kemonoparty.KemonopartyPostExtractor.pattern,
"#auth" : True,
"#count" : 3,
"#sha1_url": "4be8e84cb384a907a8e7997baaf6287b451783b5",
"#urls" : (
"https://kemono.su/subscribestar/user/alcorart/post/184329",
"https://kemono.su/fanbox/user/6993449/post/23913",
"https://kemono.su/patreon/user/881792/post/4769638",
),
},

{
"#url" : "https://kemono.su/favorites?type=post&sort=published&order=asc",
"#category": ("", "kemonoparty", "favorite"),
"#class" : kemonoparty.KemonopartyFavoriteExtractor,
"#pattern" : kemonoparty.KemonopartyPostExtractor.pattern,
"#auth" : True,
"#urls" : (
"https://kemono.su/patreon/user/881792/post/4769638",
"https://kemono.su/fanbox/user/6993449/post/23913",
"https://kemono.su/subscribestar/user/alcorart/post/184329",
),
},

)

0 comments on commit 72ac2c7

Please sign in to comment.