feat: Song can be added without quitting app

This commit is contained in:
2024-06-29 22:59:25 +02:00
parent 1dceebdbef
commit 7d507e7c46
3 changed files with 22 additions and 2 deletions

19
main.py
View File

@ -1,3 +1,6 @@
import requests
import os
from dotenv import load_dotenv
from flask import Flask, request, render_template
from flask_bootstrap import Bootstrap5
@ -8,7 +11,7 @@ app = Flask(__name__)
bootstrap = Bootstrap5(app)
@app.route('/', methods=['GET', 'POST'])
def form_example():
def main_app():
# handle the POST request
if request.method == 'POST':
search = request.form.get('search')
@ -18,6 +21,20 @@ def form_example():
# otherwise handle the GET request
return render_template("index.html")
@app.route('/add/<string:trackid>', methods=['GET'])
def add_to_playlist(trackid):
if not os.getenv("n8n_webhook"):
return 'n8n_webhook not set'
if not trackid:
return 'No trackid provided'
try:
data = requests.get(os.getenv("n8n_webhook") + "/" + trackid)
if data.json()['message'] == 'Workflow was started':
return 'Track added to playlist'
else:
return 'Invalid response from server: {}'.format(data.text)
except requests.exceptions.RequestException as e:
return 'Request failed: {}'.format(e)
if __name__ == '__main__':