From b201bdcf2e28b9beeeaeb86d11f393fe8f427e37 Mon Sep 17 00:00:00 2001 From: adryd Date: Sat, 19 Mar 2022 20:37:28 -0400 Subject: [PATCH] Re-add quality sorting --- twitfix.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/twitfix.py b/twitfix.py index cafde1a..94fd17b 100644 --- a/twitfix.py +++ b/twitfix.py @@ -393,12 +393,12 @@ def link_to_vnf_from_api(video_link): print(" ➤ [ + ] Tweet Type: " + tweetType(tweet)) # Check to see if tweet has a video, if not, make the url passed to the VNF the first t.co link in the tweet if tweetType(tweet) == "Video": - if tweet['extended_entities']['media'][0]['video_info']['variants'][-1]['content_type'] == "video/mp4": - url = tweet['extended_entities']['media'][0]['video_info']['variants'][-1]['url'] - thumb = tweet['extended_entities']['media'][0]['media_url'] - else: - url = tweet['extended_entities']['media'][0]['video_info']['variants'][-2]['url'] + if tweet['extended_entities']['media'][0]['video_info']['variants']: + best_bitrate = 0 thumb = tweet['extended_entities']['media'][0]['media_url'] + for video in tweet['extended_entities']['media'][0]['video_info']['variants']: + if video.content_type == "video/mp4" and video.bitrate > best_bitrate: + url = video.url elif tweetType(tweet) == "Text": url = "" thumb = ""