[itaku] add 'order' option

This commit is contained in:
Mike Fährmann
2025-10-30 18:47:34 +01:00
parent 20bca3f2e4
commit 2194dde9ea
4 changed files with 50 additions and 10 deletions

View File

@@ -3707,6 +3707,24 @@ Note
It is possible to use ``"all"`` instead of listing all values separately. It is possible to use ``"all"`` instead of listing all values separately.
extractor.itaku.order
---------------------
Type
``string``
Default
``"desc"``
Description
Controls the order in which
images/posts/users are returned.
``"asc"`` | ``"reverse"``
Ascending order (oldest first)
``"desc"``
Descending order (newest first)
any other ``string``
Custom result order
extractor.itaku.videos extractor.itaku.videos
---------------------- ----------------------
Type Type

View File

@@ -474,6 +474,7 @@
{ {
"sleep-request": "0.5-1.5", "sleep-request": "0.5-1.5",
"include": "gallery", "include": "gallery",
"order" : "desc",
"videos" : true "videos" : true
}, },
"iwara": "iwara":

View File

@@ -182,11 +182,11 @@ class ItakuUserExtractor(Dispatch, ItakuExtractor):
def items(self): def items(self):
base = f"{self.root}/profile/{self.groups[0]}/" base = f"{self.root}/profile/{self.groups[0]}/"
return self._dispatch_extractors(( return self._dispatch_extractors((
(ItakuGalleryExtractor , base + "gallery"), (ItakuGalleryExtractor , f"{base}gallery"),
(ItakuPostsExtractor , base + "posts"), (ItakuPostsExtractor , f"{base}posts"),
(ItakuFollowersExtractor, base + "followers"), (ItakuFollowersExtractor, f"{base}followers"),
(ItakuFollowingExtractor, base + "following"), (ItakuFollowingExtractor, f"{base}following"),
(ItakuStarsExtractor , base + "stars"), (ItakuStarsExtractor , f"{base}stars"),
), ("gallery",)) ), ("gallery",))
@@ -246,7 +246,7 @@ class ItakuAPI():
def __init__(self, extractor): def __init__(self, extractor):
self.extractor = extractor self.extractor = extractor
self.root = extractor.root + "/api" self.root = f"{extractor.root}/api"
self.headers = { self.headers = {
"Accept": "application/json, text/plain, */*", "Accept": "application/json, text/plain, */*",
} }
@@ -257,7 +257,7 @@ class ItakuAPI():
"cursor" : None, "cursor" : None,
"date_range": "", "date_range": "",
"maturity_rating": ("SFW", "Questionable", "NSFW"), "maturity_rating": ("SFW", "Questionable", "NSFW"),
"ordering" : "-date_added", "ordering" : self._order(),
"page" : "1", "page" : "1",
"page_size" : "30", "page_size" : "30",
"visibility": ("PUBLIC", "PROFILE_ONLY"), "visibility": ("PUBLIC", "PROFILE_ONLY"),
@@ -271,7 +271,7 @@ class ItakuAPI():
"cursor" : None, "cursor" : None,
"date_range": "", "date_range": "",
"maturity_rating": ("SFW", "Questionable", "NSFW"), "maturity_rating": ("SFW", "Questionable", "NSFW"),
"ordering" : "-date_added", "ordering" : self._order(),
"page" : "1", "page" : "1",
"page_size" : "30", "page_size" : "30",
**params, **params,
@@ -282,7 +282,7 @@ class ItakuAPI():
endpoint = "/user_profiles/" endpoint = "/user_profiles/"
params = { params = {
"cursor" : None, "cursor" : None,
"ordering" : "-date_added", "ordering" : self._order(),
"page" : "1", "page" : "1",
"page_size": "50", "page_size": "50",
"sfw_only" : "false", "sfw_only" : "false",
@@ -309,7 +309,7 @@ class ItakuAPI():
def _call(self, endpoint, params=None): def _call(self, endpoint, params=None):
if not endpoint.startswith("http"): if not endpoint.startswith("http"):
endpoint = self.root + endpoint endpoint = f"{self.root}{endpoint}"
return self.extractor.request_json( return self.extractor.request_json(
endpoint, params=params, headers=self.headers) endpoint, params=params, headers=self.headers)
@@ -328,3 +328,11 @@ class ItakuAPI():
return return
data = self._call(url_next) data = self._call(url_next)
def _order(self):
if order := self.extractor.config("order"):
if order in {"a", "asc", "r", "reverse"}:
return "date_added"
if order not in {"d", "desc"}:
return order
return "-date_added"

View File

@@ -49,6 +49,19 @@ __tests__ = (
"sections" : ["Fanart/Pokemon"], "sections" : ["Fanart/Pokemon"],
}, },
{
"#url" : "https://itaku.ee/profile/piku/gallery/7391",
"#comment" : "'order' option",
"#class" : itaku.ItakuGalleryExtractor,
"#options" : {"order": "reverse"},
"#results" : (
"https://itaku.ee/api/media/gallery_imgs/bea_alpha_N0YGfeT.png",
"https://itaku.ee/api/media/gallery_imgs/misty-psyduck_IWbYdwT.png",
),
"sections" : ["Fanart/Pokemon"],
},
{ {
"#url" : "https://itaku.ee/profile/piku/posts", "#url" : "https://itaku.ee/profile/piku/posts",
"#class" : itaku.ItakuPostsExtractor, "#class" : itaku.ItakuPostsExtractor,