New embed format, also closes #168
This commit is contained in:
parent
bf82e2e27e
commit
fd74f70044
26
msgs.py
26
msgs.py
@ -8,12 +8,13 @@ tweetSuspended="This Tweet is from a suspended account."
|
|||||||
|
|
||||||
videoDescLimit=220
|
videoDescLimit=220
|
||||||
tweetDescLimit=340
|
tweetDescLimit=340
|
||||||
|
providerLimit=220
|
||||||
|
|
||||||
def genLikesDisplay(vnf):
|
def genLikesDisplay(vnf):
|
||||||
if vnf['retweets'] > 0:
|
if vnf['retweets'] > 0:
|
||||||
return ("\n\n💖 " + numerize.numerize(vnf['likes']) + " 🔁 " + numerize.numerize(vnf['retweets']))
|
return ("💖 " + numerize.numerize(vnf['likes']) + " 🔁 " + numerize.numerize(vnf['retweets']))
|
||||||
else:
|
else:
|
||||||
return ("\n\n💖 " + numerize.numerize(vnf['likes']))
|
return ("💖 " + numerize.numerize(vnf['likes']))
|
||||||
|
|
||||||
def genQrtDisplay(qrt):
|
def genQrtDisplay(qrt):
|
||||||
verifiedCheck = "☑️" if ('verified' in qrt and qrt['verified']) else ""
|
verifiedCheck = "☑️" if ('verified' in qrt and qrt['verified']) else ""
|
||||||
@ -26,7 +27,18 @@ def genPollDisplay(poll):
|
|||||||
output+=choice["name"]+"\n"+("█"*int(choice["percent"]/pctSplit)) +" "+str(choice["percent"])+"%\n"
|
output+=choice["name"]+"\n"+("█"*int(choice["percent"]/pctSplit)) +" "+str(choice["percent"])+"%\n"
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def formatEmbedDesc(type,body,qrt,pollData,likesDisplay):
|
# formats the top text of the embed
|
||||||
|
def formatProvider(base,vnf):
|
||||||
|
finalText = base
|
||||||
|
likes = genLikesDisplay(vnf)
|
||||||
|
finalText += "\n" + likes
|
||||||
|
if ('communityNote' in vnf and vnf['communityNote'] != None):
|
||||||
|
finalText += "\n⚠️ Has community note"
|
||||||
|
if len(finalText) > providerLimit:
|
||||||
|
finalText = base
|
||||||
|
return finalText
|
||||||
|
|
||||||
|
def formatEmbedDesc(type,body,qrt,pollData):
|
||||||
# Trim the embed description to 248 characters, prioritizing poll and likes
|
# Trim the embed description to 248 characters, prioritizing poll and likes
|
||||||
|
|
||||||
qrtType=None
|
qrtType=None
|
||||||
@ -51,16 +63,16 @@ def formatEmbedDesc(type,body,qrt,pollData,likesDisplay):
|
|||||||
qrt=None
|
qrt=None
|
||||||
|
|
||||||
if type=="" or type=="Video":
|
if type=="" or type=="Video":
|
||||||
output = body+pollDisplay+likesDisplay
|
output = body+pollDisplay
|
||||||
elif qrt==None:
|
elif qrt==None:
|
||||||
output= body+pollDisplay+likesDisplay
|
output= body+pollDisplay
|
||||||
else:
|
else:
|
||||||
output= body + likesDisplay
|
output= body
|
||||||
if len(output)>limit:
|
if len(output)>limit:
|
||||||
# find out how many characters we need to remove
|
# find out how many characters we need to remove
|
||||||
diff = len(output)-limit
|
diff = len(output)-limit
|
||||||
# remove the characters from body, add ellipsis
|
# remove the characters from body, add ellipsis
|
||||||
body = body[:-(diff+1)]+"…"
|
body = body[:-(diff+1)]+"…"
|
||||||
return formatEmbedDesc(type,body,qrt,pollData,likesDisplay)
|
return formatEmbedDesc(type,body,qrt,pollData)
|
||||||
else:
|
else:
|
||||||
return output
|
return output
|
||||||
|
@ -23,5 +23,5 @@
|
|||||||
|
|
||||||
<meta property="og:description" content="{{ desc }}" />
|
<meta property="og:description" content="{{ desc }}" />
|
||||||
|
|
||||||
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user=Twitter&link={{ tweetLink }}&ttype=photo&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
|
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user=Twitter&link={{ tweetLink }}&ttype=photo&provider={{ appname|urlencode }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
|
||||||
<meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}
|
<meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}
|
@ -1,30 +0,0 @@
|
|||||||
{% extends 'base.html' %} {% block head %}
|
|
||||||
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
|
|
||||||
<meta content="{{ color }}" name="theme-color" />
|
|
||||||
<meta property="og:site_name" content="{{ appname }}">
|
|
||||||
|
|
||||||
<meta name="twitter:card" content="player" />
|
|
||||||
<meta name="twitter:title" content="{{ user }}" />
|
|
||||||
<meta name="twitter:image" content="{{ pic }}" />
|
|
||||||
<!-- The line below breaks Telegram embeds if present but doesn't affect Discord embeds if removed
|
|
||||||
<meta name="twitter:player" content="{{ vidurl }}" />
|
|
||||||
<meta name="twitter:description" content="{{ desc }}" />!-->
|
|
||||||
<meta name="twitter:player:width" content="720" />
|
|
||||||
<meta name="twitter:player:height" content="480" />
|
|
||||||
<meta name="twitter:player:stream" content="{{ vidurl }}" />
|
|
||||||
<meta name="twitter:player:stream:content_type" content="video/mp4" />
|
|
||||||
|
|
||||||
|
|
||||||
<meta property="og:url" content="{{ vidlink }}" />
|
|
||||||
<meta property="og:video" content="{{ vidurl }}" />
|
|
||||||
<meta property="og:video:secure_url" content="{{ vidurl }}" />
|
|
||||||
<meta property="og:video:type" content="video/mp4" />
|
|
||||||
<meta property="og:video:width" content="720" />
|
|
||||||
<meta property="og:video:height" content="480" />
|
|
||||||
<meta property="og:title" content="{{ user }}" />
|
|
||||||
<!--<meta property="og:description" content="{{ desc }}" />!-->
|
|
||||||
<meta property="og:image" content="{{ pic[0] }}" />
|
|
||||||
|
|
||||||
<!--!-->
|
|
||||||
<link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ tweetLink }}" type="application/json+oembed" title="{{ user }}">
|
|
||||||
<meta http-equiv="refresh" content="0; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}
|
|
@ -9,5 +9,5 @@
|
|||||||
|
|
||||||
<meta property="og:description" content="{{ desc }}" />
|
<meta property="og:description" content="{{ desc }}" />
|
||||||
|
|
||||||
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user=Twitter&link={{ tweetLink }}&ttype=link&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
|
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user=Twitter&link={{ tweetLink }}&ttype=link&provider={{ appname|urlencode }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
|
||||||
<meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}
|
<meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}
|
@ -18,5 +18,5 @@
|
|||||||
<meta property="og:image" content="{{ media['thumbnail_url'] }}" />
|
<meta property="og:image" content="{{ media['thumbnail_url'] }}" />
|
||||||
<meta property="og:description" content="{{ desc }}" />
|
<meta property="og:description" content="{{ desc }}" />
|
||||||
|
|
||||||
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user={{ urlEncodedDesc }}&link={{ tweetLink }}&ttype=video&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
|
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user={{ urlEncodedDesc }}&link={{ tweetLink }}&ttype=video&provider={{ appname|urlencode }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
|
||||||
<meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a>{% endblock %}
|
<meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a>{% endblock %}
|
12
twitfix.py
12
twitfix.py
@ -76,7 +76,7 @@ def message(text):
|
|||||||
|
|
||||||
def renderImageTweetEmbed(tweetData,image,appnameSuffix=""):
|
def renderImageTweetEmbed(tweetData,image,appnameSuffix=""):
|
||||||
qrt = tweetData['qrt']
|
qrt = tweetData['qrt']
|
||||||
embedDesc = msgs.formatEmbedDesc("Image",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData))
|
embedDesc = msgs.formatEmbedDesc("Image",tweetData['text'],qrt,tweetData['pollData'])
|
||||||
|
|
||||||
if image.startswith("https://pbs.twimg.com") and "?" not in image:
|
if image.startswith("https://pbs.twimg.com") and "?" not in image:
|
||||||
image = f"{image}?name=orig"
|
image = f"{image}?name=orig"
|
||||||
@ -88,12 +88,12 @@ def renderImageTweetEmbed(tweetData,image,appnameSuffix=""):
|
|||||||
desc=embedDesc,
|
desc=embedDesc,
|
||||||
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
||||||
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
||||||
appname=config['config']['appname']+appnameSuffix,
|
appname=msgs.formatProvider(config['config']['appname']+appnameSuffix,tweetData),
|
||||||
)
|
)
|
||||||
|
|
||||||
def renderVideoTweetEmbed(tweetData,mediaInfo,appnameSuffix=""):
|
def renderVideoTweetEmbed(tweetData,mediaInfo,appnameSuffix=""):
|
||||||
qrt = tweetData['qrt']
|
qrt = tweetData['qrt']
|
||||||
embedDesc = msgs.formatEmbedDesc("Video",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData))
|
embedDesc = msgs.formatEmbedDesc("Video",tweetData['text'],qrt,tweetData['pollData'])
|
||||||
|
|
||||||
mediaInfo=fixMedia(mediaInfo)
|
mediaInfo=fixMedia(mediaInfo)
|
||||||
return render_template("video.html",
|
return render_template("video.html",
|
||||||
@ -103,19 +103,19 @@ def renderVideoTweetEmbed(tweetData,mediaInfo,appnameSuffix=""):
|
|||||||
desc=embedDesc,
|
desc=embedDesc,
|
||||||
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
||||||
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
||||||
appname=config['config']['appname']+appnameSuffix,
|
appname=msgs.formatProvider(config['config']['appname']+appnameSuffix,tweetData),
|
||||||
)
|
)
|
||||||
|
|
||||||
def renderTextTweetEmbed(tweetData,appnameSuffix=""):
|
def renderTextTweetEmbed(tweetData,appnameSuffix=""):
|
||||||
qrt = tweetData['qrt']
|
qrt = tweetData['qrt']
|
||||||
embedDesc = msgs.formatEmbedDesc("Text",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData))
|
embedDesc = msgs.formatEmbedDesc("Text",tweetData['text'],qrt,tweetData['pollData'])
|
||||||
return render_template("text.html",
|
return render_template("text.html",
|
||||||
tweet=tweetData,
|
tweet=tweetData,
|
||||||
host=config['config']['url'],
|
host=config['config']['url'],
|
||||||
desc=embedDesc,
|
desc=embedDesc,
|
||||||
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
||||||
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
||||||
appname=config['config']['appname']+appnameSuffix,
|
appname=msgs.formatProvider(config['config']['appname']+appnameSuffix,tweetData),
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route('/robots.txt')
|
@app.route('/robots.txt')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user