Print Playlist from Google Play Music – Guide

exportgoogle-play-music

I want to print a list of songs (with artist, album, rating and, if possible, number of plays and duration) from my Google Play Music account.

There is no easy way to do this from the app. Doing print-screens as I page through a long list of songs is not tenable.

I would be happy with an export of data to a standard format (plain text, CSV, XML, etc.) that I can manipulate myself.

Any suggestions?

Best Answer

Notice: While this answer is still completely accurate, now Google is phasing out Google Play Music in favor of YouTube Music. If you use their automatic converter, your playlists (including uploaded music) will be retained in YouTube Music. Unfortunately uploaded songs are not visible in shared playlists there either. So I made an equivalent script to the below for YouTube Music.


Modifying darkliquid's answer, I came up with the following which allows for multiple playlists to be saved at once.

Instructions:

  1. Go to Your Playlists page.
  2. Paste in the JavaScript code below into your console (press F12 to open your console).
  3. Click on a playlist that you want to save to text.
  4. Once on the playlist page, scroll to the bottom relatively slowly (so that each entry can be seen).
  5. After you've scrolled to the bottom, navigate back to the playlists page (same as in step 1.) using the menu or your browsers back button.
  6. Repeat steps 3-5 for all playlists you want to save to text.
  7. Once you've done this for all the playlists you want to save to text, you can either type JSON.stringify(tracklistObj, null, '\t') (change the '\t' to ' ' if you want minimal indentation) or tracklistObj if you just want the JavaScript object to manipulate it your own way. If you want it sorted, run the command Object.values(tracklistObj).forEach(a => a.sort()) before calling the JSON.stringify command.

Be careful to not refresh the page before you've completed all that you want to do or else you'll have to restart from step 1.

// Setup
var tracklistObj = {},
    currentPlaylist,
    checkIntervalTime = 100,
    lastTime;

// Process the visible tracks
function getVisibleTracks() {
    var playlist = document.querySelectorAll('.song-table tr.song-row');
    for(var i = 0; i < playlist.length ; i++) { 
        var l = playlist[i];

        var title = l.querySelector('td[data-col="title"] .column-content');
        if(title !== null)
            title = title.textContent;

        var artist = l.querySelector('td[data-col="artist"] .column-content');
        if(artist !== null)
            artist = artist.textContent;

        var duration = l.querySelector('td[data-col="duration"] span');
        if(duration !== null)
            duration = duration.textContent;

        var album = l.querySelector('td[data-col="album"] .column-content');
        if(album !== null)
            album = album.textContent;

        var playCount = l.querySelector('td[data-col="play-count"] span');
        if(playCount !== null)
            playCount = playCount.textContent;

        var rating = l.querySelector('td[data-col="rating"]');
        if(rating !== null)
            rating = rating.textContent;

        // Add it if it doesn't exist already
        if(tracklistObj[currentPlaylist] && !tracklistObj[currentPlaylist].includes(artist + " - " + title)) {
            tracklistObj[currentPlaylist].push(artist + " - " + title);

            if(printTracksToConsole) {
                console.log(artist + ' - ' + title);
            }
        }
    }
}

// Listen for page changes
window.onhashchange = function(e) {
    currentPlaylist = null; 

    var doneLoading = setInterval(function() {
        var playListName = document.querySelector('.gpm-detail-page-header h2[slot="title"]');
        if(playListName != null) {
            currentPlaylist = playListName.innerText;
            if(tracklistObj[currentPlaylist] === undefined) {
                tracklistObj[currentPlaylist] = [];
            }

            console.log("===================================");
            console.log("Adding to playlist " + currentPlaylist);

            getVisibleTracks();

            clearInterval(doneLoading);
        }
    }, 100);

}

// Check for new tracks every so often
setInterval(function() {
    getVisibleTracks();
}, checkIntervalTime);

// Whether or not to print the tracks obtained to the console
var printTracksToConsole = false;

You can also print out track names to the console as you go by changing printTracksToConsole to true (you should do this between steps 2 and 3).

Note that you can probably ignore all GET and POST errors in the console (these are generated by Play Music itself, not this script).

Also note that currently it's setup only to give Artist - Track name, but you can easily edit the line that has tracklistObj[currentPlaylist].push(artist + " - " + title); with album, playCount, duration, or rating, and/or whatever formatting you want (including CSV format if you so please). Do this before step 2.

Example output (all Google Play playlists I currently have) with default settings. It took about 5 minutes in total to navigate to each of the 32 playlists, scroll down them, and then convert the result to text.

P.S. You might be interested using a site I found called Tune My Music to make YouTube playlists (but YouTube restricts playlist creation to 10 a day) from the output so your friends can listen to your Google Playlists. If you do this, you probably want to use something like TextMechanic to remove the quotes and .mp3 from the outputted list.