feat: ✨ Song can be added without quitting app
This commit is contained in:
parent
1dceebdbef
commit
7d507e7c46
19
main.py
19
main.py
@ -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__':
|
||||
|
0
templates/add.html
Normal file
0
templates/add.html
Normal file
@ -35,7 +35,10 @@
|
||||
<h5 class="card-title"> {{ track[0] }} </h5>
|
||||
<p class="card-text">{{ track[1] }} - {{ track[2] }}</p>
|
||||
<audio controls><source src="{{ track[3] }}"></audio>
|
||||
<a href="https://n8n.louisgallet.fr/webhook/61f08b8c-5bca-4091-a934-da66d9ae09e7/61f08b8c-5bca-4091-a934-da66d9ae09e7/{{ track[5] }}" class="btn btn-primary">Add to the playlist</a>
|
||||
<form method="GET" action="/add/{{track[5]}}">
|
||||
<input type="hidden" name="track" value="{{ track[5] }}">
|
||||
<input type="submit" value="Add to the playlist" class="btn btn-primary">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user