asf
This commit is contained in:
parent
61dcd99db2
commit
f49027805e
3 changed files with 47 additions and 21 deletions
Binary file not shown.
23
app.py
23
app.py
|
@ -13,7 +13,7 @@ app = Flask(__name__)
|
||||||
# Spotify API credentials from environment variables
|
# Spotify API credentials from environment variables
|
||||||
CLIENT_ID = os.getenv("CLIENT_ID")
|
CLIENT_ID = os.getenv("CLIENT_ID")
|
||||||
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
|
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
|
||||||
REDIRECT_URI = "http://localhost:80/callback"
|
REDIRECT_URI = "http://0.0.0.0/callback"
|
||||||
SCOPE = "user-modify-playback-state user-read-playback-state"
|
SCOPE = "user-modify-playback-state user-read-playback-state"
|
||||||
|
|
||||||
# Spotipy client
|
# Spotipy client
|
||||||
|
@ -52,7 +52,6 @@ def add_song():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
# Route to serve the queue table for iframe
|
|
||||||
@app.route("/queue_table")
|
@app.route("/queue_table")
|
||||||
def queue_table():
|
def queue_table():
|
||||||
queue_data = sp.queue()
|
queue_data = sp.queue()
|
||||||
|
@ -62,12 +61,28 @@ def queue_table():
|
||||||
for track in queue_data["queue"]:
|
for track in queue_data["queue"]:
|
||||||
track_name = track["name"]
|
track_name = track["name"]
|
||||||
artist_name = track["artists"][0]["name"]
|
artist_name = track["artists"][0]["name"]
|
||||||
queue.append({"track": track_name, "artist": artist_name})
|
artist_uri = track["artists"][0]["uri"] # Get the Spotify URI for the artist
|
||||||
|
artist_link = f"https://open.spotify.com/artist/{artist_uri.split(':')[-1]}" # Construct the Spotify artist link
|
||||||
|
track_uri = track["uri"] # Get the Spotify URI for the track
|
||||||
|
track_link = f"https://open.spotify.com/track/{track_uri.split(':')[-1]}" # Construct the Spotify track link
|
||||||
|
queue.append({
|
||||||
|
"track": track_name,
|
||||||
|
"artist": artist_name,
|
||||||
|
"track_link": track_link,
|
||||||
|
"artist_link": artist_link
|
||||||
|
})
|
||||||
current = None
|
current = None
|
||||||
if queue_data["currently_playing"]:
|
if queue_data["currently_playing"]:
|
||||||
current = {"track": queue_data["currently_playing"]["name"], "artist": queue_data["currently_playing"]["artists"][0]["name"]}
|
current_track = queue_data["currently_playing"]
|
||||||
|
current = {
|
||||||
|
"track": current_track["name"],
|
||||||
|
"artist": current_track["artists"][0]["name"],
|
||||||
|
"track_link": f"https://open.spotify.com/track/{current_track['uri'].split(':')[-1]}",
|
||||||
|
"artist_link": f"https://open.spotify.com/artist/{current_track['artists'][0]['uri'].split(':')[-1]}"
|
||||||
|
}
|
||||||
return render_template("queue_table.html", queue=queue, length=len(queue), now_playing=current)
|
return render_template("queue_table.html", queue=queue, length=len(queue), now_playing=current)
|
||||||
|
|
||||||
|
|
||||||
# Run the Flask app
|
# Run the Flask app
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(port=80, host="0.0.0.0", debug=True)
|
app.run(port=80, host="0.0.0.0", debug=True)
|
||||||
|
|
|
@ -11,22 +11,33 @@
|
||||||
<title>table</title>
|
<title>table</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<center> <main class="container">
|
<center>
|
||||||
<table class="striped" style="table-layout: fixed; overflow: hidden;">
|
<main class="container">
|
||||||
<thead style=" text-align: center;">
|
<table class="striped" style="table-layout: fixed; overflow: hidden; text-align: center;">
|
||||||
<tr style=" text-align: center;">
|
<thead>
|
||||||
<th scope="row" style=" text-align: center;">Track</th>
|
<tr>
|
||||||
<th style=" text-align: center;">Artist</th>
|
<th scope="col" style="table-layout: fixed; overflow: hidden; text-align: center;">Track</th>
|
||||||
</tr>
|
<th scope="col"style="table-layout: fixed; overflow: hidden; text-align: center;">Artist</th>
|
||||||
</thead style=" text-align: center;">
|
</tr>
|
||||||
<tbody style=" text-align: center;">
|
</thead>
|
||||||
{% for i in range(length) %}
|
<tbody>
|
||||||
<tr style=" text-align: center;">
|
{% for i in range(length) %}
|
||||||
<td style=" text-align: center;">{{ queue[i].track }}</td>
|
<tr>
|
||||||
<td style=" text-align: center;">{{ queue[i].artist }}</td>
|
<td style="table-layout: fixed; overflow: hidden; text-align: center;">
|
||||||
</tr>
|
<a href="{{ queue[i].track_link }}" target="_blank" rel="noopener noreferrer">
|
||||||
{% endfor %}
|
{{ queue[i].track }}
|
||||||
</tbody>
|
</a>
|
||||||
</table></center></main>
|
</td >
|
||||||
|
<td style="table-layout: fixed; overflow: hidden; text-align: center;">
|
||||||
|
<a href="{{ queue[i].artist_link }}" target="_blank" rel="noopener noreferrer">
|
||||||
|
{{ queue[i].artist }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</main>
|
||||||
|
</center>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue