From 6e87ad2ccc8318e59c56dfd5147ef6f96cfa8824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 27 May 2025 18:04:35 +0200 Subject: [PATCH] [fanbox] extract 'archives' metadata (#7454) --- gallery_dl/extractor/fanbox.py | 16 ++++++++++++---- test/results/fanbox.py | 35 +++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/gallery_dl/extractor/fanbox.py b/gallery_dl/extractor/fanbox.py index aaa81135..7d5ab5ee 100644 --- a/gallery_dl/extractor/fanbox.py +++ b/gallery_dl/extractor/fanbox.py @@ -7,7 +7,7 @@ """Extractors for https://www.fanbox.cc/""" from .common import Extractor, Message -from .. import text +from .. import text, util from ..cache import memcache import re @@ -85,6 +85,7 @@ class FanboxExtractor(Extractor): """Fetch and process post data""" url = "https://api.fanbox.cc/post.info?postId="+post_id post = self.request(url, headers=self.headers).json()["body"] + post["archives"] = () content_body = post.pop("body", None) if content_body: @@ -108,11 +109,18 @@ class FanboxExtractor(Extractor): if "fileId" in block: files.append(block["fileId"]) - self._sort_map(content_body, "imageMap", images) - self._sort_map(content_body, "fileMap", files) - post["content"] = "\n".join(content) + self._sort_map(content_body, "imageMap", images) + file_map = self._sort_map(content_body, "fileMap", files) + if file_map: + exts = util.EXTS_ARCHIVE + post["archives"] = [ + file + for file in file_map.values() + if file.get("extension", "").lower() in exts + ] + post["date"] = text.parse_datetime(post["publishedDatetime"]) post["text"] = content_body.get("text") if content_body else None post["isCoverImage"] = False diff --git a/test/results/fanbox.py b/test/results/fanbox.py index 818c1294..0a4ecd24 100644 --- a/test/results/fanbox.py +++ b/test/results/fanbox.py @@ -106,7 +106,7 @@ __tests__ = ( "user": { "coverImageUrl" : "https://pixiv.pximg.net/c/1620x580_90_a2_g5/fanbox/public/images/creator/74349833/cover/n9mX8q4tUXHXXj7sK1RPWyUu.jpeg", "creatorId" : "official-en", - "description" : "This is the official English pixivFANBOX account! \n(official Japanese account: https://official.fanbox.cc/ )\n\npixivFANBOX is a subscription service for building a reliable fan community where creators can nurture creative lifestyles together with their fans.\nFollowers can be notified of the updates from their favorite creators they are following. Supporters can enjoy closer communication with creators through exclusive content and their latest information.\n", + "description" : "re:This is the official English pixivFANBOX account!.+", "hasAdultContent" : False, "hasBoothShop" : False, "iconUrl" : "https://pixiv.pximg.net/c/160x160_90_a2_g5/fanbox/public/images/user/74349833/icon/oJH0OoGoSixLrJXlnneNvC95.jpeg", @@ -153,9 +153,42 @@ __tests__ = ( "https://downloads.fanbox.cc/images/post/3746116/C93E7db3C3sBqbDw6gQoZBMz.jpeg", ], + "archives": (), "comments": "len:4", }, +{ + "#url" : "https://mochirong.fanbox.cc/posts/9809662", + "#comment" : "'archives' metadata (#7454)", + "#class" : fanbox.FanboxPostExtractor, + "#urls" : ( + "https://downloads.fanbox.cc/images/post/9809662/TUeXGybLxGVmzzrP8o3fhn27.jpeg", + "https://downloads.fanbox.cc/images/post/9809662/qt5fZBGxErXDAgBf2qgUZ1O8.jpeg", + "https://downloads.fanbox.cc/images/post/9809662/NvA7M0tIMGjA3sQxBqvdmwBm.jpeg", + "https://downloads.fanbox.cc/images/post/9809662/189bCj577YGtiBT7qCxVQJjK.jpeg", + "https://downloads.fanbox.cc/images/post/9809662/pYeCpfJYbojdj2VlyAwnh1oM.jpeg", + "https://downloads.fanbox.cc/files/post/9809662/8amsYwtWPtwcBVF4JnALM1ec.zip", + "https://downloads.fanbox.cc/files/post/9809662/6uhhqHYD4UvzVGx2I0QyLaiG.zip", + ), + + "archives": [ + { + "extension": "zip", + "id" : "8amsYwtWPtwcBVF4JnALM1ec", + "name" : "brushes", + "size" : 1087777, + "url" : "https://downloads.fanbox.cc/files/post/9809662/8amsYwtWPtwcBVF4JnALM1ec.zip", + }, + { + "extension": "zip", + "id" : "6uhhqHYD4UvzVGx2I0QyLaiG", + "name" : "Manual", + "size" : 3222, + "url" : "https://downloads.fanbox.cc/files/post/9809662/6uhhqHYD4UvzVGx2I0QyLaiG.zip", + }, + ], +}, + { "#url" : "https://fanbox.cc/", "#category": ("", "fanbox", "home"),