Added working WTForm to get URL at /downloader
This commit is contained in:
5
app.py
5
app.py
@@ -1,8 +1,10 @@
|
||||
from flask import Flask, current_app, g
|
||||
from flask_bootstrap import Bootstrap
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
|
||||
from frontend import frontend, get_db
|
||||
from nav import nav
|
||||
from os import urandom
|
||||
|
||||
|
||||
def init_db():
|
||||
@@ -17,6 +19,9 @@ def create_app():
|
||||
Bootstrap(app)
|
||||
|
||||
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
|
||||
app.config['SECRET_KEY'] = urandom(32)
|
||||
CSRFProtect(app)
|
||||
|
||||
app.register_blueprint(frontend)
|
||||
app.app_context().push()
|
||||
nav.init_app(app)
|
||||
|
||||
7
forms/download.py
Normal file
7
forms/download.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import URLField
|
||||
from wtforms.validators import URL, DataRequired
|
||||
|
||||
|
||||
class DownloadForm(FlaskForm):
|
||||
url = URLField('url', validators=[DataRequired(), URL()])
|
||||
22
frontend.py
22
frontend.py
@@ -3,7 +3,9 @@ from flask_nav3.elements import Navbar, View
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
import forms.download
|
||||
from nav import nav
|
||||
from forms.download import DownloadForm
|
||||
|
||||
frontend = Blueprint('frontend', __name__)
|
||||
|
||||
@@ -23,16 +25,22 @@ def index():
|
||||
|
||||
@frontend.route('/downloader', methods=['GET', 'POST'])
|
||||
def downloader():
|
||||
if request.method == 'GET':
|
||||
return render_template('downloader.html')
|
||||
else:
|
||||
return 'Hello there!'
|
||||
form = DownloadForm()
|
||||
if form.validate_on_submit():
|
||||
# put here the interaction with youtube-dl
|
||||
# or forward to site that shows details of yt link
|
||||
url = form.url.data
|
||||
return f"Hello There {url}"
|
||||
|
||||
return render_template('downloader.html', form=form)
|
||||
|
||||
|
||||
@frontend.route('/download/<path:file>', methods=['GET'])
|
||||
def download(file):
|
||||
dir = os.path.join(current_app.root_path, 'downloads/')
|
||||
return send_from_directory(dir, )
|
||||
return send_from_directory(
|
||||
os.path.join(current_app.root_path, 'downloads/'),
|
||||
file
|
||||
)
|
||||
|
||||
|
||||
@frontend.route('/update', methods=['GET', 'POST'])
|
||||
@@ -51,7 +59,7 @@ def library():
|
||||
def collection():
|
||||
query = query_db("""
|
||||
SELECT video.name FROM video
|
||||
INNER JOIN collection ON collection.path = video.path
|
||||
INNER JOIN collection ON collection.path = video.filename
|
||||
INNER JOIN playlist ON playlist.ROWID = collection.playlist
|
||||
WHERE video.name IS ?;
|
||||
""", ("",))
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
{%- extends "base.html" %}
|
||||
|
||||
{% import "bootstrap/utils.html" as utils %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
{%- with messages = get_flashed_messages(with_categories=True) %}
|
||||
{%- if messages %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{{utils.flashed_messages(messages)}}
|
||||
</div>
|
||||
</div>
|
||||
{%- endif %}
|
||||
{%- endwith %}
|
||||
<form method="POST">
|
||||
{{ form.csrf_token }}
|
||||
<label for="url">Video, Channel or Playlist</label> <br>
|
||||
<input id="url" name="url" required type="url" placeholder="YouTube Link">
|
||||
<input type="submit" value="Go">
|
||||
</form>
|
||||
{% if form.errors %}
|
||||
{{ form.errors['url'][0][:-1] + ', try again.' }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- endblock %}
|
||||
Reference in New Issue
Block a user