[pixiv] incorporate into '_pagination'
This commit is contained in:
@@ -551,9 +551,6 @@ class PixivSeriesExtractor(PixivExtractor):
|
||||
directory_fmt = ("{category}", "{user[id]} {user[account]}",
|
||||
"{series[id]} {series[title]}")
|
||||
filename_fmt = "{num_series:>03}_{id}_p{num}.{extension}"
|
||||
cookies_domain = ".pixiv.net"
|
||||
browser = "firefox"
|
||||
tls12 = False
|
||||
pattern = BASE_PATTERN + r"/user/(\d+)/series/(\d+)"
|
||||
example = "https://www.pixiv.net/user/12345/series/12345"
|
||||
|
||||
@@ -562,38 +559,17 @@ class PixivSeriesExtractor(PixivExtractor):
|
||||
self.user_id, self.series_id = match.groups()
|
||||
|
||||
def works(self):
|
||||
offset = 0
|
||||
|
||||
series = None
|
||||
works = []
|
||||
while True:
|
||||
data = (self.api.illust_series(self.series_id, offset))
|
||||
|
||||
for work in self.api.illust_series(self.series_id):
|
||||
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'],
|
||||
}
|
||||
series = self.api.data
|
||||
series["total"] = num_series = series.pop("series_work_count")
|
||||
else:
|
||||
num_series -= 1
|
||||
|
||||
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["num_series"] = num_series
|
||||
work["series"] = series
|
||||
|
||||
yield work
|
||||
|
||||
|
||||
@@ -923,7 +899,8 @@ class PixivAppAPI():
|
||||
|
||||
def illust_series(self, series_id, offset=0):
|
||||
params = {"illust_series_id": series_id, "offset": offset}
|
||||
return self._call("/v1/illust/series", params)
|
||||
return self._pagination("/v1/illust/series", params,
|
||||
key_data="illust_series_detail")
|
||||
|
||||
def novel_bookmark_detail(self, novel_id):
|
||||
params = {"novel_id": novel_id}
|
||||
@@ -1022,10 +999,15 @@ class PixivAppAPI():
|
||||
|
||||
raise exception.StopExtraction("API request failed: %s", error)
|
||||
|
||||
def _pagination(self, endpoint, params, key="illusts"):
|
||||
def _pagination(self, endpoint, params,
|
||||
key_items="illusts", key_data=None):
|
||||
while True:
|
||||
data = self._call(endpoint, params)
|
||||
yield from data[key]
|
||||
|
||||
if key_data:
|
||||
self.data = data.get(key_data)
|
||||
key_data = None
|
||||
yield from data[key_items]
|
||||
|
||||
if not data["next_url"]:
|
||||
return
|
||||
|
||||
@@ -405,12 +405,14 @@ __tests__ = (
|
||||
|
||||
"num_series": int,
|
||||
"series" : {
|
||||
"canonical" : "https://www.pixiv.net/user/10509347/series/21859",
|
||||
"description": str,
|
||||
"ogp" : dict,
|
||||
"title" : "先輩がうざい後輩の話",
|
||||
"total" : int,
|
||||
"twitter" : dict,
|
||||
"create_date": "2017-10-22T14:07:42+09:00",
|
||||
"width" : 4250,
|
||||
"height": 3009,
|
||||
"id" : 21859,
|
||||
"title" : "先輩がうざい後輩の話",
|
||||
"total" : range(100, 500),
|
||||
"user" : dict,
|
||||
"watchlist_added": False,
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user