Skip to content

Commit

Permalink
[pornhub] fix KeyError when album images are missing (#6299)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Oct 9, 2024
1 parent d14d04a commit 4adb1df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
39 changes: 25 additions & 14 deletions gallery_dl/extractor/pornhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ def __init__(self, match):
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):
Expand Down Expand Up @@ -105,18 +114,20 @@ def images(self):
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):
Expand Down
9 changes: 8 additions & 1 deletion test/results/pornhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
},
},

{
"#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"),
Expand Down Expand Up @@ -112,7 +119,7 @@
"#category": ("", "pornhub", "gifs"),
"#class" : pornhub.PornhubGifsExtractor,
"#pattern" : pornhub.PornhubGifExtractor.pattern,
"#count" : ">= 42",
"#count" : ">= 30",
},

{
Expand Down

0 comments on commit 4adb1df

Please sign in to comment.