Skip to content

Commit

Permalink
[reddit] skip invalid/failed gallery items (fixes #1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Nov 21, 2020
1 parent 174945d commit 102c482
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions gallery_dl/extractor/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,25 @@ def submissions(self):

def _extract_gallery(self, submission):
if submission["gallery_data"] is None:
self.log.warning("gallery '%s' was deleted", submission["id"])
self.log.warning("gallery %s: deleted", submission["id"])
return

meta = submission["media_metadata"]
for item in submission["gallery_data"]["items"]:
src = meta[item["media_id"]]["s"]
data = meta[item["media_id"]]
if data["status"] != "valid" or "s" not in data:
self.log.warning(
"gallery %s: skipping item %s ('status: %s')",
submission["id"], item["media_id"], data.get("status"))
continue
src = data["s"]
url = src.get("u") or src.get("gif") or src.get("mp4")
if url:
yield url.partition("?")[0].replace("/preview.", "/i.", 1)
else:
self.log.error("Unable to get download URL for item '%s'",
item["media_id"])
self.log.error(
"gallery %s: unable to fetch download URL for item %s",
submission["id"], item["media_id"])
self.log.debug(src)


Expand Down Expand Up @@ -211,6 +218,10 @@ class RedditSubmissionExtractor(RedditExtractor):
"pattern": r"https://i\.redd\.it/\w+\.gif",
"count": 2,
}),
# "failed" gallery item (#1127)
("https://www.reddit.com/r/cosplay/comments/jvwaqr", {
"count": 1,
}),
("https://old.reddit.com/r/lavaporn/comments/2a00np/"),
("https://np.reddit.com/r/lavaporn/comments/2a00np/"),
("https://m.reddit.com/r/lavaporn/comments/2a00np/"),
Expand Down

0 comments on commit 102c482

Please sign in to comment.