mirror of
https://github.com/mikf/gallery-dl.git
synced 2025-01-31 19:51:34 +01:00
[sankaku] implement 'notes' extraction (#5865)
This commit is contained in:
parent
7d5415c201
commit
287a7d13cf
@ -45,6 +45,9 @@ class SankakuExtractor(BooruExtractor):
|
||||
def skip(self, num):
|
||||
return 0
|
||||
|
||||
def _init(self):
|
||||
self.api = SankakuAPI(self)
|
||||
|
||||
def _file_url(self, post):
|
||||
url = post["file_url"]
|
||||
if not url:
|
||||
@ -81,6 +84,15 @@ class SankakuExtractor(BooruExtractor):
|
||||
post["tags_" + key] = value
|
||||
post["tag_string_" + key] = " ".join(value)
|
||||
|
||||
def _notes(self, post, page):
|
||||
if post.get("has_notes"):
|
||||
post["notes"] = self.api.notes(post["id"])
|
||||
for note in post["notes"]:
|
||||
note["created_at"] = note["created_at"]["s"]
|
||||
note["updated_at"] = note["updated_at"]["s"]
|
||||
else:
|
||||
post["notes"] = ()
|
||||
|
||||
|
||||
class SankakuTagExtractor(SankakuExtractor):
|
||||
"""Extractor for images from sankaku.app by search-tags"""
|
||||
@ -109,7 +121,7 @@ class SankakuTagExtractor(SankakuExtractor):
|
||||
|
||||
def posts(self):
|
||||
params = {"tags": self.tags}
|
||||
return SankakuAPI(self).posts_keyset(params)
|
||||
return self.api.posts_keyset(params)
|
||||
|
||||
|
||||
class SankakuPoolExtractor(SankakuExtractor):
|
||||
@ -125,7 +137,7 @@ class SankakuPoolExtractor(SankakuExtractor):
|
||||
self.pool_id = match.group(1)
|
||||
|
||||
def metadata(self):
|
||||
pool = SankakuAPI(self).pools(self.pool_id)
|
||||
pool = self.api.pools(self.pool_id)
|
||||
pool["tags"] = [tag["name"] for tag in pool["tags"]]
|
||||
pool["artist_tags"] = [tag["name"] for tag in pool["artist_tags"]]
|
||||
|
||||
@ -151,7 +163,7 @@ class SankakuPostExtractor(SankakuExtractor):
|
||||
self.post_id = match.group(1)
|
||||
|
||||
def posts(self):
|
||||
return SankakuAPI(self).posts(self.post_id)
|
||||
return self.api.posts(self.post_id)
|
||||
|
||||
|
||||
class SankakuBooksExtractor(SankakuExtractor):
|
||||
@ -167,7 +179,7 @@ class SankakuBooksExtractor(SankakuExtractor):
|
||||
|
||||
def items(self):
|
||||
params = {"tags": self.tags, "pool_type": "0"}
|
||||
for pool in SankakuAPI(self).pools_keyset(params):
|
||||
for pool in self.api.pools_keyset(params):
|
||||
pool["_extractor"] = SankakuPoolExtractor
|
||||
url = "https://sankaku.app/books/{}".format(pool["id"])
|
||||
yield Message.Queue, url, pool
|
||||
@ -192,6 +204,10 @@ class SankakuAPI():
|
||||
if not self.username:
|
||||
self.authenticate = util.noop
|
||||
|
||||
def notes(self, post_id):
|
||||
params = {"lang": "en"}
|
||||
return self._call("/posts/{}/notes".format(post_id), params)
|
||||
|
||||
def pools(self, pool_id):
|
||||
params = {"lang": "en"}
|
||||
return self._call("/pools/" + pool_id, params)
|
||||
|
@ -124,11 +124,13 @@ __tests__ = (
|
||||
"#class" : sankaku.SankakuPostExtractor,
|
||||
"#options" : {
|
||||
"tags" : True,
|
||||
"notes" : True,
|
||||
"id-format": "alphanumeric",
|
||||
},
|
||||
"#sha1_content": "5e255713cbf0a8e0801dc423563c34d896bb9229",
|
||||
|
||||
"id": "y0abGlDOr2o",
|
||||
"notes": [],
|
||||
"tags_artist": [
|
||||
"bonocho",
|
||||
],
|
||||
@ -149,6 +151,30 @@ __tests__ = (
|
||||
"tags_general": list,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://sankaku.app/posts/VAr2mjLJ2av",
|
||||
"#comment" : "notes (#5073)",
|
||||
"#category": ("booru", "sankaku", "post"),
|
||||
"#class" : sankaku.SankakuPostExtractor,
|
||||
"#options" : {"notes": True},
|
||||
|
||||
"notes": [
|
||||
{
|
||||
"body" : "A lonely person, is a lonely person, because he or she is lonely.",
|
||||
"created_at": 1643733759,
|
||||
"creator_id": 1370766,
|
||||
"height" : 871,
|
||||
"id" : 1832643,
|
||||
"is_active" : True,
|
||||
"post_id" : 23688624,
|
||||
"updated_at": 1643733759,
|
||||
"width" : 108,
|
||||
"x" : 703,
|
||||
"y" : 83,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://sankaku.app/post/show/360451",
|
||||
"#comment" : "legacy post URL",
|
||||
|
Loading…
x
Reference in New Issue
Block a user