Tuesday, September 11, 2012

Export playlists from Google Play Music

After some brief googling, I was unable to find out a way to export playlists from Google Play Music, so I just figured it out for myself.

In order to do this, your Android device must be rooted, otherwise you won't have access to the music database file where the playlists are stored.

If you don't have an Android device, there's a chance you could use the android emulator from the Android SDK. You'd have to find an .apk file for the Google Play Music app, which shouldn't be too hard.

  1. First, make sure all of your tracks and playlists are synced with Google's servers:
    1. Install the Google Play Music app on the Android device. If it's already installed, open up the Google Play Store app, go to Menu --> My apps, and if it's in the list of updates, update it.

    2. Connect your Android device to the internet (data or wifi)

    3. Open the Google Play Music app

    4. This step will probably change as Google continues to update the app, but essentially you want it to show all of your music in the cloud and refresh it. The current way to do this is:

      At the top left of the app, make sure it says All music. If it says On device, tap it and change it to All music. Click Menu --> Refresh

    5. Wait for all of the tracks and playlists to sync (you should be able to see all of your playlists and music in the app)

    6. Exit the Google Play Music app by pressing the back button

  2. Next, you need to get the music database file from the Android device. The file is located at /data/data/com.google.android.music/databases/music.db. There are several ways to do this:

    • You can use a file manager app, browse to the file, copy it to your SD card, then plug the phone into your computer and copy it from there. Whichever file manager app you use, it needs root access. I'm currently using File Explorer by NextApp with the Root Add-On.

    • Using a file manager app, browse to the file and send it to yourself using whatever method is easiest for you (email, Dropbox, etc.).

    • As an Android developer, because I already have the Android SDK installed, my preferred method is to transfer the file using the Android SDK Platform Tools over the command line.

  3. Open the music.db file with your favorite SQLite database client (I prefer Sqliteman) to get the playlist data, using this query:

  4. select name as "Playlist Name", artist, title from listitems join music on listitems.musicid = music.id join lists on listitems.listid = lists.id order by "Playlist Name";

    From there you can export the data to a friendly format, such as a CSV file. To do a quick dump of the data from a Linux/Mac terminal, you can run this command:

    sqlite3 music.db 'select name as "Playlist Name", artist, title from listitems join music on listitems.musicid = music.id join lists on listitems.listid = lists.id order by "Playlist Name"' > playlists.txt

There are a lot of other columns available, such as album. to get the full list, just replace everything in the query from select to from with *, i.e. select * from listitems...