[reddit] prevent crash for galleries with no 'media_metadata'
(fixes #2001)
This commit is contained in:
@@ -112,12 +112,18 @@ class RedditExtractor(Extractor):
|
|||||||
"""Return an iterable containing all (submission, comments) tuples"""
|
"""Return an iterable containing all (submission, comments) tuples"""
|
||||||
|
|
||||||
def _extract_gallery(self, submission):
|
def _extract_gallery(self, submission):
|
||||||
if submission["gallery_data"] is None:
|
gallery = submission["gallery_data"]
|
||||||
|
if gallery is None:
|
||||||
self.log.warning("gallery %s: deleted", submission["id"])
|
self.log.warning("gallery %s: deleted", submission["id"])
|
||||||
return
|
return
|
||||||
|
|
||||||
meta = submission["media_metadata"]
|
meta = submission.get("media_metadata")
|
||||||
for item in submission["gallery_data"]["items"]:
|
if meta is None:
|
||||||
|
self.log.warning("gallery %s: missing 'media_metadata'",
|
||||||
|
submission["id"])
|
||||||
|
return
|
||||||
|
|
||||||
|
for item in gallery["items"]:
|
||||||
data = meta[item["media_id"]]
|
data = meta[item["media_id"]]
|
||||||
if data["status"] != "valid" or "s" not in data:
|
if data["status"] != "valid" or "s" not in data:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
@@ -221,6 +227,10 @@ class RedditSubmissionExtractor(RedditExtractor):
|
|||||||
("https://www.reddit.com/r/cosplay/comments/jvwaqr", {
|
("https://www.reddit.com/r/cosplay/comments/jvwaqr", {
|
||||||
"count": 1,
|
"count": 1,
|
||||||
}),
|
}),
|
||||||
|
# gallery with no 'media_metadata' (#2001)
|
||||||
|
("https://www.reddit.com/r/kpopfap/comments/qjj04q/", {
|
||||||
|
"count": 0,
|
||||||
|
}),
|
||||||
("https://old.reddit.com/r/lavaporn/comments/2a00np/"),
|
("https://old.reddit.com/r/lavaporn/comments/2a00np/"),
|
||||||
("https://np.reddit.com/r/lavaporn/comments/2a00np/"),
|
("https://np.reddit.com/r/lavaporn/comments/2a00np/"),
|
||||||
("https://m.reddit.com/r/lavaporn/comments/2a00np/"),
|
("https://m.reddit.com/r/lavaporn/comments/2a00np/"),
|
||||||
|
|||||||
Reference in New Issue
Block a user