From 8bcf7bf5ee926d05176df40d64a0b8c1711b430c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 6 Oct 2024 19:41:05 +0200 Subject: [PATCH] [pixiv] add 'comments' option (#6287) --- docs/configuration.rst | 34 +++++++++++++++++++++++++++++++++- gallery_dl/extractor/pixiv.py | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index df974e3f..fac36786 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1626,6 +1626,25 @@ Description ``gallery``. +extractor.civitai.include +------------------------- +Type + * ``string`` + * ``list`` of ``strings`` +Default + ``["user-models", "user-posts"]`` +Description + A (comma-separated) list of subcategories to include + when processing a user profile. + + Possible values are + ``"user-models"``, + ``"user-posts"``, + ``"user-images"``. + + It is possible to use ``"all"`` instead of listing all values separately. + + extractor.civitai.nsfw ---------------------- Type @@ -3465,7 +3484,20 @@ Description `your own account `__, fetch bookmark tags as ``tags_bookmark`` metadata. - Note: This requires 1 additional API call per bookmarked post. + Note: This requires 1 additional API request per bookmarked post. + + +extractor.pixiv.comments +------------------------ +Type + ``bool`` +Default + ``false`` +Description + Fetch ``comments`` metadata. + + Note: This requires 1 or more additional API requests per post, + depending on the number of comments. extractor.pixiv.work.related diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index 8642d0e1..aed78d1d 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -52,6 +52,7 @@ class PixivExtractor(Extractor): ratings = {0: "General", 1: "R-18", 2: "R-18G"} meta_user = self.config("metadata") meta_bookmark = self.config("metadata-bookmark") + meta_comments = self.config("comments") metadata = self.metadata() works = self.works() @@ -65,10 +66,17 @@ class PixivExtractor(Extractor): if meta_user: work.update(self.api.user_detail(work["user"]["id"])) + if meta_comments: + if work["total_comments"]: + work["comments"] = list( + self.api.illust_comments(work["id"])) + else: + work["comments"] = () if meta_bookmark and work["is_bookmarked"]: detail = self.api.illust_bookmark_detail(work["id"]) work["tags_bookmark"] = [tag["name"] for tag in detail["tags"] if tag["is_registered"]] + if transform_tags: transform_tags(work) work["num"] = 0 @@ -744,6 +752,7 @@ class PixivNovelExtractor(PixivExtractor): ratings = {0: "General", 1: "R-18", 2: "R-18G"} meta_user = self.config("metadata") meta_bookmark = self.config("metadata-bookmark") + meta_comments = self.config("comments") embeds = self.config("embeds") covers = self.config("covers") @@ -763,6 +772,12 @@ class PixivNovelExtractor(PixivExtractor): for novel in novels: if meta_user: novel.update(self.api.user_detail(novel["user"]["id"])) + if meta_comments: + if novel["total_comments"]: + novel["comments"] = list( + self.api.novel_comments(novel["id"])) + else: + novel["comments"] = () if meta_bookmark and novel["is_bookmarked"]: detail = self.api.novel_bookmark_detail(novel["id"]) novel["tags_bookmark"] = [tag["name"] for tag in detail["tags"] @@ -1030,6 +1045,10 @@ class PixivAppAPI(): return self._call( "/v2/illust/bookmark/detail", params)["bookmark_detail"] + def illust_comments(self, illust_id): + params = {"illust_id": illust_id} + return self._pagination("/v3/illust/comments", params, "comments") + def illust_follow(self, restrict="all"): params = {"restrict": restrict} return self._pagination("/v2/illust/follow", params) @@ -1052,6 +1071,10 @@ class PixivAppAPI(): return self._call( "/v2/novel/bookmark/detail", params)["bookmark_detail"] + def novel_comments(self, novel_id): + params = {"novel_id": novel_id} + return self._pagination("/v1/novel/comments", params, "comments") + def novel_detail(self, novel_id): params = {"novel_id": novel_id} return self._call("/v2/novel/detail", params)["novel"]