Initial import of pytubedl - web part

This commit is contained in:
kleph 2021-04-12 14:15:08 +02:00
commit f0da90a81b
2 changed files with 81 additions and 0 deletions

32
pytubedl.py Normal file
View file

@ -0,0 +1,32 @@
from flask import Flask, render_template, request, flash
from wtforms import Form, StringField
from wtforms.validators import DataRequired, URL
import secrets
DEBUG = False
app = Flask(__name__)
app.config['SECRET_KEY'] = secrets.token_urlsafe(20)
class MyForm(Form):
url = StringField('url', validators=[DataRequired(), URL(message='Must be a valid URL')])
@app.route('/', methods=['GET', 'POST'])
def hello():
# TODO: error handling?
form = MyForm(request.form)
# print(form.errors)
if request.method == 'POST':
url = request.form['url']
print("URL: " + url)
if form.validate():
flash('OK. Download in progress')
else:
flash('Error: bad URL')
return render_template('index.html', form=form)
if __name__ == "__main__":
app.run()

49
templates/index.html Normal file
View file

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en" data-theme='dark'>
<style>
:root {
--background-color: #fff;
--text-color: #121416d8;
--link-color: #543fd7;
}
html[data-theme='light'] {
--background-color: #fff;
--text-color: #121416d8;
--link-color: #543fd7;
}
html[data-theme='dark'] {
--background-color: #212a2e;
--text-color: #F7F8F8;
--link-color: #828fff;
}
body {
background: var(--background-color);
color: var(--text-color);
}
</style>
<head>
<meta charset="UTF-8">
<title>PyTubeDL</title>
</head>
<body>
<form method="POST" action="/">
{{ form.csrf }}
{{ form.url.label }} {{ form.url }}
<input type="submit" value="Go">
</form>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class=flashes>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
</body>
</html>