Fix KeyError: 'fallback_url'

This commit is contained in:
blank X 2020-12-04 11:44:50 +07:00
parent 9fcaaeb6cc
commit 47c2010f7f
1 changed files with 11 additions and 7 deletions

View File

@ -293,7 +293,8 @@ async def main():
url = None url = None
break break
else: else:
url = reddit_video['fallback_url'] if 'fallback_url' in reddit_video:
url = reddit_video['fallback_url']
elif getattr(random_post, 'is_gallery', None): elif getattr(random_post, 'is_gallery', None):
files = [] files = []
captions = [] captions = []
@ -352,12 +353,15 @@ async def main():
gfyitem = apidata.get('gfyItem') gfyitem = apidata.get('gfyItem')
if gfyitem: if gfyitem:
url = gfyitem.get('mp4Url', url) url = gfyitem.get('mp4Url', url)
elif random_post.is_reddit_media_domain and splitted[1] == '.gif' and preview: elif random_post.is_reddit_media_domain and preview:
preview = preview['images'][0]['variants'] ppreview = preview['images'][0]
for i in ('mp4', 'gif'): if splitted[1] == '.gif':
if i in preview: for i in ('mp4', 'gif'):
url = preview[i]['source']['url'] if i in ppreview['variants']:
break url = ppreview['variants'][i]['source']['url']
break
elif random_post.is_video:
url = ppreview['source']['url']
if url: if url:
url = urlunparse(urlparse(url, 'https')) url = urlunparse(urlparse(url, 'https'))
await _download_file(filename, url) await _download_file(filename, url)