From ac2893b991b0939436f0911abb65437e2b66a9b4 Mon Sep 17 00:00:00 2001 From: EduardSkibidiEdger Date: Sun, 12 Jan 2025 16:42:08 +0200 Subject: [PATCH] asd --- .cache | 1 + app.py | 66 ++++++++++++++++++++++ templates/index.html | 113 +++++++++++++++++++++++++++++++++++++ templates/queue_table.html | 63 +++++++++++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 .cache create mode 100644 app.py create mode 100644 templates/index.html create mode 100644 templates/queue_table.html diff --git a/.cache b/.cache new file mode 100644 index 0000000..61e9fcc --- /dev/null +++ b/.cache @@ -0,0 +1 @@ +{"access_token": "BQChu2C4bda7mJQi_xq_9-DRf3Vtq6hVwk88K3h1QXacIN8ppdFME-RZfy1wxJekQ__UVET_o9ZlWmD3nfqh1Otlbaenr0OwYGQlJDHSZYPBINUT0RbjkkCy5-2rNuqXEimVZpPf3ud9dYuHq4-hxJxrd1OdHi7fGhncF53qs4pulx1iPDVr5hDeJOO6vJh4A6X1NagW3nW8W1wxvesvlxaXeGE", "token_type": "Bearer", "expires_in": 3600, "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1736693329, "refresh_token": "AQDjS3e8vYiwJmfaksX3Bb-aS01v9UN0houDiFWvMMeJiCSv2fzNO4Gy81LAktHOgychbjD0e_ZC7m_HLJufAMQx3EeXn9HOz8Wo08MHfUaXHNaajKK5e7SIgev9H_2mU7g"} \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..4bcfd6a --- /dev/null +++ b/app.py @@ -0,0 +1,66 @@ +from flask import Flask, render_template, request, redirect, url_for, jsonify +from spotipy import Spotify +from spotipy.oauth2 import SpotifyOAuth + +# Flask app +app = Flask(__name__) + +# Spotify API credentials +CLIENT_ID = "d599e0f7a26d419eb6ae618361e1538c" +CLIENT_SECRET = "af42c3dcdc90448087f8bc597ad551c6" +REDIRECT_URI = "https://localhost:8888/callback" +SCOPE = "user-modify-playback-state user-read-playback-state" + +# Spotipy client +sp = Spotify(auth_manager=SpotifyOAuth( + client_id=CLIENT_ID, + client_secret=CLIENT_SECRET, + redirect_uri=REDIRECT_URI, + scope=SCOPE +)) + +# Home route +@app.route("/") +def home(): + return render_template("index.html") + +@app.route("/add", methods=["GET"]) +def add_song(): + # Get the song name from the query parameters + song_name = request.args.get("song_name") + if not song_name: + return jsonify({"error": "No song name provided."}), 400 + + try: + # Search and add the song to the Spotify queue + search_results = sp.search(q=song_name, type="track", limit=1) + if search_results["tracks"]["items"]: + track_uri = search_results["tracks"]["items"][0]["uri"] + print(search_results["tracks"]["items"][0]) + sp.add_to_queue(track_uri) + name = search_results["tracks"]["items"][0]["name"] + return jsonify({"message": f"'{name}' has been added to the queue."}), 200 + else: + return jsonify({"error": "No matching track found."}), 404 + except Exception as e: + return jsonify({"error": str(e)}), 500 + +# Route to serve the queue table for iframe +@app.route("/queue_table") +def queue_table(): + queue_data = sp.queue() + print(queue_data) + queue = [] + if "queue" in queue_data and queue_data["queue"]: + for track in queue_data["queue"]: + track_name = track["name"] + artist_name = track["artists"][0]["name"] + queue.append({"track": track_name, "artist": artist_name}) + current = None + if queue_data["currently_playing"]: + current = {"track":queue_data["currently_playing"]["name"], "artist":queue_data["currently_playing"]["artists"][0]["name"]} + return render_template("queue_table.html", queue=queue, length=len(queue), now_playing=current) + +# Run the Flask app +if __name__ == "__main__": + app.run(port=80, host="0.0.0.0", debug=True) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..fed1883 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,113 @@ + + + + + + Spotify Queue Manager + + + +

Queue

+
+ + +
+
+ + + + + diff --git a/templates/queue_table.html b/templates/queue_table.html new file mode 100644 index 0000000..fd4e40b --- /dev/null +++ b/templates/queue_table.html @@ -0,0 +1,63 @@ + + + + + + + + +
+ + + + + + + + + + {% for i in range(length) %} + + + + + + {% endfor %} + +
#TrackArtist
{{ i+1 }}{{ queue[i].track }}{{ queue[i].artist }}
+ +