2021-07-04 03:46:02 +02:00
|
|
|
from flask import Flask, render_template
|
2021-07-04 01:52:30 +02:00
|
|
|
import youtube_dl
|
2021-07-04 03:41:47 +02:00
|
|
|
import re
|
2021-07-04 01:52:30 +02:00
|
|
|
|
|
|
|
ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s.%(ext)s'})
|
|
|
|
app = Flask(__name__)
|
2021-07-04 03:41:47 +02:00
|
|
|
pathregex = re.compile("\\w{1,15}\\/status\\/\\d{19}")
|
2021-07-04 01:52:30 +02:00
|
|
|
|
2021-07-04 02:08:19 +02:00
|
|
|
@app.route('/<path:subpath>')
|
2021-07-04 01:52:30 +02:00
|
|
|
def twitfix(subpath):
|
2021-07-04 03:41:47 +02:00
|
|
|
|
|
|
|
match = pathregex.search(subpath)
|
|
|
|
if match is not None:
|
|
|
|
twitter_url = subpath
|
|
|
|
|
|
|
|
if match.start() == 0:
|
|
|
|
twitter_url = "https://twitter.com/" + subpath
|
|
|
|
|
2021-07-04 01:52:30 +02:00
|
|
|
with ydl:
|
2021-07-04 03:41:47 +02:00
|
|
|
try:
|
|
|
|
result = ydl.extract_info(twitter_url, download=False)
|
|
|
|
except Exception: # Just to keep from 500s that are messy
|
|
|
|
return "Bad twitter link, try again"
|
2021-07-04 01:52:30 +02:00
|
|
|
|
2021-07-04 03:41:47 +02:00
|
|
|
return render_template('index.html', vidurl=result['url'], tweet=result['description'], pic=result['thumbnail'], user=result['uploader'], tweeturl=twitter_url)
|
2021-07-04 01:52:30 +02:00
|
|
|
else:
|
|
|
|
return "Please use a twitter link"
|
|
|
|
|
|
|
|
@app.route('/info/<path:subpath>')
|
|
|
|
def info(subpath):
|
|
|
|
with ydl:
|
|
|
|
result = ydl.extract_info(subpath, download=False)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run(host='0.0.0.0', port=80)
|