Coming Up for Air

Syncing Playlists with Android Devices

Monday, April 29, 2013 |

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

device=/media/jdlee/SD
folder=Music

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

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

        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/"
                        fi
                else
                        echo "The destination directory does not exist"
                        echo "Please check the destination directory"
                        exit
                fi
        fi
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:

1
$ 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

Search

    Quotes

    Sample quote

    Quote source

    About

    My name is Jason Lee. I am a software developer living in the middle of Oklahoma. I’ve been a professional developer since 1997, using a variety of languages, including Java, Javascript, PHP, Python, Delphi, and even a bit of C#. I currently work for Red Hat on the WildFly/EAP team, where, among other things, I maintain integrations for some MicroProfile specs, OpenTelemetry, Micrometer, Jakarta Faces, and Bean Validation. (Full resume here. LinkedIn profile)

    I am the president of the Oklahoma City JUG, and an occasional speaker at the JUG and a variety of technical conferences.

    On the personal side, I’m active in my church, and enjoy bass guitar, running, fishing, and a variety of martial arts. I’m also married to a beautiful woman, and have two boys, who, thankfully, look like their mother.

    My Links

    Publications