From a1b6ebe73e6e27ac41ea9c1fd111c6050adffd17 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 12 Jul 2023 22:11:34 +0100 Subject: [PATCH] Proper fix for API --- twitfix.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/twitfix.py b/twitfix.py index e7afd24..25eca06 100644 --- a/twitfix.py +++ b/twitfix.py @@ -108,6 +108,8 @@ def twitfix(sub_path): twitter_url = "https://twitter.com/" + sub_path try: tweet = twExtract.extractStatusV2(twitter_url) + if '__typename' in tweet and tweet['__typename'] == 'TweetWithVisibilityResults': + tweet=tweet['tweet'] tweetL = tweet["legacy"] userL = tweet["core"]["user_results"]["result"]["legacy"] media=[] @@ -118,12 +120,13 @@ def twitfix(sub_path): for i in tmedia: if "video_info" in i: # find the highest bitrate - highest = 0 + highest = -1 + besturl="" for j in i["video_info"]["variants"]: - if "bitrate" in j: - if j["bitrate"] > highest: - highest = j["bitrate"] - media.append(j["url"]) + if j['content_type'] == "video/mp4" and j['bitrate'] > best_bitrate: + besturl = j['url'] + best_bitrate = i['bitrate'] + media.append(besturl) else: media.append(i["media_url_https"]) if "hashtags" in tweetL["extended_entities"]: