From 94ce8ba17e56051f788f2f6dfabad9aa4f35ef48 Mon Sep 17 00:00:00 2001 From: adryd Date: Mon, 2 Aug 2021 21:52:13 -0400 Subject: [PATCH] Addresses #23 --- __pycache__/twitfix.cpython-39.pyc | Bin 0 -> 8598 bytes templates/index.html | 2 +- twitfix.py | 25 ++++++++++++------------- 3 files changed, 13 insertions(+), 14 deletions(-) create mode 100644 __pycache__/twitfix.cpython-39.pyc diff --git a/__pycache__/twitfix.cpython-39.pyc b/__pycache__/twitfix.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1466598f88fe87717e373b1ce9dd0f5e521b9274 GIT binary patch literal 8598 zcma)BOLH4ncJ3$8Xo3$>6eUu!+_EK8(1Rdp$qz|>NS5WXM}jnZSmU-PFo=6efCSL+ z?WRQbfU}`1m5s`-sZ>^~8Y+uaIg2b)Q&&ZQs_Z&1mKP9N+VPp6`zD@V(#{`0n~H-v|5wz8C!>-v|96smtLF-5-$yoBM?M zRQE?0HDUdw?(dhyrLoNe!hWiU|1QUcEpi*i_t*S`A}<_K5Uv;yMKLIbp5(=_7!mu# zsM!C+5@Syc|B!T-CgdS`P#h5B;^1RT*Y0DTmS$-irml5HX0`C2W;C7uzCtMv`IDVV zdJEQaSh|}>g!fqY-^k`WHlg`%$~Q%R*}$BCXlnlP?Op$%hkw7d?^D?K8{&zqgu2QJ}5sBzn(iYH?v-{;@dZZxY=se%IBwNypuO-^=2mu!p24K^G+mN z9thseJKit7*_r9tnTwu!c;W5$re{jtXR^K=l;>t^oDm=B`z+%%>;-H4)Yc%fVtX+y2soksss{MudFl8dU=z7j;<$yRe& zdUqc+qev+^1`5! zMepTTBra9b9!YWMRLNlWls1-(B$pm_Vq(ZM3*vb9N5juGA%~sFFNA@LXwjiMgeEmi z;%cY~+>%^lZC*76Kd5nPJxIkE6$en1^u(&IL=81alst;(e0X8XRYT0HArP;XbU%+Z zbRgW%^>Q7gt)GsXiR%+w;T(!cThccTp+D8vwVoE44>ffpvV^gr-_asF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z literal 0 HcmV?d00001 diff --git a/templates/index.html b/templates/index.html index c759f3f..607cbc3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -28,7 +28,7 @@ - + {% endblock %} diff --git a/twitfix.py b/twitfix.py index d94d364..0e1e625 100644 --- a/twitfix.py +++ b/twitfix.py @@ -6,11 +6,11 @@ import pymongo import json import re import os +import urllib.parse app = Flask(__name__) pathregex = re.compile("\\w{1,15}\\/status\\/\\d{2,20}") -discord_user_agents = ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0", "Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)"] -telegram_user_agents = ["TelegramBot (like TwitterBot)"] +generate_embed_user_agents = ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0", "Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)", "TelegramBot (like TwitterBot)", "test"] # Read config from config.json. If it does not exist, create new. if not os.path.exists("config.json"): @@ -48,7 +48,7 @@ elif link_cache_system == "db": @app.route('/') # If the useragent is discord, return the embed, if not, redirect to configured repo directly def default(): user_agent = request.headers.get('user-agent') - if user_agent in discord_user_agents: + if user_agent in generate_embed_user_agents: 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!") else: return redirect(config['config']['repo'], 301) @@ -70,12 +70,10 @@ def twitfix(sub_path): if match.start() == 0: twitter_url = "https://twitter.com/" + sub_path - if user_agent in discord_user_agents: - res = embed_video(twitter_url) - return res - if user_agent in telegram_user_agents: + if user_agent in generate_embed_user_agents: res = embed_video(twitter_url) return res + else: print("Redirect to " + twitter_url) return redirect(twitter_url, 301) @@ -105,12 +103,10 @@ def dir(sub_path): if match.start() == 0: twitter_url = "https://twitter.com/" + url - if user_agent in discord_user_agents: - res = message('Click the link to be redirected to the Direct MP4 Link') - return res - if user_agent in telegram_user_agents: + if user_agent in generate_embed_user_agents: res = message('Click the link to be redirected to the Direct MP4 Link') return res + else: print("Redirect to direct MP4 URL") return direct_video(twitter_url) @@ -261,8 +257,11 @@ def message(text): def embed(video_link, vnf): print(vnf['url']) if vnf['url'].startswith('https://t.co') is not True: - desc = re.sub(r' http.*t\.co\S+', '', vnf['description'].replace("#","ļ¼ƒ")) # some funky string manipulation to get rid of the t.co vid link and replace # with a similar looking character, the normal # breaks when getting fed into the oembed endpoint - return render_template('index.html', vidurl=vnf['url'], desc=desc, pic=vnf['thumbnail'], user=vnf['uploader'], video_link=video_link, color=config['config']['color'], appname=config['config']['appname'], repo=config['config']['repo'], url=config['config']['url']) + desc = re.sub(r' http.*t\.co\S+', '', vnf['description']) + urlUser = urllib.parse.quote(vnf['uploader']) + urlDesc = urllib.parse.quote(desc) + urlLink = urllib.parse.quote(video_link) + return render_template('index.html', vidurl=vnf['url'], desc=desc, pic=vnf['thumbnail'], user=vnf['uploader'], video_link=video_link, color=config['config']['color'], appname=config['config']['appname'], repo=config['config']['repo'], url=config['config']['url'], urlDesc=urlDesc, urlUser=urlUser, urlLink=urlLink) else: return redirect(vnf['url'], 301)