yt2podcast/rest_server.py
2022-04-19 00:09:40 +01:00

59 lines
1.4 KiB
Python

import os
import flask
from flask import render_template
from flask import request
from flask import url_for
from flask_cors import CORS
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import check_password_hash
# import main
# from werkzeug.utils import redirect
import config_parser
from yt2podcast.ytdownloader import call_youtubedl
app = flask.Flask(__name__)
auth = HTTPBasicAuth()
app.config["DEBUG"] = True
CORS(app)
URL_BASE_PATH = "/"
# URL_BASE_PATH = "/tagebuch"
@auth.verify_password
def verify_password(username, password):
if username == config_parser.credentials['username'] and \
check_password_hash(config_parser.credentials['hashedPassword'], password):
return username
@app.route(URL_BASE_PATH + 'home', methods=['GET'])
# @auth.login_required
def api_show_form():
return render_template("index.html")
@app.route(URL_BASE_PATH, methods=['POST', 'GET'])
@auth.login_required
def handle_yt_url():
if request.method == "POST":
user_input = request.form['ytlink']
# return redirect(url_for("return_result", ytlink=user_input))
print(user_input)
call_youtubedl(user_input)
return render_template("yt.html")
else:
return render_template("yt.html")
if __name__ == '__main__':
flask_options = dict(
host='0.0.0.0',
debug=True,
port=4001,
threaded=True,
)
app.run(**flask_options)