Just redirect to Twitter when it's not Discord calling
Signed-off-by: adryd <me@adryd.com>
This commit is contained in:
parent
f90249fc05
commit
4053f6373d
1 changed files with 14 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
from flask import Flask, render_template, request
|
from flask import Flask, render_template, request, redirect
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
import textwrap
|
import textwrap
|
||||||
import twitter
|
import twitter
|
||||||
|
@ -9,6 +9,7 @@ import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
pathregex = re.compile("\\w{1,15}\\/status\\/\\d{19}")
|
pathregex = re.compile("\\w{1,15}\\/status\\/\\d{19}")
|
||||||
|
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)"]
|
||||||
|
|
||||||
if not os.path.exists("config.json"):
|
if not os.path.exists("config.json"):
|
||||||
with open("config.json", "w") as outfile:
|
with open("config.json", "w") as outfile:
|
||||||
|
@ -52,6 +53,8 @@ def oembedend():
|
||||||
|
|
||||||
@app.route('/<path:subpath>')
|
@app.route('/<path:subpath>')
|
||||||
def twitfix(subpath):
|
def twitfix(subpath):
|
||||||
|
user_agent = request.headers.get('user-agent')
|
||||||
|
if user_agent in discord_user_agents:
|
||||||
|
|
||||||
match = pathregex.search(subpath)
|
match = pathregex.search(subpath)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
|
@ -64,6 +67,8 @@ def twitfix(subpath):
|
||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
return render_template('default.html', message="This doesn't seem to be a twitter link, try /other/ to see if other kinds of video link works? (experimental)")
|
return render_template('default.html', message="This doesn't seem to be a twitter link, try /other/ to see if other kinds of video link works? (experimental)")
|
||||||
|
else:
|
||||||
|
return redirect("https://twitter.com/" + subpath, 301)
|
||||||
|
|
||||||
@app.route('/other/<path:subpath>') # Show all info that Youtube-DL can get about a video as a json
|
@app.route('/other/<path:subpath>') # Show all info that Youtube-DL can get about a video as a json
|
||||||
def other(subpath):
|
def other(subpath):
|
||||||
|
|
Loading…
Reference in a new issue