Skip to content

Instantly share code, notes, and snippets.

@liamross
Last active November 12, 2020 17:06
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 liamross/108f1131a3545765c50ed1616585030e to your computer and use it in GitHub Desktop.
Save liamross/108f1131a3545765c50ed1616585030e to your computer and use it in GitHub Desktop.
Get all songs from Google Play Music as CSV string.

Edit: You should be able to just use Google Takout to export your song data: https://takeout.google.com

With the recent moves towards YouTube Music which is pretty terrible, I figured it was time to embrace Spotify, so I wrote a script to get all of my Google Play Music songs as a CSV so I can add them to Spotify.

  1. Paste in the function below (getAllSongs) into the console when you are in https://play.google.com/music/listen#/all and scrolled all the way to the top
  2. Type await getAllSongs() and wait for the script to scroll all the way down
  3. Confirm that your LENGTH: output matches the total songs on the top of the page
  4. Copy the output string, it's valid CSV for importing into Google Sheets, Excel, etc.
async function getAllSongs() {
const songs = {};
const m = document.getElementById('mainContainer');
let prevScrollTop = -1;
while (true) {
if (prevScrollTop === m.scrollTop) {
break;
}
await new Promise(r => {
setTimeout(() => r(), 25);
});
prevScrollTop = m.scrollTop;
m.scrollTop += 400;
const rows = document.querySelectorAll('.song-row');
rows.forEach(r => {
const title = r.querySelector('[data-col="title"] .column-content').textContent;
const artist = r.querySelector('[data-col="artist"] .text').textContent;
const album = r.querySelector('[data-col="album"] .text').textContent;
const liked = r.querySelector('[data-col="rating"]').getAttribute('data-rating') === '5';
const key = title + artist + album;
songs[key] = { title, artist, album, liked: liked ? "true" : "false" };
});
}
console.log("LENGTH: ", Object.values(songs).length);
return Object.values(songs)
.map(song => Object.values(song).map(songPart => `"${songPart}"`).join(', '))
.join('\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment