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
|
||||
CLIENT_ID = os.getenv("CLIENT_ID")
|
||||
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"
|
||||
|
||||
# Spotipy client
|
||||
|
@ -52,7 +52,6 @@ def add_song():
|
|||
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()
|
||||
|
@ -62,12 +61,28 @@ def queue_table():
|
|||
for track in queue_data["queue"]:
|
||||
track_name = track["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
|
||||
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)
|
||||
|
||||
|
||||
# Run the Flask app
|
||||
if __name__ == "__main__":
|
||||
app.run(port=80, host="0.0.0.0", debug=True)
|
||||
|
|
|
@ -11,22 +11,33 @@
|
|||
<title>table</title>
|
||||
</head>
|
||||
<body>
|
||||
<center> <main class="container">
|
||||
<table class="striped" style="table-layout: fixed; overflow: hidden;">
|
||||
<thead style=" text-align: center;">
|
||||
<tr style=" text-align: center;">
|
||||
<th scope="row" style=" text-align: center;">Track</th>
|
||||
<th style=" text-align: center;">Artist</th>
|
||||
<center>
|
||||
<main class="container">
|
||||
<table class="striped" style="table-layout: fixed; overflow: hidden; text-align: center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" style="table-layout: fixed; overflow: hidden; text-align: center;">Track</th>
|
||||
<th scope="col"style="table-layout: fixed; overflow: hidden; text-align: center;">Artist</th>
|
||||
</tr>
|
||||
</thead style=" text-align: center;">
|
||||
<tbody style=" text-align: center;">
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in range(length) %}
|
||||
<tr style=" text-align: center;">
|
||||
<td style=" text-align: center;">{{ queue[i].track }}</td>
|
||||
<td style=" text-align: center;">{{ queue[i].artist }}</td>
|
||||
<tr>
|
||||
<td style="table-layout: fixed; overflow: hidden; text-align: center;">
|
||||
<a href="{{ queue[i].track_link }}" target="_blank" rel="noopener noreferrer">
|
||||
{{ queue[i].track }}
|
||||
</a>
|
||||
</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></center></main>
|
||||
</table>
|
||||
</main>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue