Skip to content

Instantly share code, notes, and snippets.

@d-schmidt
Last active November 8, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-schmidt/33ff4aeb539b1fd2a5d37cfa0b08d4cf to your computer and use it in GitHub Desktop.
Save d-schmidt/33ff4aeb539b1fd2a5d37cfa0b08d4cf to your computer and use it in GitHub Desktop.
How to convert a Google Play Music Playlist to CSV
// open playlist or album
// paste this into the console in dev tools (F12) of browser:
var seenSongs = {};
var seenSongTitles = {};
var playlistTable = document.querySelectorAll('.song-table tbody')[0];
function printSongs() {
let playlist = playlistTable.querySelectorAll('tr.song-row');
for(let i = 0; i < playlist.length; i++) {
let l = playlist[i];
let index = l.querySelectorAll('td[data-col="index"] .column-content')[0].textContent;
let title = l.querySelectorAll('td[data-col="title"] .column-content')[0].textContent;
if (!(index in seenSongs) && !(title in seenSongTitles)) {
let artist = l.querySelectorAll('td[data-col="artist"] .column-content')[0].textContent;
let album = l.querySelectorAll('td[data-col="album"] .column-content')[0].textContent;
seenSongs[index] = artist + '|' + title + '|' + album;
seenSongTitles[title] = artist + '|' + title + '|' + album;
console.log(artist + '|' + title + '|' + album);
}
}
}
printSongs();
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === 'data-start-index') {
printSongs();
}
});
});
observer.observe(playlistTable, { attributes: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment