Saturday, August 24, 2013

Import playlists into Google Play Music


I've already covered getting playlists out of Google Play Music, but what if you want to import your playlists into Google Play Music? The easiest way to do this would probably be to get your playlists into iTunes or Windows Media Player and use Google's Music Manager to sync your playlists.

Being a Linux user, that's not the best option for me, so I came up with another way. This one's not for the faint of heart, so be sure you've got some time on your hands and lots of patience. Here we go:

  1. Just like my method for exporting playlists from Google Play Music, importing them will require a rooted Android device. The exact method for doing this varies by device, so you'll need to Google it.

  2. This may seem obvious, but first of all you need to make sure all of your music is in Google Play Music. It can take a while, so if you haven't done this you should probably get crackin. These links should help:

  3. Remove any music stored on your Android device's internal memory or SD card. This isn't absolutely necessary, but if you don't do this, any music in the playlists you wish to import that's on your device may not get added to Google Play Music playlists in the cloud.

  4. Get the playlists to import. This step will vary widely depending on where the playlists are coming from. You'll want your data file to contain the following fields:
    1. Playlist name
    2. Artist
    3. Title

    Based on the tools I've used to import data into a Sqlite database, I'd recommend that the data is in one of these formats:
    • A text file where each row is on one line, the fields are separated by a unique character (like the pipe symbol: |), and the fields aren't quoted. For example:

      Folk|Gregory Alan Isakov|Dandelion Wine
      Folk|Gregory Alan Isakov|That Moon Song
      
    • A Microsoft Excel XML file. You don't need Excel to create this; free programs such as LibreOffice Calc work fine.

  5. Make sure all of your tracks and playlists on your Android device are synced with Google's servers. I've already documented this; see step 1 in my post on exporting playlists from Google Play Music.

  6. Optional, but strongly recommended: back up Google Play Music. My app of choice for doing this is Titanium Backup (the free version will suffice, although I think it's worth paying for).

  7. Get the Google Play Music database file (music.db). The instructions for this are also in my post on exporting playlists from Google Play Music (step 2).

  8. Open the music database file. You can use a tool such as Sqliteman, or you can use the sqlite3 command in a terminal, like so:
    sqlite3 /path/to/music.db

  9. Import your playlists into the database file. This is where it gets fun!
    1. Create temporary tables
      create table "temp" ("Playlist Name" text, "Artist" text, "Title" text);
      create table "temp2" ("Playlist Name" text, "Artist" text, "Title" text, "ClientPosition" integer primary key autoincrement);

    2. Import the data. This will vary depending how your playlists are formatted and what program you're using. If you're using Sqliteman:
      • In the menu go to Database --> Import Table Data...
      • Table to Import Into --> select temp
      • File to Import --> Search... --> browse to your playlist file
      • Select an appropriate separator under Column Separators
      • Under Preview, you should see three columns with playlist name, artist, and title
      • Click OK

      If you're using the sqlite3 command:
      • Define the separator between fields. If it's a pipe (|), you can skip this step. For example, to set the separator to a dollar sign:
        sqlite> .separator $
      • Then import the file (things will be easier if the file name doesn't have spaces):
        sqlite> .import /path/to/playlists.txt temp

    3. Before we actually import the playlist entries, this query will show you what's actually going to get imported:
      select temp."playlist name", temp.artist, temp.title from music join temp on music.artist=temp.artist and music.title=temp.title;

    4. If some of your songs don't show up in the above query, then they either aren't in Google Play Music, or the artist or title aren't spelled the same. If you want at this time, upload or rename any missing music. If you decide to fix any missing music, you'll have to start over at the step above where you make sure the music on your Android device is synced with Google's servers.

    5. Copy the data from the temp table to the temp2 table (the temp2 table is my hack to keep the playlist order):
      insert into temp2 ("playlist name", artist, title) select * from temp;

    6. Now, we're finally ready to create the playlists. If you already have playlists in Google Play Music with the same names as the ones you're importing, you can skip this step. Here's the query (the _sync_dirty part is what tells Google Play Music that the data needs to be synced to the cloud):
      insert into lists ("Name", "_sync_dirty") select distinct "Playlist Name", '1' from temp2;

    7. We've created the lists, now we need to import the data into them:
      insert into listitems ("MusicId", "ListId", "ClientPosition", "_sync_dirty") select music.id as musicid, lists.id as listid, clientposition, "1" from music join temp2 on music.artist=temp2.artist and music.title=temp2.title join lists on "playlist name"=lists.name;

    8. Clean up after ourselves:
      drop table temp;
      drop table temp2;

  10. Just to be safe, turn off internet on the Android device (whether it's wifi or data)

  11. On the Android device, kill the Google Play Music app by going to the home screen --> Menu --> Settings --> Application manager --> scroll down and click on Google Play Music --> Force stop

  12. Copy the music.db file you modified back to the device's SD card

  13. Copy the music.db file from the SD card back to /data/data/com.google.android.music/databases

  14. This part can be tricky. Copying music.db back will probably mess up the permissions, which means at this point if you were to open the Google Play Music app, it would probably crash. To fix the permissions, you need to either use the command line or use a file explorer app that's capable of modifying the permissions. For these instructions, I used File Explorer by NextApp with the Root Add-On:
    1. Long-press on one of the other files in the folder, like music.db-journal --> Permissions
    2. Make a note of the Owner and Group
    3. Now long-press on music.db --> Permissions
    4. Click on Owner --> App --> change it to the same owner as the other file you just looked at. You'll see a Google Play Music icon beside the owner, which will confirm you're picking the right one.
    5. Repeat the same thing for the group.
    6. This isn't completely necessary, but you can also uncheck all of the boxes in the Exec column, and uncheck the Global box in the Read column. In the bottom left it should say Octal: 0660.
    7. Click OK --> OK.

  15. Phew, we're almost there! Now open the Play Music app, and go to Playlists. Scroll down and you should see the playlists you imported (if you don't, make sure you're viewing All Music instead of music On Device). Open the playlists, and you should see all the songs you imported.

  16. Lastly, if everything looks good, go ahead and connect your device to the internet again, and follow the step you did above on making sure your music's synced with Google's servers.

  17. To make sure your playlists are on Google's servers, go to music.google.com and your playlists should be there. If they don't show up, don't worry. Give it some time, try syncing from the Play Music app again, and refresh the page. It can take a little bit to sync.

4 comments:

  1. Nice going. I wonder if it's possible to automate this via emulator on Linux?

    Also, "Wow. It's hard to believe that in this modern age, you have to go through that level of pain to get your fucking PLAYLISTS onto a music app."

    This is one of the many ways that Google Music sucks. You'd have to try really hard to suck this badly, right? Well, the only reasonable conclusion I can come to is that they don't want you to be able to pick and choose music in the 'old fashioned' way. Hence removal of the 5 star rating system from Labs, and the making practically impossible to sync playlists. (I've tried the Windows Media Player route, and it's fucking TERRIBLE) So you get to listen to what they recommend, and that's all they want.

    ReplyDelete
    Replies
    1. It's been a while since I wrote this. It looks like these days the easiest way to import/export playlists is probably by using this tool here: https://github.com/soulfx/gmusic-playlist

      Delete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Hi try using musconv, its a tool for copying or transferring your music playlist from one music library to another - Bangelica

    ReplyDelete