1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-24 19:52:32 +01:00

[pornhub] fix KeyError when album images are missing (#6299)

This commit is contained in:
Mike Fährmann 2024-10-09 17:18:06 +02:00
parent d14d04adbf
commit 4adb1df55a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 33 additions and 15 deletions

View File

@ -66,10 +66,19 @@ class PornhubGalleryExtractor(PornhubExtractor):
def items(self):
data = self.metadata()
yield Message.Directory, data
for num, image in enumerate(self.images(), 1):
for num, img in enumerate(self.images(), 1):
image = {
"url" : img["img_large"],
"caption": img["caption"],
"id" : text.parse_int(img["id"]),
"views" : text.parse_int(img["times_viewed"]),
"score" : text.parse_int(img["vote_percent"]),
"num" : num,
}
url = image["url"]
image.update(data)
image["num"] = num
yield Message.Url, url, text.nameext_from_url(url, image)
def metadata(self):
@ -105,18 +114,20 @@ class PornhubGalleryExtractor(PornhubExtractor):
images = response.json()
key = end = self._first
while True:
img = images[key]
yield {
"url" : img["img_large"],
"caption": img["caption"],
"id" : text.parse_int(img["id"]),
"views" : text.parse_int(img["times_viewed"]),
"score" : text.parse_int(img["vote_percent"]),
}
key = str(img["next"])
if key == end:
return
results = []
try:
while True:
img = images[key]
results.append(img)
key = str(img["next"])
if key == end:
break
except KeyError:
self.log.warning("%s: Unable to ensure correct file order",
self.gallery_id)
return images.values()
return results
class PornhubGifExtractor(PornhubExtractor):

View File

@ -31,6 +31,13 @@ __tests__ = (
},
},
{
"#url" : "https://www.pornhub.com/album/69606532",
"#comment" : "KeyError due to missing image entry (#6299)",
"#class" : pornhub.PornhubGalleryExtractor,
"#count" : 6,
},
{
"#url" : "https://www.pornhub.com/album/69040172",
"#category": ("", "pornhub", "gallery"),
@ -112,7 +119,7 @@ __tests__ = (
"#category": ("", "pornhub", "gifs"),
"#class" : pornhub.PornhubGifsExtractor,
"#pattern" : pornhub.PornhubGifExtractor.pattern,
"#count" : ">= 42",
"#count" : ">= 30",
},
{