[pixiv] provide fallback URLs (#6762)

This commit is contained in:
Mike Fährmann
2025-01-06 15:19:14 +01:00
parent 770f41eb4a
commit 270aaea8ab
2 changed files with 29 additions and 1 deletions

View File

@@ -111,6 +111,7 @@ class PixivExtractor(Extractor):
{
"url" : img["image_urls"]["original"],
"suffix": "_p{:02}".format(num),
"_fallback": self._fallback_image(img),
}
for num, img in enumerate(meta_pages)
]
@@ -128,7 +129,7 @@ class PixivExtractor(Extractor):
self.log.warning("%s: 'My pixiv' locked", work["id"])
elif work["type"] != "ugoira":
return ({"url": url},)
return ({"url": url, "_fallback": self._fallback_image(url)},)
elif self.load_ugoira:
try:
@@ -269,6 +270,24 @@ class PixivExtractor(Extractor):
except exception.HttpError:
pass
def _fallback_image(self, src):
if isinstance(src, str):
urls = None
orig = src
else:
urls = src["image_urls"]
orig = urls["original"]
base = orig.rpartition(".")[0]
yield base.replace("-original/", "-master/", 1) + "_master1200.jpg"
if urls is None:
return
for fmt in ("large", "medium", "square_medium"):
if fmt in urls:
yield urls[fmt]
@staticmethod
def _date_from_url(url, offset=timedelta(hours=9)):
try:

View File

@@ -289,6 +289,15 @@ __tests__ = (
"caption": r"re:Either she doesn't know how to pose or she can't move with that much clothing on her, in any case she's very well dressed for a holiday trip around town. Lots of stuff to see and a perfect day to grab some sweet pastries at the bakery.<br />...",
},
{
"#url" : "https://www.pixiv.net/artworks/56360615",
"#comment" : "fallback; 'original' version results in HTTP 500 error (#6762)",
"#class" : pixiv.PixivWorkExtractor,
"#options" : {"retries": 0},
"#range" : "4",
"#sha1_content": "aa119c27fec0a36bbd06e7491987acf5f1be6293",
},
{
"#url" : "https://www.pixiv.net/en/artworks/966412",
"#category": ("", "pixiv", "work"),