From f0da90a81b3f95cf129335b7a94ed5e9766943cb Mon Sep 17 00:00:00 2001 From: kleph Date: Mon, 12 Apr 2021 14:15:08 +0200 Subject: [PATCH] Initial import of pytubedl - web part --- pytubedl.py | 32 +++++++++++++++++++++++++++++ templates/index.html | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 pytubedl.py create mode 100644 templates/index.html diff --git a/pytubedl.py b/pytubedl.py new file mode 100644 index 0000000..7feabaf --- /dev/null +++ b/pytubedl.py @@ -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() diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..1f7699b --- /dev/null +++ b/templates/index.html @@ -0,0 +1,49 @@ + + + + + + + PyTubeDL + + +
+ {{ form.csrf }} + {{ form.url.label }} {{ form.url }} + +
+{% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} +{% endwith %} + + \ No newline at end of file