[kemonoparty] add 'endpoint' option (#7438)

This commit is contained in:
Mike Fährmann
2025-04-28 16:47:48 +02:00
parent f6330bf16d
commit 16b5d41ce5
4 changed files with 88 additions and 9 deletions

View File

@@ -3107,12 +3107,32 @@ Description
Extract a user's announcements as ``announcements`` metadata.
extractor.kemonoparty.endpoint
------------------------------
Type
``string``
Default
``"legacy"``
Description
API endpoint to use for retrieving creator posts.
``"legacy"``
| Use the results from
`/v1/{service}/user/{creator_id}/posts-legacy <https://kemono.su/documentation/api#operations-default-get_v1__service__user__creator_id__posts_legacy>`__
| Provides less metadata, but is more reliable at returning all posts.
| Supports filtering results by ``tag`` query parameter.
``"posts"``
| Use the results from
`/v1/{service}/user/{creator_id} <https://kemono.su/documentation/api#operations-Posts-get_v1__service__user__creator_id_>`__
| Provides more metadata, but might not return a creator's first/last posts.
extractor.kemonoparty.favorites
-------------------------------
Type
``string``
Default
``artist``
``"artist"``
Description
Determines the type of favorites to be downloaded.

View File

@@ -379,6 +379,7 @@
"comments" : false,
"dms" : false,
"duplicates" : false,
"endpoint" : "legacy",
"favorites" : "artist",
"files" : ["attachments", "file", "inline"],
"max-posts" : null,

View File

@@ -317,11 +317,15 @@ class KemonopartyUserExtractor(KemonopartyExtractor):
KemonopartyExtractor.__init__(self, match)
def posts(self):
if self.config("endpoint") == "posts":
endpoint = self.api.creator_posts
else:
endpoint = self.api.creator_posts_legacy
_, _, service, creator_id, query = self.groups
params = text.parse_query(query)
return self.api.creator_posts_legacy(
service, creator_id,
params.get("o"), params.get("q"), params.get("tag"))
return endpoint(service, creator_id,
params.get("o"), params.get("q"), params.get("tag"))
class KemonopartyPostsExtractor(KemonopartyExtractor):
@@ -525,9 +529,10 @@ class KemonoAPI():
endpoint = "/file/" + file_hash
return self._call(endpoint)
def creator_posts(self, service, creator_id, offset=0, query=None):
def creator_posts(self, service, creator_id,
offset=0, query=None, tags=None):
endpoint = "/{}/user/{}".format(service, creator_id)
params = {"q": query, "o": offset}
params = {"q": query, "tag": tags, "o": offset}
return self._pagination(endpoint, params, 50)
def creator_posts_legacy(self, service, creator_id,

View File

@@ -15,15 +15,68 @@ __tests__ = (
"#class" : kemonoparty.KemonopartyUserExtractor,
"#range" : "1-500",
"#count" : 500,
"archives" : list,
"attachments": list,
"count" : int,
"num" : int,
"date" : "type:datetime",
"id" : str,
"published" : str,
"service" : "fanbox",
"subcategory": "fanbox",
"substring" : str,
"title" : str,
"user" : "6993449",
"username" : "かえぬこ",
"file" : {
"extension": str,
"filename" : str,
"hash" : "len:str:64",
"name" : str,
"path" : str,
"type" : "file",
"url" : str,
},
},
{
"#url" : "https://kemono.su/patreon/user/881792?o=150",
"#comment" : "'max-posts' option, 'o' query parameter (#1674)",
"#comment" : "'max-posts' and 'endpoint' option, 'o' query parameter (#1674)",
"#category": ("", "kemonoparty", "patreon"),
"#class" : kemonoparty.KemonopartyUserExtractor,
"#options" : {"max-posts": 100},
"#options" : {"max-posts": 100, "endpoint": "posts"},
"#count" : range(200, 400),
"added" : {str, None},
"archives" : [],
"attachments": list,
"captions" : None,
"content" : str,
"count" : int,
"num" : int,
"date" : "type:datetime",
"edited" : str,
"embed" : dict,
"id" : str,
"poll" : None,
"published" : str,
"service" : "fanbox",
"shared_file": False,
"subcategory": "fanbox",
"tags" : str,
"title" : str,
"user" : "6993449",
"username" : "かえぬこ",
"file" : {
"extension": str,
"filename" : str,
"hash" : "len:str:64",
"name" : str,
"path" : str,
"type" : "file",
"url" : str,
},
},
{
@@ -76,7 +129,7 @@ __tests__ = (
"#pattern" : r"https://kemono.su/data/21/0f/210f35388e28bbcf756db18dd516e2d82ce75[0-9a-f]+\.jpg",
"#sha1_content": "900949cefc97ab8dc1979cc3664785aac5ba70dd",
"added" : "2020-05-06T20:28:02.302000",
"added" : None,
"archives" : [],
"content" : str,
"count" : 1,