Skip to content

Commit

Permalink
add error handling when reddit media url cannot be determined
Browse files Browse the repository at this point in the history
  • Loading branch information
ggogel committed Feb 21, 2024
1 parent 9c0301d commit bb9f27e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions socialmediadownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,14 @@ async def handle_reddit(self, evt, url_tup):
file_name = media_id
await self.send_image(evt, media_url, mime_type, file_name)
return
if 'reddit_video' in post_data['secure_media']:
elif 'secure_media' in post_data and 'reddit_video' in post_data['secure_media']:
fallback_url = post_data['secure_media']['reddit_video']['fallback_url']
else:
elif 'preview' in post_data and 'reddit_video_preview' in post_data['preview']:
fallback_url = post_data['preview']['reddit_video_preview']['fallback_url']
else:
self.log.warning(f"Unable to determine media url for {query_url}")
return

media_url = fallback_url.split('?')[0]
mime_type = mimetypes.guess_type(media_url)[0]

Expand Down

0 comments on commit bb9f27e

Please sign in to comment.