Last active
November 8, 2020 12:34
-
-
Save d-schmidt/33ff4aeb539b1fd2a5d37cfa0b08d4cf to your computer and use it in GitHub Desktop.
How to convert a Google Play Music Playlist to CSV
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
// 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