1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[kemonoparty] add 'metadata' option (closes #1548)

to fetch creator names with an additional HTTP request
This commit is contained in:
Mike Fährmann 2021-05-14 19:54:16 +02:00
parent 559462789d
commit 0717456b4e
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 20 additions and 0 deletions

View File

@ -1176,6 +1176,16 @@ Description
Download video files.
extractor.kemonoparty.metadata
------------------------------
Type
``bool``
Default
``false``
Description
Extract ``username`` metadata
extractor.khinsider.format
--------------------------
Type

View File

@ -26,6 +26,12 @@ class KemonopartyExtractor(Extractor):
def items(self):
find_inline = re.compile(r'src="(/inline/[^"]+)').findall
if self.config("metadata"):
username = text.unescape(text.extract(
self.request(self.user_url).text, "<title>", " | Kemono<")[0])
else:
username = None
for post in self.posts():
files = []
@ -38,6 +44,8 @@ class KemonopartyExtractor(Extractor):
post["date"] = text.parse_datetime(
post["published"], "%a, %d %b %Y %H:%M:%S %Z")
if username:
post["username"] = username
yield Message.Directory, post
for post["num"], file in enumerate(files, 1):
@ -67,6 +75,7 @@ class KemonopartyUserExtractor(KemonopartyExtractor):
KemonopartyExtractor.__init__(self, match)
service, user_id = match.groups()
self.api_url = "{}/api/{}/user/{}".format(self.root, service, user_id)
self.user_url = "{}/{}/user/{}".format(self.root, service, user_id)
def posts(self):
url = self.api_url
@ -125,6 +134,7 @@ class KemonopartyPostExtractor(KemonopartyExtractor):
service, user_id, post_id = match.groups()
self.api_url = "{}/api/{}/user/{}/post/{}".format(
self.root, service, user_id, post_id)
self.user_url = "{}/{}/user/{}".format(self.root, service, user_id)
def posts(self):
posts = self.request(self.api_url).json()