Skip to content

Commit 1254c4e

Browse files
committed
[sankaku] update API URLs (#7154 #7155)
and fix errors due to other changes
1 parent 518865c commit 1254c4e

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

gallery_dl/extractor/sankaku.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _check_expired(self, response):
7676

7777
def _tags(self, post, page):
7878
tags = collections.defaultdict(list)
79-
for tag in post["tags"]:
79+
for tag in self.api.tags(post["id"]):
8080
name = tag["name"]
8181
if name:
8282
tags[tag["type"]].append(name.lower().replace(" ", "_"))
@@ -112,11 +112,11 @@ def __init__(self, match):
112112
if "date:" in self.tags:
113113
# rewrite 'date:' tags (#1790)
114114
self.tags = re.sub(
115-
r"date:(\d\d)[.-](\d\d)[.-](\d\d\d\d)",
116-
r"date:\3.\2.\1", self.tags)
115+
r"date:(\d\d)[.-](\d\d)[.-](\d\d\d\d)(?!T)",
116+
r"date:\3-\2-\1T00:00", self.tags)
117117
self.tags = re.sub(
118-
r"date:(\d\d\d\d)[.-](\d\d)[.-](\d\d)",
119-
r"date:\1.\2.\3", self.tags)
118+
r"date:(\d\d\d\d)[.-](\d\d)[.-](\d\d)(?!T)",
119+
r"date:\1-\2-\3T00:00", self.tags)
120120

121121
def metadata(self):
122122
return {"search_tags": self.tags}
@@ -209,31 +209,44 @@ def notes(self, post_id):
209209
params = {"lang": "en"}
210210
return self._call("/posts/{}/notes".format(post_id), params)
211211

212+
def tags(self, post_id):
213+
params = {"lang": "en"}
214+
return self._call("/posts/{}/tags".format(post_id), params)["data"]
215+
212216
def pools(self, pool_id):
213217
params = {"lang": "en"}
214218
return self._call("/pools/" + pool_id, params)
215219

216220
def pools_keyset(self, params):
217221
return self._pagination("/pools/keyset", params)
218222

223+
def pools_series(self, params):
224+
params_ = {
225+
"lang" : "en",
226+
"filledPools": "true",
227+
"includes[]" : "pools",
228+
}
229+
params_.update(params)
230+
return self._pagination("/poolseriesv2", params)
231+
219232
def posts(self, post_id):
220233
params = {
221234
"lang" : "en",
222235
"page" : "1",
223236
"limit": "1",
224237
"tags" : ("md5:" if len(post_id) == 32 else "id_range:") + post_id,
225238
}
226-
return self._call("/posts", params)
239+
return self._call("/v2/posts", params)
227240

228241
def posts_keyset(self, params):
229-
return self._pagination("/posts/keyset", params)
242+
return self._pagination("/v2/posts/keyset", params)
230243

231244
def authenticate(self):
232245
self.headers["Authorization"] = \
233246
_authenticate_impl(self.extractor, self.username, self.password)
234247

235248
def _call(self, endpoint, params=None):
236-
url = "https://capi-v2.sankakucomplex.com" + endpoint
249+
url = "https://sankakuapi.com" + endpoint
237250
for _ in range(5):
238251
self.authenticate()
239252
response = self.extractor.request(
@@ -311,7 +324,7 @@ def _pagination(self, endpoint, params):
311324
def _authenticate_impl(extr, username, password):
312325
extr.log.info("Logging in as %s", username)
313326

314-
url = "https://capi-v2.sankakucomplex.com/auth/token"
327+
url = "https://sankakuapi.com/auth/token"
315328
headers = {"Accept": "application/vnd.sankaku.api+json;v=2"}
316329
data = {"login": username, "password": password}
317330

test/results/sankaku.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"#category": ("booru", "sankaku", "tag"),
8080
"#class" : sankaku.SankakuTagExtractor,
8181
"#options" : {"username": None},
82-
"#exception": exception.StopExtraction,
82+
"#exception": exception.AuthorizationError,
8383
},
8484

8585
{
@@ -89,6 +89,15 @@
8989
"#class" : sankaku.SankakuTagExtractor,
9090
},
9191

