Skip to content

Commit 7e7b314

Browse files
committed
- playing around with the spotify API
1 parent 39a8eb4 commit 7e7b314

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

tools/spotify_test.html

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
background: white;
5757
}
5858

59-
.card-back {
60-
transform: rotateY(180deg);
59+
.card-back p.year {
60+
font-size: 24px;
61+
margin-top: 8px;
6162
}
6263

6364
.hidden {
@@ -176,7 +177,6 @@
176177
const card = document.createElement('div');
177178
card.className = 'card';
178179

179-
// Create the inner structure first
180180
const cardInner = document.createElement('div');
181181
cardInner.className = 'card-inner';
182182

@@ -190,46 +190,52 @@
190190
<div class="p-4">
191191
<h3 class="text-xl font-bold">${track.name}</h3>
192192
<p class="text-gray-600">${track.artist}</p>
193-
<p class="text-gray-500">${track.year}</p>
193+
<p class="text-gray-500 year">${track.year}</p>
194194
</div>
195195
`;
196196

197-
// Assemble the card
198197
cardInner.appendChild(cardFront);
199198
cardInner.appendChild(cardBack);
200199
card.appendChild(cardInner);
201200

202-
// Generate QR code after the element is in the DOM
203-
setTimeout(() => {
204-
new QRCode(cardFront, {
205-
text: `https://www.gptgames.dev/tools/spotify_test.html?track=${track.id}`,
206-
width: 200,
207-
height: 200
208-
});
209-
}, 0);
201+
// Create QR code with larger size
202+
new QRCode(cardFront, {
203+
text: `https://www.gptgames.dev/tools/spotify_test.html?track=${track.id}`,
204+
width: 220,
205+
height: 220,
206+
colorDark: "#000000",
207+
colorLight: "#ffffff",
208+
});
210209

211210
return card;
212211
}
213212

213+
214214
async function createQRCodesFromPlaylist() {
215215
const input = prompt("Enter Spotify playlist URL:");
216+
const maxTracks = 20; // Limit to 20 tracks
217+
216218
if (!input) return;
217219

218220
try {
219221
const tracks = await getPlaylistTracks(input);
220-
221222
if (tracks.length === 0) {
222223
throw new Error('No valid tracks found in playlist');
223224
}
224225

225226
const printArea = document.getElementById('printArea');
226227
printArea.innerHTML = '';
227228

228-
tracks.forEach(track => {
229+
// Take only the first 20 tracks
230+
tracks.slice(0, maxTracks).forEach(track => {
229231
printArea.appendChild(createQRCard(track));
230232
});
231233

232-
window.print();
234+
// Add a small delay before printing to ensure QR codes are generated
235+
setTimeout(() => {
236+
window.print();
237+
}, 500);
238+
233239
} catch (error) {
234240
alert('Error processing tracks: ' + error.message);
235241
console.error('Detailed error:', error);

0 commit comments

Comments
 (0)