From 0717456b4e0d1ca34652f9420436d47ed01bc0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 14 May 2021 19:54:16 +0200 Subject: [PATCH] [kemonoparty] add 'metadata' option (closes #1548) to fetch creator names with an additional HTTP request --- docs/configuration.rst | 10 ++++++++++ gallery_dl/extractor/kemonoparty.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/configuration.rst b/docs/configuration.rst index 4c73b2c1..e6aa99c4 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1176,6 +1176,16 @@ Description Download video files. +extractor.kemonoparty.metadata +------------------------------ +Type + ``bool`` +Default + ``false`` +Description + Extract ``username`` metadata + + extractor.khinsider.format -------------------------- Type diff --git a/gallery_dl/extractor/kemonoparty.py b/gallery_dl/extractor/kemonoparty.py index d0c0fe37..3abf11be 100644 --- a/gallery_dl/extractor/kemonoparty.py +++ b/gallery_dl/extractor/kemonoparty.py @@ -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, "", " | 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()