Last active
August 10, 2021 02:35
-
-
Save rxw1/58f1460eb5d147b3a0569b45252b5bee to your computer and use it in GitHub Desktop.
Spotify Playlist to JSON (Bookmarklet)
This file contains hidden or 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
javascript:!function(){const o=document.querySelector("#main > div > div.Root__top-container > div.Root__main-view > main > div.os-host.os-host-foreign.os-theme-spotify.os-host-resize-disabled.os-host-scrollbar-horizontal-hidden.main-view-container__scroll-node.os-host-transition.os-host-overflow.os-host-overflow-y > div.os-padding > div > div > div.main-view-container__scroll-node-child > section > div.contentSpacing._4c3b6e4e88112fc8ef88512cbe7521ed-scss.da51a6e223c7200d373a2fd0614d7c33-scss > div.faffb409617fd7cf35017fde898cf860-scss > div > div > a").textContent.replace(/[^A-Za-z]/g,""),e=document.querySelector("#main > div > div.Root__top-container > div.Root__main-view > main > div.os-host.os-host-foreign.os-theme-spotify.os-host-resize-disabled.os-host-scrollbar-horizontal-hidden.main-view-container__scroll-node.os-host-transition.os-host-overflow.os-host-overflow-y > div.os-padding > div > div > div.main-view-container__scroll-node-child > section > div.contentSpacing._4c3b6e4e88112fc8ef88512cbe7521ed-scss.da51a6e223c7200d373a2fd0614d7c33-scss > div.faffb409617fd7cf35017fde898cf860-scss > span > h1").textContent.replace(/[^A-Za-z]/g,""),i=[...document.querySelectorAll("div._235729a60d5e265806e8509d8633b779-scss > div:nth-child(3) > div > div.bc1fe098cc33981dc67049628a2cac6b-scss > div:nth-child(2) > div > div")].map((o=>o.innerText)).map((o=>o.split("\n"))).map((o=>({Track:parseInt(o[0]),Title:o[1],Artist:o[2],Album:o[3],Duration:o[5]})));var t,s,d,n;t=i,s=`${o} - ${e}`,d="data:text/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(t)),(n=document.createElement("a")).setAttribute("href",d),n.setAttribute("download",s+".json"),document.body.appendChild(n),n.click(),n.remove()}(); |
This file contains hidden or 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() { | |
const maker = document.querySelector('#main > div > div.Root__top-container > div.Root__main-view > main > div.os-host.os-host-foreign.os-theme-spotify.os-host-resize-disabled.os-host-scrollbar-horizontal-hidden.main-view-container__scroll-node.os-host-transition.os-host-overflow.os-host-overflow-y > div.os-padding > div > div > div.main-view-container__scroll-node-child > section > div.contentSpacing._4c3b6e4e88112fc8ef88512cbe7521ed-scss.da51a6e223c7200d373a2fd0614d7c33-scss > div.faffb409617fd7cf35017fde898cf860-scss > div > div > a').textContent.replace(/[^A-Za-z]/g, "") | |
const title = document.querySelector('#main > div > div.Root__top-container > div.Root__main-view > main > div.os-host.os-host-foreign.os-theme-spotify.os-host-resize-disabled.os-host-scrollbar-horizontal-hidden.main-view-container__scroll-node.os-host-transition.os-host-overflow.os-host-overflow-y > div.os-padding > div > div > div.main-view-container__scroll-node-child > section > div.contentSpacing._4c3b6e4e88112fc8ef88512cbe7521ed-scss.da51a6e223c7200d373a2fd0614d7c33-scss > div.faffb409617fd7cf35017fde898cf860-scss > span > h1').textContent.replace(/[^A-Za-z]/g, "") | |
const tracks = [...document.querySelectorAll('div._235729a60d5e265806e8509d8633b779-scss > div:nth-child(3) > div > div.bc1fe098cc33981dc67049628a2cac6b-scss > div:nth-child(2) > div > div')] | |
.map(e => e.innerText) | |
.map(f => f.split('\n')) | |
.map(x => { | |
return { | |
Track: parseInt(x[0]), | |
Title: x[1], | |
Artist: x[2], | |
Album: x[3], | |
Duration: x[5] | |
}; | |
}) | |
// https://stackoverflow.com/a/30800715/220472 | |
function downloadObjectAsJson(exportObj, exportName){ | |
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj)); | |
var downloadAnchorNode = document.createElement('a'); | |
downloadAnchorNode.setAttribute("href", dataStr); | |
downloadAnchorNode.setAttribute("download", exportName + ".json"); | |
document.body.appendChild(downloadAnchorNode); // required for firefox | |
downloadAnchorNode.click(); | |
downloadAnchorNode.remove(); | |
} | |
downloadObjectAsJson(tracks, `${maker} - ${title}`) | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment