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): def items(self):
data = self.metadata() data = self.metadata()
yield Message.Directory, data 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"] url = image["url"]
image.update(data) image.update(data)
image["num"] = num
yield Message.Url, url, text.nameext_from_url(url, image) yield Message.Url, url, text.nameext_from_url(url, image)
def metadata(self): def metadata(self):
@ -105,18 +114,20 @@ class PornhubGalleryExtractor(PornhubExtractor):
images = response.json() images = response.json()
key = end = self._first key = end = self._first
while True: results = []
img = images[key] try:
yield { while True:
"url" : img["img_large"], img = images[key]
"caption": img["caption"], results.append(img)
"id" : text.parse_int(img["id"]), key = str(img["next"])
"views" : text.parse_int(img["times_viewed"]), if key == end:
"score" : text.parse_int(img["vote_percent"]), break
} except KeyError:
key = str(img["next"]) self.log.warning("%s: Unable to ensure correct file order",
if key == end: self.gallery_id)
return return images.values()
return results
class PornhubGifExtractor(PornhubExtractor): 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", "#url" : "https://www.pornhub.com/album/69040172",
"#category": ("", "pornhub", "gallery"), "#category": ("", "pornhub", "gallery"),
@ -112,7 +119,7 @@ __tests__ = (
"#category": ("", "pornhub", "gifs"), "#category": ("", "pornhub", "gifs"),
"#class" : pornhub.PornhubGifsExtractor, "#class" : pornhub.PornhubGifsExtractor,
"#pattern" : pornhub.PornhubGifExtractor.pattern, "#pattern" : pornhub.PornhubGifExtractor.pattern,
"#count" : ">= 42", "#count" : ">= 30",
}, },
{ {