From b6a40217d6ffc1f6188410428f12d953c43eaaf2 Mon Sep 17 00:00:00 2001 From: mix5003 Date: Sat, 10 Aug 2024 11:04:36 +0700 Subject: [PATCH] [pixiv] use api for illust series --- gallery_dl/extractor/pixiv.py | 61 ++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index d732894a9c..f6fe21c708 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -562,34 +562,39 @@ def __init__(self, match): self.user_id, self.series_id = match.groups() def works(self): - url = self.root + "/ajax/series/" + self.series_id - params = {"p": 1} - headers = { - "Accept": "application/json", - "Referer": "{}/user/{}/series/{}".format( - self.root, self.user_id, self.series_id), - "Alt-Used": "www.pixiv.net", - } + offset = 0 + series = None + works = [] while True: - data = self.request(url, params=params, headers=headers).json() - body = data["body"] - page = body["page"] - - series = body["extraData"]["meta"] - series["id"] = self.series_id - series["total"] = page["total"] - series["title"] = text.extr(series["title"], '"', '"') - - for info in page["series"]: - work = self.api.illust_detail(info["workId"]) - work["num_series"] = info["order"] - work["series"] = series - yield work - - if len(page["series"]) < 10: - return - params["p"] += 1 + data = (self.api.illust_series(self.series_id, offset)) + + if series is None: + detail = data['illust_series_detail'] + series = { + 'id': self.series_id, + 'total': detail['series_work_count'], + 'title': detail["title"], + 'description': detail['caption'], + } + + works = works + data['illusts'] + + if data['next_url'] is None: + break + + offset = len(works) + + works.reverse() + + chapterNo = 0 + for work in works: + chapterNo += 1 + + work["num_series"] = chapterNo + work["series"] = series + + yield work class PixivNovelExtractor(PixivExtractor): @@ -916,6 +921,10 @@ def illust_related(self, illust_id): params = {"illust_id": illust_id} return self._pagination("/v2/illust/related", params) + def illust_series(self, series_id, offset=0): + params = {"illust_series_id": series_id, "offset": offset} + return self._call("/v1/illust/series", params) + def novel_bookmark_detail(self, novel_id): params = {"novel_id": novel_id} return self._call(