[kemonoparty] add 'endpoint' option (#7438)
This commit is contained in:
@@ -3107,12 +3107,32 @@ Description
|
|||||||
Extract a user's announcements as ``announcements`` metadata.
|
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
|
extractor.kemonoparty.favorites
|
||||||
-------------------------------
|
-------------------------------
|
||||||
Type
|
Type
|
||||||
``string``
|
``string``
|
||||||
Default
|
Default
|
||||||
``artist``
|
``"artist"``
|
||||||
Description
|
Description
|
||||||
Determines the type of favorites to be downloaded.
|
Determines the type of favorites to be downloaded.
|
||||||
|
|
||||||
|
|||||||
@@ -379,6 +379,7 @@
|
|||||||
"comments" : false,
|
"comments" : false,
|
||||||
"dms" : false,
|
"dms" : false,
|
||||||
"duplicates" : false,
|
"duplicates" : false,
|
||||||
|
"endpoint" : "legacy",
|
||||||
"favorites" : "artist",
|
"favorites" : "artist",
|
||||||
"files" : ["attachments", "file", "inline"],
|
"files" : ["attachments", "file", "inline"],
|
||||||
"max-posts" : null,
|
"max-posts" : null,
|
||||||
|
|||||||
@@ -317,11 +317,15 @@ class KemonopartyUserExtractor(KemonopartyExtractor):
|
|||||||
KemonopartyExtractor.__init__(self, match)
|
KemonopartyExtractor.__init__(self, match)
|
||||||
|
|
||||||
def posts(self):
|
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
|
_, _, service, creator_id, query = self.groups
|
||||||
params = text.parse_query(query)
|
params = text.parse_query(query)
|
||||||
return self.api.creator_posts_legacy(
|
return endpoint(service, creator_id,
|
||||||
service, creator_id,
|
params.get("o"), params.get("q"), params.get("tag"))
|
||||||
params.get("o"), params.get("q"), params.get("tag"))
|
|
||||||
|
|
||||||
|
|
||||||
class KemonopartyPostsExtractor(KemonopartyExtractor):
|
class KemonopartyPostsExtractor(KemonopartyExtractor):
|
||||||
@@ -525,9 +529,10 @@ class KemonoAPI():
|
|||||||
endpoint = "/file/" + file_hash
|
endpoint = "/file/" + file_hash
|
||||||
return self._call(endpoint)
|
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)
|
endpoint = "/{}/user/{}".format(service, creator_id)
|
||||||
params = {"q": query, "o": offset}
|
params = {"q": query, "tag": tags, "o": offset}
|
||||||
return self._pagination(endpoint, params, 50)
|
return self._pagination(endpoint, params, 50)
|
||||||
|
|
||||||
def creator_posts_legacy(self, service, creator_id,
|
def creator_posts_legacy(self, service, creator_id,
|
||||||
|
|||||||
@@ -15,15 +15,68 @@ __tests__ = (
|
|||||||
"#class" : kemonoparty.KemonopartyUserExtractor,
|
"#class" : kemonoparty.KemonopartyUserExtractor,
|
||||||
"#range" : "1-500",
|
"#range" : "1-500",
|
||||||
"#count" : 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",
|
"#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"),
|
"#category": ("", "kemonoparty", "patreon"),
|
||||||
"#class" : kemonoparty.KemonopartyUserExtractor,
|
"#class" : kemonoparty.KemonopartyUserExtractor,
|
||||||
"#options" : {"max-posts": 100},
|
"#options" : {"max-posts": 100, "endpoint": "posts"},
|
||||||
"#count" : range(200, 400),
|
"#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",
|
"#pattern" : r"https://kemono.su/data/21/0f/210f35388e28bbcf756db18dd516e2d82ce75[0-9a-f]+\.jpg",
|
||||||
"#sha1_content": "900949cefc97ab8dc1979cc3664785aac5ba70dd",
|
"#sha1_content": "900949cefc97ab8dc1979cc3664785aac5ba70dd",
|
||||||
|
|
||||||
"added" : "2020-05-06T20:28:02.302000",
|
"added" : None,
|
||||||
"archives" : [],
|
"archives" : [],
|
||||||
"content" : str,
|
"content" : str,
|
||||||
"count" : 1,
|
"count" : 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user