92+
{
93+
"#url" : "https://chan.sankakucomplex.com/?tags=date:2023-03-20T00:00",
94+
"#comment" : "'date:' tags (#1790)",
95+
"#category": ("booru", "sankaku", "tag"),
96+
"#class" : sankaku.SankakuTagExtractor,
97+
"#range" : "1",
98+
"#count" : 1,
99+
},
100+
92101
{
93102
"#url" : "https://chan.sankakucomplex.com/?tags=date:2023-03-20",
94103
"#comment" : "'date:' tags (#1790)",
@@ -102,7 +111,6 @@
102111
"#url" : "https://sankaku.app/books/90",
103112
"#category": ("booru", "sankaku", "pool"),
104113
"#class" : sankaku.SankakuPoolExtractor,
105-
"#count" : 5,
106114
},
107115

108116
{
@@ -182,11 +190,14 @@
182190
{
183191
"body" : "A lonely person, is a lonely person, because he or she is lonely.",
184192
"created_at": 1643733759,
185-
"creator_id": 1370766,
193+
# "creator_id": 1370766,
194+
"creator_id": "WKaoQv7VRJ0",
186195
"height" : 871,
187-
"id" : 1832643,
196+
# "id" : 1832643,
197+
"id" : "e8M5EmNZMzv",
188198
"is_active" : True,
189-
"post_id" : 23688624,
199+
# "post_id" : 23688624,
200+
"post_id" : "VAr2mjLJ2av",
190201
"updated_at": 1643733759,
191202
"width" : 108,
192203
"x" : 703,
@@ -196,22 +207,26 @@
196207
},
197208

198209
{
199-
"#url" : "https://sankaku.app/post/show/360451",
210+
# "#url" : "https://sankaku.app/post/show/360451",
211+
"#url" : "https://sankaku.app/post/show/y0abGlDOr2o",
200212
"#comment" : "legacy post URL",
201213
"#category": ("booru", "sankaku", "post"),
202214
"#class" : sankaku.SankakuPostExtractor,
203215
"#pattern" : r"https://s\.sankakucomplex\.com/data/ac/8e/ac8e3b92ea328ce9cf7211e69c905bf9\.jpg\?e=.+",
204216

205-
"id": 360451,
217+
# "id": 360451,
218+
"id": "y0abGlDOr2o",
206219
},
207220

208221
{
209-
"#url" : "https://sankaku.app/post/show/21418978",
222+
"#url" : "https://www.sankakucomplex.com/posts/8JaGbKW4eML",
210223
"#comment" : "'contentious_content'",
211224
"#category": ("booru", "sankaku", "post"),
212225
"#class" : sankaku.SankakuPostExtractor,
213226
"#auth" : True,
214227
"#pattern" : r"https://s\.sankakucomplex\.com/data/13/3c/133cda3bfde249c504284493903fb985\.jpg",
228+
229+
"md5": "133cda3bfde249c504284493903fb985",
215230
},
216231

217232
{
@@ -244,7 +259,8 @@
244259
"#pattern" : r"https://s\.sankakucomplex\.com/data/f8/ba/f8ba89043078f0e4be2d9c46550b840a\.jpg",
245260
"#count" : 1,
246261

247-
"id" : 33195194,
262+
# "id" : 33195194,
263+
"id" : "k3R93nWBqaG",
248264
"md5": "f8ba89043078f0e4be2d9c46550b840a",
249265
},
250266

@@ -256,7 +272,8 @@
256272
"#pattern" : r"https://s\.sankakucomplex\.com/data/f8/ba/f8ba89043078f0e4be2d9c46550b840a\.jpg",
257273
"#count" : 1,
258274

259-
"id" : 33195194,
275+
# "id" : 33195194,
276+
"id" : "k3R93nWBqaG",
260277
"md5": "f8ba89043078f0e4be2d9c46550b840a",
261278
},
262279

@@ -266,7 +283,8 @@
266283
"#category": ("booru", "sankaku", "post"),
267284
"#class" : sankaku.SankakuPostExtractor,
268285

269-
"id" : 360451,
286+
# "id" : 360451,
287+
"id" : "y0abGlDOr2o",
270288
"md5": "ac8e3b92ea328ce9cf7211e69c905bf9",
271289
},
272290

0 commit comments

Comments
 (0)