commit f0da90a81b3f95cf129335b7a94ed5e9766943cb Author: kleph Date: Mon Apr 12 14:15:08 2021 +0200 Initial import of pytubedl - web part 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