Merge branch 'main' of https://github.com/dylanpdx/BetterTwitFix into github/origin
Some checks failed
Run Tests / build (push) Failing after 2m11s

This commit is contained in:
2025-11-10 08:40:46 +01:00
11 changed files with 305 additions and 205 deletions

View File

@@ -67,13 +67,14 @@ def isValidUserAgent(user_agent):
return False
def message(text):
return render_template(
rendered = render_template(
'default.html',
message = text,
color = config['config']['color'],
appname = config['config']['appname'],
repo = config['config']['repo'],
url = config['config']['url'] )
return Response(rendered, mimetype='text/html',headers={"Cache-Tag": "message", "Cache-Control": "max-age=1760, public"})
def generateActivityLink(tweetData,media=None,mediatype=None,embedIndex=-1):
global user_agent
@@ -265,19 +266,13 @@ def getTweetData(twitter_url,include_txt="false",include_rtf="false"):
return cachedVNF
try:
rawTweetData = twExtract.extractStatusV2Anon(twitter_url, None)
if config['config']['workaroundTokens'] is not None:
workaroundTokens = config['config']['workaroundTokens'].split(",")
else:
workaroundTokens = None
rawTweetData = twExtract.extractStatus(twitter_url,workaroundTokens=workaroundTokens)
except:
rawTweetData = None
if rawTweetData is None:
try:
if config['config']['workaroundTokens'] is not None:
workaroundTokens = config['config']['workaroundTokens'].split(",")
else:
workaroundTokens = None
rawTweetData = twExtract.extractStatus(twitter_url,workaroundTokens=workaroundTokens)
except:
rawTweetData = None
if rawTweetData == None or 'error' in rawTweetData:
return None
@@ -291,14 +286,18 @@ def getTweetData(twitter_url,include_txt="false",include_rtf="false"):
return tweetData
def getUserData(twitter_url,includeFeed=False):
rawUserData = twExtract.extractUser(twitter_url,workaroundTokens=config['config']['workaroundTokens'].split(','))
if config['config']['workaroundTokens'] is not None:
workaroundTokens = config['config']['workaroundTokens'].split(",")
else:
workaroundTokens = None
rawUserData = twExtract.extractUser(twitter_url,workaroundTokens=workaroundTokens)
userData = getApiUserResponse(rawUserData)
if includeFeed:
if userData['protected']:
userData['latest_tweets']=[]
else:
feed = twExtract.extractUserFeedFromId(userData['id'],workaroundTokens=config['config']['workaroundTokens'].split(','))
feed = twExtract.extractUserFeedFromId(userData['id'],workaroundTokens=workaroundTokens)
apiFeed = []
for tweet in feed:
apiFeed.append(getApiResponse(tweet))
@@ -415,33 +414,33 @@ def twitfix(sub_path):
embeddingMedia = tweetData['hasMedia']
renderMedia = None
if embeddingMedia:
renderMedia = determineMediaToEmbed(tweetData,embedIndex)
renderMedia = determineMediaToEmbed(tweetData,embedIndex,convertGif=False)
# direct embeds should always prioritize the main tweet, so don't check for qrt
# determine what type of media we're dealing with
if not embeddingMedia and qrt is None:
return renderTextTweetEmbed(tweetData)
else:
if renderMedia['type'] == "image":
return render_template("rawimage.html",media=renderMedia)
return Response(render_template("rawimage.html",media=renderMedia),headers={"Cache-Tag": "embed"})
elif renderMedia['type'] == "video" or renderMedia['type'] == "gif":
return render_template("rawvideo.html",media=renderMedia)
return Response(render_template("rawvideo.html",media=renderMedia),headers={"Cache-Tag": "embed"})
else: # full embed
embedTweetData = determineEmbedTweet(tweetData)
embeddingMedia = embedTweetData['hasMedia']
if "article" in embedTweetData and embedTweetData["article"] is not None:
return renderArticleTweetEmbed(tweetData," • See original tweet for full article")
return Response(renderArticleTweetEmbed(tweetData," • See original tweet for full article"),headers={"Cache-Tag": "embed"})
elif not embeddingMedia:
return renderTextTweetEmbed(tweetData)
return Response(renderTextTweetEmbed(tweetData),headers={"Cache-Tag": "embed"})
else:
media = determineMediaToEmbed(embedTweetData,embedIndex)
suffix=""
if "suffix" in media:
suffix = media["suffix"]
if media['type'] == "image":
return renderImageTweetEmbed(tweetData,media['url'] , appnameSuffix=suffix,embedIndex=embedIndex)
return Response(renderImageTweetEmbed(tweetData,media['url'] , appnameSuffix=suffix,embedIndex=embedIndex),headers={"Cache-Tag": "embed"})
elif media['type'] == "video" or media['type'] == "gif":
return renderVideoTweetEmbed(tweetData,media,appnameSuffix=suffix,embedIndex=embedIndex)
return Response(renderVideoTweetEmbed(tweetData,media,appnameSuffix=suffix,embedIndex=embedIndex),headers={"Cache-Tag": "embed"})
return message(msgs.failedToScan)