aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/kemonoparty.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/extractor/kemonoparty.py')
-rw-r--r--gallery_dl/extractor/kemonoparty.py42
1 files changed, 33 insertions, 9 deletions
diff --git a/gallery_dl/extractor/kemonoparty.py b/gallery_dl/extractor/kemonoparty.py
index 377e00b..1b5e5e9 100644
--- a/gallery_dl/extractor/kemonoparty.py
+++ b/gallery_dl/extractor/kemonoparty.py
@@ -26,24 +26,41 @@ 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 = []
- if post["file"]:
- files.append(post["file"])
- if post["attachments"]:
- files.extend(post["attachments"])
+ append = files.append
+ file = post["file"]
+
+ if file:
+ file["type"] = "file"
+ append(file)
+ for attachment in post["attachments"]:
+ attachment["type"] = "attachment"
+ append(attachment)
for path in find_inline(post["content"] or ""):
- files.append({"path": path, "name": path})
+ append({"path": path, "name": path, "type": "inline"})
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):
+ post["type"] = file["type"]
url = file["path"]
if url[0] == "/":
- url = self.root + url
+ url = "https://data.kemono.party" + url
+ elif url.startswith("https://kemono.party/"):
+ url = "https://data.kemono.party" + url[20:]
+
text.nameext_from_url(file["name"], post)
yield Message.Url, url, post
@@ -64,6 +81,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
@@ -84,7 +102,7 @@ class KemonopartyPostExtractor(KemonopartyExtractor):
pattern = BASE_PATTERN + r"/post/([^/?#]+)"
test = (
("https://kemono.party/fanbox/user/6993449/post/506575", {
- "pattern": r"https://kemono\.party/files/fanbox"
+ "pattern": r"https://data\.kemono\.party/files/fanbox"
r"/6993449/506575/P058kDFYus7DbqAkGlfWTlOr\.jpeg",
"keyword": {
"added": "Wed, 06 May 2020 20:28:02 GMT",
@@ -101,16 +119,21 @@ class KemonopartyPostExtractor(KemonopartyExtractor):
"shared_file": False,
"subcategory": "post",
"title": "c96取り置き",
+ "type": "file",
"user": "6993449",
},
}),
# inline image (#1286)
("https://kemono.party/fanbox/user/7356311/post/802343", {
- "pattern": r"https://kemono\.party/inline/fanbox"
+ "pattern": r"https://data\.kemono\.party/inline/fanbox"
r"/uaozO4Yga6ydkGIJFAQDixfE\.jpeg",
}),
+ # kemono.party -> data.kemono.party
+ ("https://kemono.party/gumroad/user/trylsc/post/IURjT", {
+ "pattern": r"https://data\.kemono\.party/(file|attachment)s"
+ r"/gumroad/trylsc/IURjT/",
+ }),
("https://kemono.party/subscribestar/user/alcorart/post/184330"),
- ("https://kemono.party/gumroad/user/trylsc/post/IURjT"),
)
def __init__(self, match):
@@ -118,6 +141,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()