Spaces:
Sleeping
Sleeping
johndeniel
commited on
Commit
•
f966fd8
1
Parent(s):
1504d85
Update src/static/index.html
Browse files- src/static/index.html +57 -52
src/static/index.html
CHANGED
@@ -1,52 +1,57 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Spotify Playlist</title>
|
7 |
-
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
</
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
<
|
37 |
-
<
|
38 |
-
<
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Spotify Playlist</title>
|
7 |
+
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
font-family: 'Arial', sans-serif;
|
11 |
+
}
|
12 |
+
</style>
|
13 |
+
</head>
|
14 |
+
<body class="bg-gray-900 text-white">
|
15 |
+
<header class="bg-black p-6 shadow-md">
|
16 |
+
<h1 class="text-3xl font-bold text-green-500">Spotify API Demo</h1>
|
17 |
+
</header>
|
18 |
+
<main class="p-6">
|
19 |
+
<ul id="playlist" class="grid gap-6 md:grid-cols-2 lg:grid-cols-3"></ul>
|
20 |
+
</main>
|
21 |
+
|
22 |
+
<script>
|
23 |
+
async function fetchPlaylist() {
|
24 |
+
try {
|
25 |
+
const response = await fetch('/playlist');
|
26 |
+
const { tracks: { items } } = await response.json();
|
27 |
+
const playlistElement = document.getElementById('playlist');
|
28 |
+
|
29 |
+
items.forEach(({ track }) => {
|
30 |
+
const listItem = document.createElement('li');
|
31 |
+
listItem.className = 'flex flex-col md:flex-row items-start space-y-4 md:space-y-0 md:space-x-4 p-4 bg-gray-800 rounded-lg hover:bg-gray-700 transition shadow-lg';
|
32 |
+
|
33 |
+
listItem.innerHTML = `
|
34 |
+
<img src="${track.album.images[0].url}" alt="${track.name} cover" class="w-full md:w-48 h-48 object-cover rounded-md shadow-md">
|
35 |
+
<div class="flex flex-col space-y-2">
|
36 |
+
<h2 class="text-xl font-semibold">${track.name}</h2>
|
37 |
+
<p class="text-gray-400">Artists: ${track.artists.map(artist => artist.name).join(', ')}</p>
|
38 |
+
<p class="text-gray-400">Album: ${track.album.name}</p>
|
39 |
+
<p class="text-gray-400">Release Date: ${track.album.release_date}</p>
|
40 |
+
<p class="text-gray-400">Duration: ${Math.floor(track.duration_ms / 60000)}:${((track.duration_ms % 60000) / 1000).toFixed(0).padStart(2, '0')} minutes</p>
|
41 |
+
<p class="text-gray-400">Popularity: ${track.popularity}</p>
|
42 |
+
<a href="${track.external_urls.spotify}" target="_blank" class="text-green-500 hover:underline">Listen on Spotify</a>
|
43 |
+
<a href="https://open.spotify.com/playlist/4kTgs1z0nssQlYk3Q3xecY?si=cktIWgT6SMiEzF5qZfQSYw&pi=7GCDGY_zRmKUp&nd=1&dlsi=9394824faa9043fe" target="_blank" class="text-green-500 hover:underline">View Playlist</a>
|
44 |
+
</div>
|
45 |
+
`;
|
46 |
+
|
47 |
+
playlistElement.appendChild(listItem);
|
48 |
+
});
|
49 |
+
} catch (error) {
|
50 |
+
console.error('Error fetching playlist:', error);
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
fetchPlaylist();
|
55 |
+
</script>
|
56 |
+
</body>
|
57 |
+
</html>
|