[pixiv] fix exception when processing deleted sanity_level work (#6339)

https://github.com/mikf/gallery-dl/issues/6339#issuecomment-2427350524
This commit is contained in:
Mike Fährmann
2024-10-21 20:35:48 +02:00
parent 9a2bccd0d9
commit 2d15e64ea9
2 changed files with 11 additions and 3 deletions

View File

@@ -77,7 +77,7 @@ class PixivExtractor(Extractor):
work["tags_bookmark"] = [tag["name"] for tag in detail["tags"] work["tags_bookmark"] = [tag["name"] for tag in detail["tags"]
if tag["is_registered"]] if tag["is_registered"]]
if self.sanity_workaround and not work.get("caption") and \ if self.sanity_workaround and not work.get("caption") and \
not work.get("_mypixiv"): not work.get("_mypixiv") and not work.get("_ajax"):
body = self._request_ajax("/illust/" + str(work["id"])) body = self._request_ajax("/illust/" + str(work["id"]))
if body: if body:
work["caption"] = text.unescape(body["illustComment"]) work["caption"] = text.unescape(body["illustComment"])
@@ -186,6 +186,7 @@ class PixivExtractor(Extractor):
return None return None
def _extract_ajax(self, work, body): def _extract_ajax(self, work, body):
work["_ajax"] = True
url = self._extract_ajax_url(body) url = self._extract_ajax_url(body)
if not url: if not url:
return () return ()
@@ -243,12 +244,12 @@ class PixivExtractor(Extractor):
original = body["urls"]["original"] original = body["urls"]["original"]
if original: if original:
return original return original
except KeyError: except Exception:
pass pass
try: try:
square1200 = body["userIllusts"][body["id"]]["url"] square1200 = body["userIllusts"][body["id"]]["url"]
except KeyError: except Exception:
return return
parts = square1200.rpartition("_p0")[0].split("/") parts = square1200.rpartition("_p0")[0].split("/")
del parts[3:5] del parts[3:5]

View File

@@ -266,6 +266,13 @@ __tests__ = (
], ],
}, },
{
"#url" : "https://www.pixiv.net/en/artworks/104582860",
"#comment" : "deleted limit_sanity_level_360.png work (#6339)",
"#class" : pixiv.PixivWorkExtractor,
"#count" : 0,
},
{ {
"#url" : "https://www.pixiv.net/en/artworks/103983466", "#url" : "https://www.pixiv.net/en/artworks/103983466",
"#comment" : "empty 'caption' in App API response (#4327, #5191)", "#comment" : "empty 'caption' in App API response (#4327, #5191)",