Coming Up for Air

Syncing Playlists with Android Devices

While I love my Android devices, one thing that has always bugged me is syncing music with them. Sure, there are some apps that claim to be able to do it, but I’ve never found one that will do what it says and be a decent music player at the same time (perhaps someone out there can point me to a good one). For the most part, then, I’ve settled on Banshee (which, as far as I can tell, doesn’t sync, but is a decent player1). Here, then, is my very manual process for syncing music.

The first step is to create a playlist. You can, of course, sync all of your music, which is much easier, but my phone won’t hold all of my music, so I have to be selective. Once I’ve created my playlist, I then export it (Banshee seems to use a real database, so I have to export the .m3u manually), which I put in the root of my music directory. The only part of this post that might be of interest to anyone, is the shell script I run to sync, which looks like this:



if [ -d $device/$folder ]; then
    cp "$1" $device/$folder

while read line; do
        path=${song#*/music_folder/}    # replace music_folder/  by your Music Folder (e.g. /home/foo/MUSIC -- use MUSIC/ instead)

        if [[ ${song:0:1} != "#" ]]; then
                if [ -d $device/$folder ]; then
                        mkdir -p "$device/$folder/$path"
                        if [ ! -e "$device/$folder/$path/" ] ; then
                            echo -e $song
                            cp -r "$song" "$device/$folder/$path/"
                        echo "The destination directory does not exist"
                        echo "Please check the destination directory"
done < "$1"

I found the original script here, and made some minor modifications. You will likely need to modify the values of $device and $folder, but the rest should run as is. It doesn’t remove any music not in the playlist (which I doubt is often desirable), but it will copy anything missing to the device, as well as putting the playlist on the device for consumption by your player of choice there. To run it, you just specify the name of the playlist file and watch it run:

$ syncM3U NewMusic.m3u

It’s very manual, but simple and clean, and it saved me some hacking of my own, so I thought I’d share. Ideally, my music player would do this for me, but I just haven’t found one I like yet, so I get to do it this way, which does have a much higher geek appeal. :P

1 It’s at least good enough that I decided to quit looking. :P

tags: Android bash


Sample quote

Quote source