[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.
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
----------------------
Type

View File

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

View File

@@ -182,11 +182,11 @@ class ItakuUserExtractor(Dispatch, ItakuExtractor):
def items(self):
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 + "stars"),
(ItakuGalleryExtractor , f"{base}gallery"),
(ItakuPostsExtractor , f"{base}posts"),
(ItakuFollowersExtractor, f"{base}followers"),
(ItakuFollowingExtractor, f"{base}following"),
(ItakuStarsExtractor , f"{base}stars"),
), ("gallery",))
@@ -246,7 +246,7 @@ class ItakuAPI():
def __init__(self, extractor):
self.extractor = extractor
self.root = extractor.root + "/api"
self.root = f"{extractor.root}/api"
self.headers = {
"Accept": "application/json, text/plain, */*",
}
@@ -257,7 +257,7 @@ class ItakuAPI():
"cursor" : None,
"date_range": "",
"maturity_rating": ("SFW", "Questionable", "NSFW"),
"ordering" : "-date_added",
"ordering" : self._order(),
"page" : "1",
"page_size" : "30",
"visibility": ("PUBLIC", "PROFILE_ONLY"),
@@ -271,7 +271,7 @@ class ItakuAPI():
"cursor" : None,
"date_range": "",
"maturity_rating": ("SFW", "Questionable", "NSFW"),
"ordering" : "-date_added",
"ordering" : self._order(),
"page" : "1",
"page_size" : "30",
**params,
@@ -282,7 +282,7 @@ class ItakuAPI():
endpoint = "/user_profiles/"
params = {
"cursor" : None,
"ordering" : "-date_added",
"ordering" : self._order(),
"page" : "1",
"page_size": "50",
"sfw_only" : "false",
@@ -309,7 +309,7 @@ class ItakuAPI():
def _call(self, endpoint, params=None):
if not endpoint.startswith("http"):
endpoint = self.root + endpoint
endpoint = f"{self.root}{endpoint}"
return self.extractor.request_json(
endpoint, params=params, headers=self.headers)
@@ -328,3 +328,11 @@ class ItakuAPI():
return
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"],
},
{
"#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",
"#class" : itaku.ItakuPostsExtractor,