Last active
April 25, 2023 22:40
-
-
Save dantodev/be05074a14f302f87f41ab6df0e1a90c to your computer and use it in GitHub Desktop.
Exports a playlist from the Sportify web client as JSON.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
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); | |
})(); |
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
Reminder: scroll all the way down before starting the script to lazy load all tracks.