[itaku] add 'posts' extractors (#7707)

This commit is contained in:
Mike Fährmann
2025-07-27 18:27:22 +02:00
parent be975b7be1
commit 022f216217
5 changed files with 168 additions and 4 deletions

View File

@@ -32,7 +32,6 @@ class ItakuExtractor(Extractor):
def items(self):
if images := self.images():
for image in images:
image["date"] = text.parse_datetime(
image["date_added"], "%Y-%m-%dT%H:%M:%S.%fZ")
for category, tags in image.pop("categorized_tags").items():
@@ -59,7 +58,20 @@ class ItakuExtractor(Extractor):
if posts := self.posts():
for post in posts:
...
images = post.pop("gallery_images") or ()
post["count"] = len(images)
post["date"] = text.parse_datetime(
post["date_added"], "%Y-%m-%dT%H:%M:%S.%fZ")
post["tags"] = [t["name"] for t in post["tags"]]
yield Message.Directory, post
for post["num"], image in enumerate(images, 1):
post["file"] = image
image["date"] = text.parse_datetime(
image["date_added"], "%Y-%m-%dT%H:%M:%S.%fZ")
url = image["image"]
yield Message.Url, url, text.nameext_from_url(url, post)
return
if users := self.users():
@@ -74,7 +86,7 @@ class ItakuExtractor(Extractor):
class ItakuGalleryExtractor(ItakuExtractor):
"""Extractor for posts from an itaku user gallery"""
"""Extractor for images from an itaku user gallery"""
subcategory = "gallery"
pattern = USER_PATTERN + r"/gallery(?:/(\d+))?"
example = "https://itaku.ee/profile/USER/gallery"
@@ -87,6 +99,24 @@ class ItakuGalleryExtractor(ItakuExtractor):
})
class ItakuPostsExtractor(ItakuExtractor):
"""Extractor for an itaku user's posts"""
subcategory = "posts"
directory_fmt = ("{category}", "{owner_username}", "Posts",
"{id}{title:? //}")
filename_fmt = "{file[id]}{file[title]:? //}.{extension}"
archive_fmt = "{id}_{file[id]}"
pattern = USER_PATTERN + r"/posts(?:/(\d+))?"
example = "https://itaku.ee/profile/USER/posts"
def posts(self):
user, folder = self.groups
return self.api.posts({
"owner" : self.api.user_id(user),
"folders": folder,
})
class ItakuStarsExtractor(ItakuExtractor):
subcategory = "stars"
pattern = USER_PATTERN + r"/stars(?:/(\d+))?"
@@ -132,6 +162,7 @@ class ItakuUserExtractor(Dispatch, ItakuExtractor):
base = f"{self.root}/profile/{self.groups[0]}/"
return self._dispatch_extractors((
(ItakuGalleryExtractor , base + "gallery"),
(ItakuPostsExtractor , base + "posts"),
(ItakuFollowersExtractor, base + "followers"),
(ItakuFollowingExtractor, base + "following"),
(ItakuStarsExtractor , base + "stara"),
@@ -147,6 +178,19 @@ class ItakuImageExtractor(ItakuExtractor):
return (self.api.image(self.groups[0]),)
class ItakuPostExtractor(ItakuExtractor):
subcategory = "post"
directory_fmt = ("{category}", "{owner_username}", "Posts",
"{id}{title:? //}")
filename_fmt = "{file[id]}{file[title]:? //}.{extension}"
archive_fmt = "{id}_{file[id]}"
pattern = BASE_PATTERN + r"/posts/(\d+)"
example = "https://itaku.ee/posts/12345"
def posts(self):
return (self.api.post(self.groups[0]),)
class ItakuSearchExtractor(ItakuExtractor):
subcategory = "search"
pattern = BASE_PATTERN + r"/home/images/?\?([^#]+)"
@@ -200,6 +244,19 @@ class ItakuAPI():
}
return self._pagination(endpoint, params, self.image)
def posts(self, params):
endpoint = "/posts/"
params = {
"cursor" : None,
"date_range": "",
"maturity_rating": ("SFW", "Questionable", "NSFW"),
"ordering" : "-date_added",
"page" : "1",
"page_size" : "30",
**params,
}
return self._pagination(endpoint, params)
def user_profiles(self, params):
endpoint = "/user_profiles/"
params = {
@@ -216,6 +273,10 @@ class ItakuAPI():
endpoint = f"/galleries/images/{image_id}/"
return self._call(endpoint)
def post(self, post_id):
endpoint = f"/posts/{post_id}/"
return self._call(endpoint)
@memcache(keyarg=1)
def user(self, username):
return self._call(f"/user_profiles/{username}/")