Skip to content

Instantly share code, notes, and snippets.

@flesler
Last active March 9, 2024 07:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flesler/289f856565629b3077d3 to your computer and use it in GitHub Desktop.
Save flesler/289f856565629b3077d3 to your computer and use it in GitHub Desktop.
Bookmarklet to export the list of songs from Spotify
<ul>
<li>Exports the list of songs from Spotify <i>Songs</i> or current playlist sections</li>
<li>It will open a popup, you need to allow them to open</li>
<li>You need to scroll all the way so Spotify loads all the song names</li>
<li>Only tested on Chrome!</li>
<li>Drag the following link to your bookmarks toolbar, click it once on Spotify "Songs" page</li>
</ul>
<a href="javascript:(function(){/*1.0*/var a=document.querySelector('[id^=collection-app-spotify]').contentDocument,b=a.querySelector('.songs');!b||'none'===b.style.display&&(b=a.querySelector('#pf-playlist-view'));var a=b.querySelectorAll('tbody tr'),c=[];[].forEach.call(a,function(a){var b=a.querySelector('.tl-name div'),d=a.querySelector('.tl-artists a');b&&d&&(a=a.dataset.uri.replace('spotify:track:','https://play.spotify.com/track/'),c.push(d.innerHTML+' - '+b.innerHTML+' [<a href=\''+a+'\'>link</a>]'))});c.length!==a.length&&alert(a.length-c.length+' songs could not be found, please scroll all the way');a='<ol><li>'+c.join('</li><li>')+'</li></ol>';window.open('data:text/html;charset=utf-8,'+encodeURIComponent(a))||alert('Please allow Spotify to open popups to see the list of songs')})();">Export songs</a>
<p>Uncompressed source</p>
<pre>(function() {
/*1.0*/
var doc = document.querySelector('[id^=collection-app-spotify]').contentDocument;
var panel = doc.querySelector('.songs');
// Songs hidden or not loaded, use playlist screen
if (!panel || panel.style.display === 'none') {
panel = doc.querySelector('#pf-playlist-view');
}
var trs = panel.querySelectorAll('tbody tr');
var songs = [];
[].forEach.call(trs, function(tr) {
var name = tr.querySelector('.tl-name div');
var artist = tr.querySelector('.tl-artists a');
if (name &amp;&amp; artist) {
var uri = tr.dataset.uri.replace('spotify:track:', 'https://play.spotify.com/track/');
songs.push(artist.innerHTML + ' - ' + name.innerHTML + ' [&lt;a href=&quot;'+uri+'&quot;&gt;link&lt;/a&gt;]');
}
});
if (songs.length !== trs.length) {
alert(trs.length - songs.length + ' songs could not be found, please scroll all the way');
}
var html = '&lt;ol&gt;&lt;li&gt;' + songs.join('&lt;/li&gt;&lt;li&gt;') + '&lt;/li&gt;&lt;/ol&gt;';
var win = window.open('data:text/html;charset=utf-8,'+encodeURIComponent(html));
if (!win) {
alert('Please allow Spotify to open popups to see the list of songs');
}
})();</pre>
(function() {
/*1.0*/
var doc = document.querySelector('[id^=collection-app-spotify]').contentDocument;
var panel = doc.querySelector('.songs');
// Songs hidden or not loaded, use playlist screen
if (!panel || panel.style.display === 'none') {
panel = doc.querySelector('#pf-playlist-view');
}
var trs = panel.querySelectorAll('tbody tr');
var songs = [];
[].forEach.call(trs, function(tr) {
var name = tr.querySelector('.tl-name div');
var artist = tr.querySelector('.tl-artists a');
if (name && artist) {
var uri = tr.dataset.uri.replace('spotify:track:', 'https://play.spotify.com/track/');
songs.push(artist.innerHTML + ' - ' + name.innerHTML + ' [<a href="'+uri+'">link</a>]');
}
});
if (songs.length !== trs.length) {
alert(trs.length - songs.length + ' songs could not be found, please scroll all the way');
}
var html = '<ol><li>' + songs.join('</li><li>') + '</li></ol>';
var win = window.open('data:text/html;charset=utf-8,'+encodeURIComponent(html));
if (!win) {
alert('Please allow Spotify to open popups to see the list of songs');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment