[sankaku] update API URLs (#7154 #7155)

and fix errors due to other changes
This commit is contained in:
Mike Fährmann
2025-03-11 18:45:45 +01:00
parent 518865c7de
commit 1254c4e3d9
2 changed files with 51 additions and 20 deletions

View File

@@ -76,7 +76,7 @@ class SankakuExtractor(BooruExtractor):
def _tags(self, post, page):
tags = collections.defaultdict(list)
for tag in post["tags"]:
for tag in self.api.tags(post["id"]):
name = tag["name"]
if name:
tags[tag["type"]].append(name.lower().replace(" ", "_"))
@@ -112,11 +112,11 @@ class SankakuTagExtractor(SankakuExtractor):
if "date:" in self.tags:
# rewrite 'date:' tags (#1790)
self.tags = re.sub(
r"date:(\d\d)[.-](\d\d)[.-](\d\d\d\d)",
r"date:\3.\2.\1", self.tags)
r"date:(\d\d)[.-](\d\d)[.-](\d\d\d\d)(?!T)",
r"date:\3-\2-\1T00:00", self.tags)
self.tags = re.sub(
r"date:(\d\d\d\d)[.-](\d\d)[.-](\d\d)",
r"date:\1.\2.\3", self.tags)
r"date:(\d\d\d\d)[.-](\d\d)[.-](\d\d)(?!T)",
r"date:\1-\2-\3T00:00", self.tags)
def metadata(self):
return {"search_tags": self.tags}
@@ -209,6 +209,10 @@ class SankakuAPI():
params = {"lang": "en"}
return self._call("/posts/{}/notes".format(post_id), params)
def tags(self, post_id):
params = {"lang": "en"}
return self._call("/posts/{}/tags".format(post_id), params)["data"]
def pools(self, pool_id):
params = {"lang": "en"}
return self._call("/pools/" + pool_id, params)
@@ -216,6 +220,15 @@ class SankakuAPI():
def pools_keyset(self, params):
return self._pagination("/pools/keyset", params)
def pools_series(self, params):
params_ = {
"lang" : "en",
"filledPools": "true",
"includes[]" : "pools",
}
params_.update(params)
return self._pagination("/poolseriesv2", params)
def posts(self, post_id):
params = {
"lang" : "en",
@@ -223,17 +236,17 @@ class SankakuAPI():
"limit": "1",
"tags" : ("md5:" if len(post_id) == 32 else "id_range:") + post_id,
}
return self._call("/posts", params)
return self._call("/v2/posts", params)
def posts_keyset(self, params):
return self._pagination("/posts/keyset", params)
return self._pagination("/v2/posts/keyset", params)
def authenticate(self):
self.headers["Authorization"] = \
_authenticate_impl(self.extractor, self.username, self.password)
def _call(self, endpoint, params=None):
url = "https://capi-v2.sankakucomplex.com" + endpoint
url = "https://sankakuapi.com" + endpoint
for _ in range(5):
self.authenticate()
response = self.extractor.request(
@@ -311,7 +324,7 @@ class SankakuAPI():
def _authenticate_impl(extr, username, password):
extr.log.info("Logging in as %s", username)
url = "https://capi-v2.sankakucomplex.com/auth/token"
url = "https://sankakuapi.com/auth/token"
headers = {"Accept": "application/vnd.sankaku.api+json;v=2"}
data = {"login": username, "password": password}

View File

@@ -79,7 +79,7 @@ __tests__ = (
"#category": ("booru", "sankaku", "tag"),
"#class" : sankaku.SankakuTagExtractor,
"#options" : {"username": None},
"#exception": exception.StopExtraction,
"#exception": exception.AuthorizationError,
},
{
@@ -89,6 +89,15 @@ __tests__ = (
"#class" : sankaku.SankakuTagExtractor,
},
{
"#url" : "https://chan.sankakucomplex.com/?tags=date:2023-03-20T00:00",
"#comment" : "'date:' tags (#1790)",
"#category": ("booru", "sankaku", "tag"),
"#class" : sankaku.SankakuTagExtractor,
"#range" : "1",
"#count" : 1,
},
{
"#url" : "https://chan.sankakucomplex.com/?tags=date:2023-03-20",
"#comment" : "'date:' tags (#1790)",
@@ -102,7 +111,6 @@ __tests__ = (
"#url" : "https://sankaku.app/books/90",
"#category": ("booru", "sankaku", "pool"),
"#class" : sankaku.SankakuPoolExtractor,
"#count" : 5,
},
{
@@ -182,11 +190,14 @@ __tests__ = (
{
"body" : "A lonely person, is a lonely person, because he or she is lonely.",
"created_at": 1643733759,
"creator_id": 1370766,
# "creator_id": 1370766,
"creator_id": "WKaoQv7VRJ0",
"height" : 871,
"id" : 1832643,
# "id" : 1832643,
"id" : "e8M5EmNZMzv",
"is_active" : True,
"post_id" : 23688624,
# "post_id" : 23688624,
"post_id" : "VAr2mjLJ2av",
"updated_at": 1643733759,
"width" : 108,
"x" : 703,
@@ -196,22 +207,26 @@ __tests__ = (
},
{
"#url" : "https://sankaku.app/post/show/360451",
# "#url" : "https://sankaku.app/post/show/360451",
"#url" : "https://sankaku.app/post/show/y0abGlDOr2o",
"#comment" : "legacy post URL",
"#category": ("booru", "sankaku", "post"),
"#class" : sankaku.SankakuPostExtractor,
"#pattern" : r"https://s\.sankakucomplex\.com/data/ac/8e/ac8e3b92ea328ce9cf7211e69c905bf9\.jpg\?e=.+",
"id": 360451,
# "id": 360451,
"id": "y0abGlDOr2o",
},
{
"#url" : "https://sankaku.app/post/show/21418978",
"#url" : "https://www.sankakucomplex.com/posts/8JaGbKW4eML",
"#comment" : "'contentious_content'",
"#category": ("booru", "sankaku", "post"),
"#class" : sankaku.SankakuPostExtractor,
"#auth" : True,
"#pattern" : r"https://s\.sankakucomplex\.com/data/13/3c/133cda3bfde249c504284493903fb985\.jpg",
"md5": "133cda3bfde249c504284493903fb985",
},
{
@@ -244,7 +259,8 @@ __tests__ = (
"#pattern" : r"https://s\.sankakucomplex\.com/data/f8/ba/f8ba89043078f0e4be2d9c46550b840a\.jpg",
"#count" : 1,
"id" : 33195194,
# "id" : 33195194,
"id" : "k3R93nWBqaG",
"md5": "f8ba89043078f0e4be2d9c46550b840a",
},
@@ -256,7 +272,8 @@ __tests__ = (
"#pattern" : r"https://s\.sankakucomplex\.com/data/f8/ba/f8ba89043078f0e4be2d9c46550b840a\.jpg",
"#count" : 1,
"id" : 33195194,
# "id" : 33195194,
"id" : "k3R93nWBqaG",
"md5": "f8ba89043078f0e4be2d9c46550b840a",
},
@@ -266,7 +283,8 @@ __tests__ = (
"#category": ("booru", "sankaku", "post"),
"#class" : sankaku.SankakuPostExtractor,
"id" : 360451,
# "id" : 360451,
"id" : "y0abGlDOr2o",
"md5": "ac8e3b92ea328ce9cf7211e69c905bf9",
},