Native Discord multi image embeds
This commit is contained in:
parent
68bb83f069
commit
e427459016
@ -20,7 +20,20 @@
|
|||||||
|
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
<meta name="twitter:title" content="{{ user }} (@{{ screenName }}) {% if verified %}☑️{% else %}{% endif %}" />
|
<meta name="twitter:title" content="{{ user }} (@{{ screenName }}) {% if verified %}☑️{% else %}{% endif %}" />
|
||||||
<meta name="twitter:image" content="{{ pic }}" />
|
<meta name="twitter:image" content="{{ pic[0] }}" />
|
||||||
|
|
||||||
|
{% if pic[1] %}
|
||||||
|
<meta name="twitter:image" content="{{ pic[1] }}" />
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if pic[2] %}
|
||||||
|
<meta name="twitter:image" content="{{ pic[2] }}" />
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if pic[3] %}
|
||||||
|
<meta name="twitter:image" content="{{ pic[3] }}" />
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<meta name="twitter:creator" content="@{{ user }}" />
|
<meta name="twitter:creator" content="@{{ user }}" />
|
||||||
|
|
||||||
<meta property="og:description" content="{{ desc }}" />
|
<meta property="og:description" content="{{ desc }}" />
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<meta property="og:video:height" content="480" />
|
<meta property="og:video:height" content="480" />
|
||||||
<meta property="og:title" content="{{ user }}" />
|
<meta property="og:title" content="{{ user }}" />
|
||||||
<!--<meta property="og:description" content="{{ desc }}" />!-->
|
<!--<meta property="og:description" content="{{ desc }}" />!-->
|
||||||
<meta property="og:image" content="{{ pic }}" />
|
<meta property="og:image" content="{{ pic[0] }}" />
|
||||||
|
|
||||||
<!--!-->
|
<!--!-->
|
||||||
<link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ urlUserLink }}" type="application/json+oembed" title="{{ user }}">
|
<link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ urlUserLink }}" type="application/json+oembed" title="{{ user }}">
|
||||||
|
28
templates/redirect_script.html
Normal file
28
templates/redirect_script.html
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<script>
|
||||||
|
function androidOrIOS() {
|
||||||
|
const userAgent = navigator.userAgent;
|
||||||
|
if(/android/i.test(userAgent)){
|
||||||
|
return 'android';
|
||||||
|
}
|
||||||
|
if(/iPad|iPhone|iPod/i.test(userAgent)){
|
||||||
|
return 'ios';
|
||||||
|
}
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
function redirect() {
|
||||||
|
const os = androidOrIOS();
|
||||||
|
if(os === 'android'){
|
||||||
|
window.location.href = 'twitter://status?status_id=1674915987789950982';
|
||||||
|
window.location.href = 'https://twitter.com/pdxdylan/status/1674915987789950982'
|
||||||
|
}
|
||||||
|
if(os === 'ios'){
|
||||||
|
window.location.href = 'twitter://status?id=1674915987789950982';
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = 'https://twitter.com/pdxdylan/status/1674915987789950982'
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect();
|
||||||
|
</script>
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
<meta name="twitter:card" content="tweet" />
|
<meta name="twitter:card" content="tweet" />
|
||||||
<meta name="twitter:title" content="{{ user }} (@{{ screenName }}) {% if verified %}☑️{% else %}{% endif %}" />
|
<meta name="twitter:title" content="{{ user }} (@{{ screenName }}) {% if verified %}☑️{% else %}{% endif %}" />
|
||||||
<meta name="twitter:image" content="{{ pic }}" />
|
<meta name="twitter:image" content="{{ pic[0] }}" />
|
||||||
<meta name="twitter:creator" content="@{{ user }}" />
|
<meta name="twitter:creator" content="@{{ user }}" />
|
||||||
|
|
||||||
<meta property="og:description" content="{{ desc }}" />
|
<meta property="og:description" content="{{ desc }}" />
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<meta property="og:video:width" content="{{ videoSize['width'] }}" />
|
<meta property="og:video:width" content="{{ videoSize['width'] }}" />
|
||||||
<meta property="og:video:height" content="{{ videoSize['height'] }}" />
|
<meta property="og:video:height" content="{{ videoSize['height'] }}" />
|
||||||
<meta name="twitter:title" content="{{ user }} (@{{ screenName }}) {% if verified %}☑️{% else %}{% endif %}" />
|
<meta name="twitter:title" content="{{ user }} (@{{ screenName }}) {% if verified %}☑️{% else %}{% endif %}" />
|
||||||
<meta property="og:image" content="{{ pic }}" />
|
<meta property="og:image" content="{{ pic[0] }}" />
|
||||||
<meta property="og:description" content="{{ desc }}" />
|
<meta property="og:description" content="{{ desc }}" />
|
||||||
|
|
||||||
<link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ urlUserLink }}&ttype=video&provider={{ appname }}" type="application/json+oembed" title="{{ user }}">
|
<link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ urlUserLink }}&ttype=video&provider={{ appname }}" type="application/json+oembed" title="{{ user }}">
|
||||||
|
36
twitfix.py
36
twitfix.py
@ -19,7 +19,7 @@ import zipfile
|
|||||||
import html
|
import html
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app)
|
CORS(app)
|
||||||
|
user_agent=""
|
||||||
pathregex = re.compile("\\w{1,15}\\/(status|statuses)\\/(\\d{2,20})")
|
pathregex = re.compile("\\w{1,15}\\/(status|statuses)\\/(\\d{2,20})")
|
||||||
generate_embed_user_agents = [
|
generate_embed_user_agents = [
|
||||||
"facebookexternalhit/1.1",
|
"facebookexternalhit/1.1",
|
||||||
@ -58,6 +58,7 @@ def robots():
|
|||||||
|
|
||||||
@app.route('/') # If the useragent is discord, return the embed, if not, redirect to configured repo directly
|
@app.route('/') # If the useragent is discord, return the embed, if not, redirect to configured repo directly
|
||||||
def default():
|
def default():
|
||||||
|
global user_agent
|
||||||
user_agent = request.headers.get('user-agent')
|
user_agent = request.headers.get('user-agent')
|
||||||
if isValidUserAgent(user_agent):
|
if isValidUserAgent(user_agent):
|
||||||
return message("TwitFix is an attempt to fix twitter video embeds in discord! created by Robin Universe :)\n\n💖\n\nClick me to be redirected to the repo!")
|
return message("TwitFix is an attempt to fix twitter video embeds in discord! created by Robin Universe :)\n\n💖\n\nClick me to be redirected to the repo!")
|
||||||
@ -75,7 +76,7 @@ def oembedend():
|
|||||||
|
|
||||||
@app.route('/<path:sub_path>') # Default endpoint used by everything
|
@app.route('/<path:sub_path>') # Default endpoint used by everything
|
||||||
def twitfix(sub_path):
|
def twitfix(sub_path):
|
||||||
|
global user_agent
|
||||||
user_agent = request.headers.get('user-agent')
|
user_agent = request.headers.get('user-agent')
|
||||||
match = pathregex.search(sub_path)
|
match = pathregex.search(sub_path)
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ def twitfix(sub_path):
|
|||||||
if e is not None:
|
if e is not None:
|
||||||
return message(msgs.failedToScan+msgs.failedToScanExtra+e)
|
return message(msgs.failedToScan+msgs.failedToScanExtra+e)
|
||||||
return message(msgs.failedToScan)
|
return message(msgs.failedToScan)
|
||||||
return make_cached_vnf_response(vnf,getTemplate("rawvideo.html",vnf,"","",clean,"","","",""))
|
return make_cached_vnf_response(vnf,getTemplate("rawvideo.html",vnf,"",[],clean,"","","",""))
|
||||||
elif request.url.endswith(".txt") or request.url.endswith("%2Etxt"):
|
elif request.url.endswith(".txt") or request.url.endswith("%2Etxt"):
|
||||||
twitter_url = "https://twitter.com/" + sub_path
|
twitter_url = "https://twitter.com/" + sub_path
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ def twitfix(sub_path):
|
|||||||
if e is not None:
|
if e is not None:
|
||||||
return abort(500,"Failed to scan tweet: "+e)
|
return abort(500,"Failed to scan tweet: "+e)
|
||||||
return abort(500,"Failed to scan tweet")
|
return abort(500,"Failed to scan tweet")
|
||||||
return make_content_type_response(getTemplate("txt.html",vnf,vnf["description"],"",clean,"","","",""),"text/plain")
|
return make_content_type_response(getTemplate("txt.html",vnf,vnf["description"],[],clean,"","","",""),"text/plain")
|
||||||
elif request.url.endswith(".zip") or request.url.endswith("%2Ezip"): # for certain types of archival software (i.e Hydrus)
|
elif request.url.endswith(".zip") or request.url.endswith("%2Ezip"): # for certain types of archival software (i.e Hydrus)
|
||||||
twitter_url = "https://twitter.com/" + sub_path
|
twitter_url = "https://twitter.com/" + sub_path
|
||||||
|
|
||||||
@ -310,6 +311,7 @@ def twitfix(sub_path):
|
|||||||
|
|
||||||
@app.route('/dir/<path:sub_path>') # Try to return a direct link to the MP4 on twitters servers
|
@app.route('/dir/<path:sub_path>') # Try to return a direct link to the MP4 on twitters servers
|
||||||
def dir(sub_path):
|
def dir(sub_path):
|
||||||
|
global user_agent
|
||||||
user_agent = request.headers.get('user-agent')
|
user_agent = request.headers.get('user-agent')
|
||||||
url = sub_path
|
url = sub_path
|
||||||
match = pathregex.search(url)
|
match = pathregex.search(url)
|
||||||
@ -616,7 +618,7 @@ def message(text):
|
|||||||
repo = config['config']['repo'],
|
repo = config['config']['repo'],
|
||||||
url = config['config']['url'] )
|
url = config['config']['url'] )
|
||||||
|
|
||||||
def getTemplate(template,vnf,desc,image,video_link,color,urlDesc,urlUser,urlLink,appNameSuffix="",embedVNF=None):
|
def getTemplate(template,vnf,desc,images,video_link,color,urlDesc,urlUser,urlLink,appNameSuffix="",embedVNF=None):
|
||||||
if (embedVNF is None):
|
if (embedVNF is None):
|
||||||
embedVNF = vnf
|
embedVNF = vnf
|
||||||
if ('width' in embedVNF['size'] and 'height' in embedVNF['size']):
|
if ('width' in embedVNF['size'] and 'height' in embedVNF['size']):
|
||||||
@ -633,7 +635,7 @@ def getTemplate(template,vnf,desc,image,video_link,color,urlDesc,urlUser,urlLink
|
|||||||
pfp = vnf['pfp'],
|
pfp = vnf['pfp'],
|
||||||
vidurl = embedVNF['url'],
|
vidurl = embedVNF['url'],
|
||||||
desc = desc,
|
desc = desc,
|
||||||
pic = image,
|
pic = images,
|
||||||
user = vnf['uploader'],
|
user = vnf['uploader'],
|
||||||
video_link = vnf,
|
video_link = vnf,
|
||||||
color = color,
|
color = color,
|
||||||
@ -705,7 +707,7 @@ def embed(video_link, vnf, image):
|
|||||||
if vnf['nsfw'] == True:
|
if vnf['nsfw'] == True:
|
||||||
color = "#800020" # Red
|
color = "#800020" # Red
|
||||||
|
|
||||||
return make_cached_vnf_response(vnf,getTemplate(template,vnf,desc,image,video_link,color,urlDesc,urlUser,urlLink,appNamePost,embedVNF))
|
return make_cached_vnf_response(vnf,getTemplate(template,vnf,desc,[image],video_link,color,urlDesc,urlUser,urlLink,appNamePost,embedVNF))
|
||||||
|
|
||||||
|
|
||||||
def embedCombined(video_link):
|
def embedCombined(video_link):
|
||||||
@ -745,17 +747,25 @@ def embedCombinedVnf(video_link,vnf):
|
|||||||
if qrt is not None:
|
if qrt is not None:
|
||||||
desc=msgs.formatEmbedDesc(vnf['type'],desc,qrt,pollDisplay,likeDisplay)
|
desc=msgs.formatEmbedDesc(vnf['type'],desc,qrt,pollDisplay,likeDisplay)
|
||||||
|
|
||||||
host = config['config']['url']
|
suffix=""
|
||||||
image = f"{host}/rendercombined.jpg?imgs="
|
if 'Discord' in user_agent:
|
||||||
for i in range(0,int(vnf['images'][4])):
|
images = []
|
||||||
image = image + vnf['images'][i] + ","
|
for i in range(0,int(vnf['images'][4])):
|
||||||
image = image[:-1] # Remove last comma
|
images.append(vnf['images'][i])
|
||||||
|
else:
|
||||||
|
host = config['config']['url']
|
||||||
|
image = f"{host}/rendercombined.jpg?imgs="
|
||||||
|
for i in range(0,int(vnf['images'][4])):
|
||||||
|
image = image + vnf['images'][i] + ","
|
||||||
|
image = image[:-1] # Remove last comma
|
||||||
|
images=[image]
|
||||||
|
suffix=" - View original tweet for full quality"
|
||||||
|
|
||||||
color = "#7FFFD4" # Green
|
color = "#7FFFD4" # Green
|
||||||
|
|
||||||
if vnf['nsfw'] == True:
|
if vnf['nsfw'] == True:
|
||||||
color = "#800020" # Red
|
color = "#800020" # Red
|
||||||
return make_cached_vnf_response(vnf,getTemplate('image.html',vnf,desc,image,video_link,color,urlDesc,urlUser,urlLink,appNameSuffix=" - View original tweet for full quality"))
|
return make_cached_vnf_response(vnf,getTemplate('image.html',vnf,desc,images,video_link,color,urlDesc,urlUser,urlLink,appNameSuffix=suffix))
|
||||||
|
|
||||||
|
|
||||||
def getPollObject(card):
|
def getPollObject(card):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user