Skip to content

Commit

Permalink
[pixiv] use api for illust series
Browse files Browse the repository at this point in the history
  • Loading branch information
mix5003 committed Aug 10, 2024
1 parent 269b280 commit 6b22282
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions gallery_dl/extractor/pixiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 += 30

works.reverse()

page = 0
for work in works:
page += 1

work["num_series"] = page
work["series"] = series

yield work


class PixivNovelExtractor(PixivExtractor):
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6b22282

Please sign in to comment.