Advertisement
Guest User

Spotify playlist to text

a guest
Feb 22nd, 2019
2,864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var songs = [];
  2. for (let entry of document.getElementsByClassName('tracklist')[0].children) {
  3.   let p = [];
  4.   for (item of entry.getElementsByClassName('ellipsis-one-line'))
  5.     p.push(item.innerText);
  6.   if (!p[0]) continue;
  7.  
  8.   let [song, artist, album] = p;
  9.   let artists = artist.split(", ");
  10.   song = song.replace(/-\s+(.+)/g, "($1)").replace(/\[(.+)]/g, "($1)");
  11.   console.log({song, artists, album});
  12.  
  13.   let fulltitle = artists[0] + " - " + song;
  14.  
  15.   // Handle featured artists
  16.   let featured = artists.slice(1);
  17.  
  18.   // Remove the ones already mentioned in the title
  19.   featured = featured.filter(x => !song.includes(x));
  20.  
  21.   if (featured.length > 0)
  22.     fulltitle += " (feat. " + featured.join(", ") + ")";
  23.  
  24.   songs.push(fulltitle);
  25. }
  26. var songlist = songs.join("\n");
  27. console.log(songlist);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement