[fanbox] return 'fileMap' files in order (#2718)
This commit is contained in:
@@ -95,26 +95,21 @@ class FanboxExtractor(Extractor):
|
|||||||
if "blocks" in content_body:
|
if "blocks" in content_body:
|
||||||
content = [] # text content
|
content = [] # text content
|
||||||
images = [] # image IDs in 'body' order
|
images = [] # image IDs in 'body' order
|
||||||
|
files = [] # file IDs in 'body' order
|
||||||
|
|
||||||
append = content.append
|
|
||||||
append_img = images.append
|
|
||||||
for block in content_body["blocks"]:
|
for block in content_body["blocks"]:
|
||||||
if "text" in block:
|
if "text" in block:
|
||||||
append(block["text"])
|
content.append(block["text"])
|
||||||
if "links" in block:
|
if "links" in block:
|
||||||
for link in block["links"]:
|
for link in block["links"]:
|
||||||
append(link["url"])
|
content.append(link["url"])
|
||||||
if "imageId" in block:
|
if "imageId" in block:
|
||||||
append_img(block["imageId"])
|
images.append(block["imageId"])
|
||||||
|
if "fileId" in block:
|
||||||
|
files.append(block["fileId"])
|
||||||
|
|
||||||
if images and "imageMap" in content_body:
|
self._sort_map(content_body, "imageMap", images)
|
||||||
# reorder 'imageMap' (#2718)
|
self._sort_map(content_body, "fileMap", files)
|
||||||
image_map = content_body["imageMap"]
|
|
||||||
content_body["imageMap"] = {
|
|
||||||
image_id: image_map[image_id]
|
|
||||||
for image_id in images
|
|
||||||
if image_id in image_map
|
|
||||||
}
|
|
||||||
|
|
||||||
post["content"] = "\n".join(content)
|
post["content"] = "\n".join(content)
|
||||||
|
|
||||||
@@ -145,6 +140,19 @@ class FanboxExtractor(Extractor):
|
|||||||
|
|
||||||
return content_body, post
|
return content_body, post
|
||||||
|
|
||||||
|
def _sort_map(self, body, key, ids):
|
||||||
|
orig = body.get(key)
|
||||||
|
if not orig:
|
||||||
|
return {} if orig is None else orig
|
||||||
|
|
||||||
|
body[key] = new = {
|
||||||
|
id: orig[id]
|
||||||
|
for id in ids
|
||||||
|
if id in orig
|
||||||
|
}
|
||||||
|
|
||||||
|
return new
|
||||||
|
|
||||||
@memcache(keyarg=1)
|
@memcache(keyarg=1)
|
||||||
def _get_user_data(self, creator_id):
|
def _get_user_data(self, creator_id):
|
||||||
url = "https://api.fanbox.cc/creator.get"
|
url = "https://api.fanbox.cc/creator.get"
|
||||||
|
|||||||
Reference in New Issue
Block a user