[kemonoparty:favorite] support 'sort' and 'order' query params (#5375)
This commit is contained in:
@@ -494,7 +494,8 @@ class KemonopartyFavoriteExtractor(KemonopartyExtractor):
|
|||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
KemonopartyExtractor.__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
|
self.config("favorites") or
|
||||||
"artist")
|
"artist")
|
||||||
|
|
||||||
@@ -502,9 +503,17 @@ class KemonopartyFavoriteExtractor(KemonopartyExtractor):
|
|||||||
self._prepare_ddosguard_cookies()
|
self._prepare_ddosguard_cookies()
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
|
sort = self.params.get("sort")
|
||||||
|
order = self.params.get("order") or "desc"
|
||||||
|
|
||||||
if self.favorites == "artist":
|
if self.favorites == "artist":
|
||||||
users = self.request(
|
users = self.request(
|
||||||
self.root + "/api/v1/account/favorites?type=artist").json()
|
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:
|
for user in users:
|
||||||
user["_extractor"] = KemonopartyUserExtractor
|
user["_extractor"] = KemonopartyUserExtractor
|
||||||
url = "{}/{}/user/{}".format(
|
url = "{}/{}/user/{}".format(
|
||||||
@@ -514,6 +523,11 @@ class KemonopartyFavoriteExtractor(KemonopartyExtractor):
|
|||||||
elif self.favorites == "post":
|
elif self.favorites == "post":
|
||||||
posts = self.request(
|
posts = self.request(
|
||||||
self.root + "/api/v1/account/favorites?type=post").json()
|
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:
|
for post in posts:
|
||||||
post["_extractor"] = KemonopartyPostExtractor
|
post["_extractor"] = KemonopartyPostExtractor
|
||||||
url = "{}/{}/user/{}/post/{}".format(
|
url = "{}/{}/user/{}/post/{}".format(
|
||||||
|
|||||||
@@ -352,8 +352,24 @@ __tests__ = (
|
|||||||
"#class" : kemonoparty.KemonopartyFavoriteExtractor,
|
"#class" : kemonoparty.KemonopartyFavoriteExtractor,
|
||||||
"#pattern" : kemonoparty.KemonopartyUserExtractor.pattern,
|
"#pattern" : kemonoparty.KemonopartyUserExtractor.pattern,
|
||||||
"#auth" : True,
|
"#auth" : True,
|
||||||
"#count" : 3,
|
"#urls" : (
|
||||||
"#sha1_url": "902c656c8002a3257ef9e255cb69bca1937373d4",
|
"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",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -362,8 +378,24 @@ __tests__ = (
|
|||||||
"#class" : kemonoparty.KemonopartyFavoriteExtractor,
|
"#class" : kemonoparty.KemonopartyFavoriteExtractor,
|
||||||
"#pattern" : kemonoparty.KemonopartyPostExtractor.pattern,
|
"#pattern" : kemonoparty.KemonopartyPostExtractor.pattern,
|
||||||
"#auth" : True,
|
"#auth" : True,
|
||||||
"#count" : 3,
|
"#urls" : (
|
||||||
"#sha1_url": "4be8e84cb384a907a8e7997baaf6287b451783b5",
|
"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",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user