Too Init To Quit

This commit is contained in:
Robin Universe 2021-07-03 18:52:30 -05:00
commit 0fdcda924e
7 changed files with 108 additions and 0 deletions

14
LICENSE.txt Normal file
View file

@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
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.

Binary file not shown.

31
readme.md Normal file
View file

@ -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**

4
static/css/main.css Normal file
View file

@ -0,0 +1,4 @@
body {
margin-right: 40%;
background: color 0;
}

9
templates/base.html Normal file
View file

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% block head %}{% endblock %}
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>

20
templates/index.html Normal file
View file

@ -0,0 +1,20 @@
{% extends 'base.html' %}
{% block head %}
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
<meta name="twitter:card" content="player" />
<meta name="twitter:title" content="{{ user }}" />
<meta name="twitter:image" content="{{ pic }}" />
<meta name="twitter:player" content="{{ vidurl }}" />
<meta name="twitter:player:width" content="720" />
<meta name="twitter:player:height" content="480" />
<meta name="twitter:player:stream" content="{{ vidurl }}" />
<meta name="twitter:player:stream:content_type" content="video/mp4" />
<meta http-equiv = "refresh" content = "0; url = {{ tweeturl }}" />
{% endblock %}
{% block body %}
<video width="100%" controls>
<source src="{{ vidurl }}" type="video/mp4">
</video>
{% endblock %}

30
twitfix.py Normal file
View file

@ -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/<path:subpath>')
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/<path:subpath>')
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)