[pixiv] prevent exceptions during 'comments' extraction (#6965)

- wrap in try-except block
- do not attempt to fetch comments for 'sanity_level' works
This commit is contained in:
Mike Fährmann
2025-02-10 09:56:09 +01:00
parent 6c2b6d50cc
commit 587205bf68
2 changed files with 8 additions and 4 deletions

View File

@@ -71,9 +71,12 @@ class PixivExtractor(Extractor):
if self.meta_user:
work.update(self.api.user_detail(work["user"]["id"]))
if self.meta_comments:
if work["total_comments"]:
work["comments"] = list(
self.api.illust_comments(work["id"]))
if work["total_comments"] and not work.get("_ajax"):
try:
work["comments"] = list(
self.api.illust_comments(work["id"]))
except Exception:
work["comments"] = ()
else:
work["comments"] = ()
if self.meta_bookmark and work["is_bookmarked"]:

View File

@@ -200,11 +200,12 @@ __tests__ = (
"#url" : "https://www.pixiv.net/en/artworks/102932581",
"#comment" : "limit_sanity_level_360.png (#4327, #5180)",
"#class" : pixiv.PixivWorkExtractor,
"#options" : {"sanity": True},
"#options" : {"sanity": True, "comments": True},
"#urls" : "https://i.pximg.net/img-original/img/2022/11/20/00/00/49/102932581_p0.jpg",
"caption" : "Meet a deer .",
"comment_access_control": 0,
"comments" : (),
"create_date" : "2022-11-19T15:00:00+00:00",
"date" : "dt:2022-11-19 15:00:00",
"date_url" : "dt:2022-11-19 15:00:49",