Skip to content

Instantly share code, notes, and snippets.

@dantodev
Last active April 25, 2023 22:40
Show Gist options
  • Save dantodev/be05074a14f302f87f41ab6df0e1a90c to your computer and use it in GitHub Desktop.
Save dantodev/be05074a14f302f87f41ab6df0e1a90c to your computer and use it in GitHub Desktop.
Exports a playlist from the Sportify web client as JSON.
(() => {
function mapItem(itemNode) {
return {
title: getText(itemNode, '.tracklist-name'),
artist: getText(itemNode, '.TrackListRow__artists'),
album: getText(itemNode, '.TrackListRow__album'),
duration: getText(itemNode, '.tracklist-duration'),
unplayable: itemNode.matches('.tracklist-row-unplayable')
};
}
function getText(context, selector) {
let node = context.querySelector(selector);
return node ? node.innerText.trim() : "";
}
let list = Array.from(document.querySelectorAll('.contentSpacing > *:first-child .tracklist-row')).map(mapItem);
return JSON.stringify(list);
})();
@dantodev
Copy link
Author

Reminder: scroll all the way down before starting the script to lazy load all tracks.

@Humbarrt
Copy link

Humbarrt commented Apr 25, 2023

For anyone also stumbling upon this. The code doesn't work anymore. Try: https://developer.spotify.com/documentation/web-api/reference/get-playlist. It is way easier and more reliable.

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