-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
511 lines (451 loc) · 17.4 KB
/
index.html
1
2
3
4
5
6
7
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="google-site-verification"
content="WzLutm74dor0Bj5D-6NeFNi9oz6IKAOsLjKzmtk9LnE"
/>
<title>
Fireflies🧚🏻 | Convert spotify playlist to apple music playlist
</title>
<link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
rel="stylesheet"
/>
<style>
/* Loader styles */
.loader {
border: 2px solid #f3f3f3; /* Light grey */
border-top: 2px solid #3498db; /* Blue */
border-radius: 50%;
width: 12px;
height: 12px;
animation: spin 2s linear infinite;
display: inline-block;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<header class="bg-primary text-white p-2">
<div class="container">
<h1>Fireflies🧚🏻</h1>
</div>
</header>
<div style="margin: 1%" id="finalResult">
<div
id="finalResultAlert"
class="alert alert-dismissible fade show"
role="alert"
style="display: none"
>
<p id="finalResultP" style="font-weight: bold;"></p>
<!-- <button
type="button"
class="btn-close"
data-bs-dismiss="alert"
aria-label="Close"
></button> -->
</div>
</div>
<div class="container mt-5">
<form id="submitNewUserForm">
<div class="form-group">
<label for="userEmailId">Enter Your Email:</label>
<input
type="text"
class="form-control"
id="userEmailId"
placeholder="Enter Your Email"
/>
</div>
<!-- Option 1: Create Playlist from Liked Songs -->
<div id="likedSongsOption" class="form-group mt-4">
<h5>Option 1: Create a Playlist from Liked Songs</h5>
<button
id="makePlaylistButton"
class="btn btn-success mt-2"
style="width: 100%;"
type="button"
>
Make Playlist of Liked Songs
</button>
</div>
<!-- Option 2: Enter Playlist ID -->
<div id="spotifyPlaylistOption" class="form-group mt-4">
<h5>Option 2: Enter a Spotify Playlist ID</h5>
<label for="spotifyPlaylistId">Spotify Playlist ID:</label>
<input
type="text"
class="form-control"
id="spotifyPlaylistId"
placeholder="Enter Spotify Playlist ID"
/>
<button
id="submitPlaylistId"
class="btn btn-primary mt-2"
style="width: 100%;"
type="submit"
>
Submit Playlist ID
</button>
</div>
</form>
<button
class="btn btn-info mt-3"
id="toggleBtn"
type="button"
data-toggle="collapse"
data-target="#resultsCollapse"
aria-expanded="True"
aria-controls="resultsCollapse"
style="margin-bottom: 10px; display: none;"
>
Show Results
</button>
<div id="resultsCollapse" class="collapse mt-3">
<p id="results" style="display: none" class="alert alert-info">
Results
</p>
</div>
<form id="appleMusicForm" style="margin-bottom: 10%; display: none">
<div class="form-group">
<label for="appleMusicAuthToken">Apple Music Auth Token:</label>
<input
type="text"
class="form-control"
id="appleMusicAuthToken"
placeholder="Enter Apple Music Auth Token"
/>
</div>
<div class="form-group">
<label for="appleMusicMediaUserToken"
>Apple Music Media User Token:</label
>
<input
type="text"
class="form-control"
id="appleMusicMediaUserToken"
placeholder="Enter Apple Music Media User Token"
/>
<span style="font-size: 10px; color: blue">
Don't know how to get these tokens?
<button
style="
font-size: 10px;
color: blue;
background: transparent;
border: none;
padding: 0;
margin: 0;
cursor: pointer;
"
id="toggleBtn"
type="button"
data-toggle="collapse"
data-target="#get-apple-music-tokens-guide"
aria-expanded="true"
aria-controls="get-apple-music-tokens-guide"
onclick="toggleGuide()"
>
Click here
</button>
</span>
</div>
</span>
<div class="form-group">
<label for="newPlaylistName">New Playlist Name:</label>
<input
type="text"
class="form-control"
id="newPlaylistName"
placeholder="Enter New Playlist Name"
/>
</div>
<button id="createAppleMusicPlaylist" class="btn btn-primary">
Create Playlist
</button>
</form>
<div id="get-apple-music-tokens-guide" class="collapse mt-3" style="border: 1px solid #ccc; padding: 15px; background-color: #f9f9f9; border-radius: 5px;">
<p style="font-weight: bold;">Here is the guide</p>
<ol style="margin-left: 20px; padding-left: 0;">
<li style="margin-bottom: 10px;">
Login to Apple Music in a browser.
</li>
<li style="margin-bottom: 10px;">
Open Dev Tools and switch to the Network Tab. Select Fetch/XHR filter.
(Just do a cmd/ctrl+shift+c, the dev tools will open)
</li>
<li style="margin-bottom: 10px;">
Click on the Recently Added section in the side navbar.
</li>
<li style="margin-bottom: 10px;">
From the request headers, copy and keep the values of these keys for future use:
<ul style="margin-top: 10px; padding-left: 20px; list-style-type: disc;">
<li style="margin-bottom: 5px;">
Authorization (Copy the code after the word Bearer, excluding the space)
</li>
<li>
Media-user-token
</li>
</ul>
</li>
</ol>
<img src="apple_tokens_image.png" alt="Apple Music Tokens Guide Image" style="max-width: 100%; border: 1px solid #ccc; border-radius: 5px; margin-top: 15px;" />
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// sending fetch request for new user
document.getElementById("submitPlaylistId").addEventListener("click", function (e) {
e.preventDefault();
const spotifyPlaylistId = document.getElementById("spotifyPlaylistId").value;
const userEmailId = document.getElementById("userEmailId").value;
const encodedUserEmail = encodeURIComponent(userEmailId);
const encodedPlaylistId = encodeURIComponent(spotifyPlaylistId);
const submitButton = document.getElementById("submitPlaylistId");
if (!spotifyPlaylistId || !userEmailId) {
alert("Please fill in both the playlist ID and the email.");
return;
}
// Show loader
submitButton.innerHTML = '<div class="loader"></div>';
const requestOptions = {
method: "GET",
redirect: "follow",
};
fetch(
`https://fireflies.radioactive11.com/get-spotify-playlist/${encodedUserEmail}/${encodedPlaylistId}`, // Domain
//`https://13.60.179.94/get-spotify-playlist/${encodedUserEmail}/${encodedPlaylistId}`, // AWS
// `https://fireflies-0rmt.onrender.com/get-spotify-playlist/${encodedUserEmail}/${encodedPlaylistId}`, //render
// `http://127.0.0.1:8000/get-spotify-playlist/${encodedUserEmail}/${encodedPlaylistId}`,
requestOptions
)
.then((response) => {
if (!response.ok) {
throw new Error(
"Network response was not ok " + response.statusText
);
}
return response.json();
})
.then((data) => {
localStorage.setItem("user_email", userEmailId);
const resultsElement = document.getElementById("results");
resultsElement.textContent = "";
const listElement = document.createElement("ul");
data.forEach((item) => {
const listItem = document.createElement("li");
listItem.textContent = item;
listElement.appendChild(listItem);
});
resultsElement.appendChild(listElement);
resultsElement.style.display = "block";
document.getElementById("toggleBtn").style.display = "block";
document.getElementById("appleMusicForm").style.display = "block";
})
.catch((error) => {
console.error(
"There has been a problem with your fetch operation:",
error
);
})
.finally(() => {
submitButton.innerHTML = 'Submit';
});
});
//creating playlist from liked songs
document.getElementById("makePlaylistButton").addEventListener("click", function (e) {
e.preventDefault();
const userEmailId = document.getElementById("userEmailId").value;
const encodedUserEmail = encodeURIComponent(userEmailId);
const makePlaylistButton = document.getElementById("makePlaylistButton");
const submitButton = document.getElementById("submitPlaylistId");
if (!userEmailId) {
alert("Please fill in the email.");
return;
}
// Show loader
makePlaylistButton.innerHTML = '<div class="loader"></div>';
submitButton.disabled = true;
const requestOptions = {
method: "GET",
redirect: "follow",
};
fetch(
`https://fireflies.radioactive11.com/get-liked-songs/${encodedUserEmail}`, // Domain
//`https://13.60.179.94/get-spotify-playlist/${encodedUserEmail}/${encodedPlaylistId}`, // AWS
// `https://fireflies-0rmt.onrender.com/get-spotify-playlist/${encodedUserEmail}/${encodedPlaylistId}`, //render
// `http://127.0.0.1:8000/get-liked-songs/${encodedUserEmail}`,
requestOptions
)
.then((response) => {
if (!response.ok) {
throw new Error(
"Network response was not ok " + response.statusText
);
}
return response.json();
})
.then((data) => {
localStorage.setItem("user_email", userEmailId);
const resultsElement = document.getElementById("results");
resultsElement.textContent = "";
const listElement = document.createElement("ul");
data.forEach((item) => {
const listItem = document.createElement("li");
listItem.textContent = item;
listElement.appendChild(listItem);
});
resultsElement.appendChild(listElement);
resultsElement.style.display = "block";
document.getElementById("toggleBtn").style.display = "block";
document.getElementById("appleMusicForm").style.display = "block";
})
.catch((error) => {
console.error(
"There has been a problem with your fetch operation:",
error
);
})
.finally(() => {
makePlaylistButton.innerHTML = 'Make Playlist of Liked Songs';
submitButton.disabled = false;
});
});
async function checkTaskStatus(taskId) {
// const response = await fetch(`http://127.0.0.1:8000/task_status/${taskId}`);
// const response = await fetch(`https://13.60.179.94/task_status/${taskId}`);
const response = await fetch(`https://fireflies.radioactive11.com/task_status/${taskId}`);
const data = await response.json();
if(data.state === 'PENDING'){
return 'PENDING';
}
else if (data.state === 'PROGRESS') {
return 'PROGRESS';
} else if (data.state === 'SUCCESS') {
return 'SUCCESS';
}
else if(data.state === 'FALIURE'){
return 'FALIURE';
}else {
return 'UNKNOWN';
}
}
// sending fetch request for creating new playlist on apple music
document.getElementById("createAppleMusicPlaylist").addEventListener("click", function (e) {
e.preventDefault();
const appleMusicAuthToken = document.getElementById("appleMusicAuthToken").value;
const appleMusicMediaUserToken = document.getElementById("appleMusicMediaUserToken").value;
const newPlaylistName = document.getElementById("newPlaylistName").value;
const createButton = document.getElementById("createAppleMusicPlaylist");
if (!appleMusicAuthToken || !appleMusicMediaUserToken || !newPlaylistName) {
alert("Please fill in all the fields.");
return;
}
// Show loader
createButton.innerHTML = '<div class="loader"></div>';
user_email_id = localStorage.getItem("user_email");
const requestData = {
user_email: user_email_id,
apple_music_auth_token: appleMusicAuthToken,
apple_music_media_token: appleMusicMediaUserToken,
new_playlist_name: newPlaylistName,
};
const requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
redirect: "follow",
body: JSON.stringify(requestData),
};
fetch(
"https://fireflies.radioactive11.com/create-apple-music-playlist", //Domain
// "https://13.60.179.94/create-apple-music-playlist", //AWS
// "https://fireflies-0rmt.onrender.com/create-apple-music-playlist", //render
//"http://127.0.0.1:8000/create-apple-music-playlist",
requestOptions
)
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok " + response.statusText);
}
return response.json();
})
.then((data) => {
const alertElement = document.getElementById("finalResultAlert");
const alertMessage = document.getElementById("finalResultP");
const taskId = data.playlist_creation_task_id;
// Function to check the task status periodically
function pollTaskStatus() {
checkTaskStatus(taskId).then((response) => {
console.log(response);
if (response === 'PROGRESS') {
alertMessage.textContent = "Converting playlist...";
alertElement.classList.add("alert-primary");
setTimeout(pollTaskStatus, 1000);
} else if (response === 'SUCCESS') {
alertMessage.textContent = "The playlist is converted successfully!";
alertElement.classList.add("alert-success");
} else if (response === 'FAILURE') {
alertMessage.textContent = "An error occurred while converting the playlist. Please try again.";
alertElement.classList.add("alert-danger");
} else {
alertMessage.textContent = "Task is in progress...";
alertElement.classList.add("alert-primary");
setTimeout(pollTaskStatus, 1000);
}
}).catch((error) => {
console.error("Error checking task status:", error);
alertElement.classList.add("alert-danger");
alertMessage.textContent = "An error occurred while checking task status. Please try again.";
});
alertElement.style.display = "block";
}
pollTaskStatus();
})
.catch((error) => {
console.error("There has been a problem with your fetch operation:", error);
})
.finally(() => {
createButton.innerHTML = 'Create Playlist';
});
});
function scrollToGuide() {
var element = document.getElementById("get-apple-music-tokens-guide");
if (element) {
element.scrollIntoView({ behavior: "smooth", block: "start" });
}
}
function toggleGuide() {
var guide = document.getElementById("get-apple-music-tokens-guide");
var button = document.getElementById("toggleBtn");
if (guide.style.display === "none" || guide.style.display === "") {
guide.style.display = "block";
button.setAttribute("aria-expanded", "true");
guide.scrollIntoView({ behavior: "smooth", block: "start" });
} else {
guide.style.display = "none";
button.setAttribute("aria-expanded", "false");
}
}
</script>
</body>
</html>
<!-- // alertMessage.textContent = data;
// if (data.includes("succesfully")) {
// alertElement.classList.remove("alert-danger");
// alertElement.classList.add("alert-success");
// } else {
// alertElement.classList.remove("alert-success");
// alertElement.classList.add("alert-danger");
// }
// alertElement.style.display = "block"; -->