Skip to content

Instantly share code, notes, and snippets.

@Quelklef
Created April 13, 2022 04:47
Show Gist options
  • Save Quelklef/fefb042046939fc3bac26ea3ba5d545b to your computer and use it in GitHub Desktop.
Save Quelklef/fefb042046939fc3bac26ea3ba5d545b to your computer and use it in GitHub Desktop.
Export a Spotify playlist via the web app
/* USAGE: Go to Spotify page for playlist, copy+paste into console, scroll */
songs = {};
const songCnt = parseInt(document.querySelector('.ebHsEf.RANLXG3qKB61Bh33I0r2').textContent, 10);
console.log(songCnt + ' songs');
id = setInterval(function() {
const nodes = Array.from(document.querySelectorAll('.h4HgbO_Uu1JYg5UGANeQ.wTUruPetkKdWAR1dd6w4'));
nodes.forEach(node => {
node = node.parentNode;
const title = node.querySelector('.fCtMzo.t_yrXoUO3qGsJS4Y6iXX').innerText;
const artist = node.querySelector('.iCQtmPqY0QvkumAOuCjr .hHrtFe').innerText;
const album = node.querySelector('.ebHsEf').innerText;
const index = parseInt(node.querySelector('.gAmaez').innerText, 10);
if (Number.isFinite(index)) {
songs[index] = { title, artist, album };
node.style.transition = 'all 0.75s';
node.style.background = '#0a340a';
node.style.paddingLeft = '1em';
}
});
const cntFound = Object.keys(songs).length;
console.log(`Found ${cntFound}/${songCnt}`);
if (cntFound === songCnt) {
clearInterval(id);
console.log(Object.keys(songs).sort((a, b) => a - b).map(k => {
const song = songs[k];
return `${song.title} ON ${song.album} BY ${song.artist}`;
}).join('\n'));
}
}, 1000);
@samm81
Copy link

samm81 commented May 17, 2022

wow the green highlighting is a great touch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment