diff options
Diffstat (limited to 'gallery_dl/extractor/fanbox.py')
| -rw-r--r-- | gallery_dl/extractor/fanbox.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/gallery_dl/extractor/fanbox.py b/gallery_dl/extractor/fanbox.py index d8337b6..9bbfb43 100644 --- a/gallery_dl/extractor/fanbox.py +++ b/gallery_dl/extractor/fanbox.py @@ -29,7 +29,10 @@ class FanboxExtractor(Extractor): _warning = True def _init(self): - self.headers = {"Origin": self.root} + self.headers = { + "Accept": "application/json, text/plain, */*", + "Origin": self.root, + } self.embeds = self.config("embeds", True) includes = self.config("metadata") @@ -40,8 +43,12 @@ class FanboxExtractor(Extractor): includes = ("user", "plan") self._meta_user = ("user" in includes) self._meta_plan = ("plan" in includes) + self._meta_comments = ("comments" in includes) else: - self._meta_user = self._meta_plan = False + self._meta_user = self._meta_plan = self._meta_comments = False + + if self.config("comments"): + self._meta_comments = True if self._warning: if not self.cookies_check(("FANBOXSESSID",)): @@ -124,6 +131,11 @@ class FanboxExtractor(Extractor): plan = plans[0].copy() plan["fee"] = fee post["plan"] = plans[fee] = plan + if self._meta_comments: + if post["commentCount"]: + post["comments"] = list(self._get_comment_data(post_id)) + else: + post["commentd"] = () return content_body, post @@ -160,6 +172,18 @@ class FanboxExtractor(Extractor): return plans + def _get_comment_data(self, post_id): + url = ("https://api.fanbox.cc/post.listComments" + "?limit=10&postId=" + post_id) + + comments = [] + while url: + url = text.ensure_http_scheme(url) + body = self.request(url, headers=self.headers).json()["body"] + comments.extend(body["items"]) + url = body["nextUrl"] + return comments + def _get_urls_from_post(self, content_body, post): num = 0 cover_image = post.get("coverImageUrl") |
