-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpm-playlist-to-csv.js
33 lines (27 loc) · 964 Bytes
/
gpm-playlist-to-csv.js
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
(function playlistToCSV(response){
const csvHeader = ([[`"song"`,`"artist"`,`"album"`].join(',')]) + '\r\n';
const songList = response[1][0];
const songs = songList.map(song => {
const title = song[1];
const artist = song[3];
const album = song[4];
return ([`"${title}"`,`"${artist}"`,`"${album}"`].join(','));
});
// create the CSV content
const csvText = csvHeader + songs.join('\r\n');
console.log(`Crunched ${songs.length} songs`);
// create a downloadable blob
const fileBlob = new Blob(
[csvText],
{ type: 'text/csv;charset=utf-8;'}
);
const url = URL.createObjectURL(fileBlob);
const link = document.createElement('a');
link.setAttribute('href', url);
link.setAttribute('download', `playlist_${Date.now()}`);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
// clean-up
document.body.removeChild(link);
})(temp1); // temp1 is the variable that got stored