Skip to content

Instantly share code, notes, and snippets.

@fcingolani
Last active June 12, 2017 01:50
Show Gist options
  • Save fcingolani/b2cccde2dd2c0b1dc10639a434f2d9c8 to your computer and use it in GitHub Desktop.
Save fcingolani/b2cccde2dd2c0b1dc10639a434f2d9c8 to your computer and use it in GitHub Desktop.

Go to your album collecion.

Scroll down the whole list until there are no more albums to load.

Paste the following code in the JS Console:

var albumEls = document.getElementsByClassName('media-object');
var albums = [];

for(var i = 0; i < albumEls.length; i++){
	var albumEl = albumEls[i];
	albums.push({
		title: albumEl.children[0].children[1].innerText,
		artist: albumEl.children[1].children[1].innerText,
	});
}

console.log(albums);

var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(albums));

var a = document.createElement('a');
a.href = 'data:' + data;
a.download = 'albums.json';
a.innerHTML = 'Download JSON';
a.className = 'navlist-itemlink';

document.querySelector('.download-item a').remove();

var container = document.querySelector('.download-item');
container.appendChild(a);

On your left navbar a "Download JSON" link will appear. Click it to download your album list as a JSON file:

[{"title":"20 Años No Es Nada","artist":"2 minutos"},{"title":"Superocho","artist":"2 minutos"},{"title":"Un Mundo De Sensaciones","artist":"2 minutos"},{"title":"The Best of 2Pac - Pt. 1: Thug","artist":"2Pac"},{"title":"The Best of 2Pac - Pt. 2: Life","artist":"2Pac"},{"title":"Hecho, Es Simple (XX Aniversario)","artist":"7 Notas 7 Colores"},{"title":"Hangyaku No March / Dark Horse / Daremo Shiranai /","artist":"9mm Parabellum Bullet"},{"title":"Seimei No Waltz","artist":"9mm Parabellum Bullet"},{"title":"Termination","artist":"9mm Parabellum Bullet"},{"title":"No Man's Sky: Music For An Infinite Universe","artist":"65daysofstatic"},{"title":"107 Faunos","artist":"107 Faunos"},{"title":"El Tesoro Que Nadie Quiere","artist":"107 Faunos"}...

Go to one of your playlists.

Scroll down the whole list until there are no more tracks to load.

Paste the following code in the JS Console:

var trackEls = document.getElementsByClassName('tracklist-col name');
var tracks = [];

for(var i = 0; i < trackEls.length; i++){
	var trackEl = trackEls[i];
	var trackArtistAndAlbum = trackEl.children[0].children[1].innerText.split('•');
	tracks.push({
		title:	trackEl.children[0].children[0].innerText,
		artist: trackArtistAndAlbum[0],
		album: trackArtistAndAlbum[1],
	});
}

var imageUrl = document.getElementsByClassName('cover-art-image')[0].style['background-image'];
imageUrl = imageUrl.substring(5,imageUrl.length-2);

var playlist = {
	name: document.getElementsByClassName('mo-info-name')[0].innerText,
	url: document.location.href,
	imageUrl: imageUrl,
	tracks: tracks,
};

console.log(playlist);

var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(playlist));

var a = document.createElement('a');
a.href = 'data:' + data;
a.download = playlist.name + '.json';
a.innerHTML = 'Download JSON';
a.className = 'navlist-itemlink';

document.querySelector('.download-item a').remove();

var container = document.querySelector('.download-item');
container.appendChild(a);

On your left navbar a "Download JSON" link will appear. Click it to download your album list as a JSON file:

{"name":"Name","url":"https://open.spotify.com/user/fcingolani/playlist/xxxxxxxxxxxx","imageUrl":"https://mosaic.scdn.co/xxx/xxxxxxxx","tracks":[{"title":"Speed Trials","artist":"Elliott Smith","album":"Either/Or"},{"title":"Ready or Not","artist":"Fugees","album":"Greatest Hits"},{"title":"Seguro Es Por Mi Culpa","artist":"Massacre","album":"Diferentes Maneras"},{"title":"Beat The Devil's Tattoo","artist":"Black Rebel Motorcycle Club","album":"Beat The Devil's Tatt...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment