From 0fdcda924e1479188fa668fa3d3610a2d581f519 Mon Sep 17 00:00:00 2001 From: Robin Universe Date: Sat, 3 Jul 2021 18:52:30 -0500 Subject: [PATCH] Too Init To Quit --- LICENSE.txt | 14 ++++++++++++++ __pycache__/app.cpython-38.pyc | Bin 0 -> 1065 bytes readme.md | 31 +++++++++++++++++++++++++++++++ static/css/main.css | 4 ++++ templates/base.html | 9 +++++++++ templates/index.html | 20 ++++++++++++++++++++ twitfix.py | 30 ++++++++++++++++++++++++++++++ 7 files changed, 108 insertions(+) create mode 100644 LICENSE.txt create mode 100644 __pycache__/app.cpython-38.pyc create mode 100644 readme.md create mode 100644 static/css/main.css create mode 100644 templates/base.html create mode 100644 templates/index.html create mode 100644 twitfix.py diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..ee7d6a5 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + diff --git a/__pycache__/app.cpython-38.pyc b/__pycache__/app.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f4e7459bba4c85133af6916103c3a4c85a4f9c0b GIT binary patch literal 1065 zcmZuv!A{#i5Z$$7dt(v;2({NM7nBpu0%4yj;yMR8q(nQ4|$2FFJ6-pW4v< z-s_!%_hP#{=x%lUJL34=-q2=ST#tIZK~xe>fpAB?$7VH0l3Ji1|DMU zA*OCQgO5l90$|sKH=&Na!m2jNARDwPUz(Ui$7U+d<@D|srrAZ1rKM8wiIT`906B_F zRSfAuW%i5>Bt6`@?J3aDG6-T+g1HO?<#f0BtRoYV?Dc1_s}EBAph| zZaF+p(yi#oWMdO+ouuRFXj+_RY1Auqj-o~JWYU>TD<*`I6C=d3&1Vx6dfBuTI)6Qf z?PVL5###zdg+k~IN@dRtAuh^TJ$M|{-|uCr)F}`4(n5}N0bs_F*FiCU~EM*QVXVOu>egSch1l-x)FPDaVKH z74D7fI2)UE{-hl=zA{4v&TBlMW8>KXOWw55R4%rI`zX&S8Jjixi+7NLR5MoGGg(>4 jd0y9)>3{2F8}q(w+6l^Sjq9{Q8xEr(WzHJIugmBkbbR=U literal 0 HcmV?d00001 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..d331838 --- /dev/null +++ b/readme.md @@ -0,0 +1,31 @@ +# TwitFix + +very basic flask server that fixes twitter embeds in discord by using youtube-dl to grab the direct link to the MP4 file and embeds the link to it in a custom page + + + +This does work! but I'm new to flask, so it can probably be improved a great deal. + + + +## How to use (discord side) + +just put the url to the server, then /twitfix/, and directly after, the full URL to the tweet you want to embed + + + +## How to run (server side) + +this is in a virtual environment, so first you should enter the virtual environment using `source env/bin/activate` and then you can start the server with `python3 twitfix.py` + + +By default I have the port set to 80, just cause that's what was convenient for me, but it can easily be changed, either using an environment variable, or changing the bottom line of the script itself + + + +this script uses the youtube-dl python module, along with flask + + + +This project is licensed under th **Do What The Fuck You Want Public License** + diff --git a/static/css/main.css b/static/css/main.css new file mode 100644 index 0000000..e9b423d --- /dev/null +++ b/static/css/main.css @@ -0,0 +1,4 @@ +body { + margin-right: 40%; + background: color 0; +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..31d6d63 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,9 @@ + + + + {% block head %}{% endblock %} + + + {% block body %}{% endblock %} + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..e1804d6 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} + +{% block head %} + + + + + + + + + + +{% endblock %} + +{% block body %} + +{% endblock %} \ No newline at end of file diff --git a/twitfix.py b/twitfix.py new file mode 100644 index 0000000..cf9347d --- /dev/null +++ b/twitfix.py @@ -0,0 +1,30 @@ +from flask import Flask, render_template, url_for, request, redirect +from datetime import datetime +import youtube_dl +import requests +import psutil +import os + +ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s.%(ext)s'}) +app = Flask(__name__) + +@app.route('/twitfix/') +def twitfix(subpath): + if subpath.startswith('https://twitter.com'): + with ydl: + result = ydl.extract_info(subpath, download=False) + + return render_template('index.html', vidurl=result['url'], tweet=result['description'], pic=result['thumbnail'], user=result['uploader'], tweeturl=subpath) + else: + return "Please use a twitter link" + +@app.route('/info/') +def info(subpath): + with ydl: + result = ydl.extract_info(subpath, download=False) + + return result + +if __name__ == "__main__": + app.run(debug=False) + app.run(host='0.0.0.0', port=80)