Skip to content

Instantly share code, notes, and snippets.

@gurchik
Created March 1, 2023 06:25
Show Gist options
  • Save gurchik/4ec8a0424cf4d55610946ae4e4081a95 to your computer and use it in GitHub Desktop.
Save gurchik/4ec8a0424cf4d55610946ae4e4081a95 to your computer and use it in GitHub Desktop.
Convert Spotify Playlist to JSON
/*
1. Open the playlist in Spotify Web (logged in if it's a private playlist)
2. Paste this in the browser's Developer Tools
For playlists longer than a handful of tracks, the entire track list won't be loaded in the DOM.
Scrolling down the page will rows from the top and vice versa. Therefore you will need to run this,
scroll down on the page to the last track outputted, run it again, etc until you get them all, then
combine the results together.
*/
(() => {
function getText(element, selector) {
return element.querySelector(selector).innerText.trim();
}
const rows = Array.from(document.querySelectorAll('[data-testid="playlist-tracklist"] [data-testid="tracklist-row"]'));
const ret = rows.map(row => ({
title: getText(row, '.t_yrXoUO3qGsJS4Y6iXX'),
artist: getText(row, '.rq2VQ5mb9SDAFWbBIUIn'),
}));
console.log(ret); // change this to suit your needs
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment