May 2007 Archives
May 11, 2007

Convert iTunes playlists to Slimserver m3u playlists

Cool gadgets | XSLT

I own few Slimdevices Squeezeboxes, which provide a great way to listen to your digital music. Through a regular remote control and the VCD screen you can choose the album, song or playlist that you want to listen to.

I rip all my music from CDs and organize and store it in iTunes. (By the way, the reason I never buy music from the iTunes Music Store is that I cannot play the DRM crippled songs on my squeezeboxes.) I then copy all the music to the hard disk of a small machine, which runs slimserver that serves the music to my squeezeboxes.

One thing that kind of bothered me for a long time was that iTunes playlist support for the slimserver software was somewhat broken. So I wrote a small script to convert the iTunes playlists into m3u playlists, the format used by slimserver. Below are the details.

Update (May 21st, 2008): Mike Hudson writes that the latest version of SqueezeCenter can now read iTunes XML, playlists included. However one still needs to change the location of the files within the XML file.

iTunes stores information about your music library into an XML file. Its format is the so-called plist, a rather unusual XML format. Its biggest flaw is that name value pairs are consecutive XML elements, rather than being associated. For example, this is an excerpt from the description of a song:

  <key>Track ID</key><integer>585</integer>
  <key>Name</key><string>Hells Bells</string>

The problem of is that you have to rely on the position of elements to figure out what they mean. An alternative would have been to represent the value as an attribute of the key element or as a child element, if it was a complex structure. Like this:

<key name="585">
    <key name="Track ID" integer="585"/>
    <key name="Name" string="Hells Bells"/>
    <key name="Artist" string="AC/DC"/>

In any case, the format is what it is, so I had to deal with it. I wrote a small XSLT program to extract the playlist information and generate the m3u playlists. It is called iTunes-to-m3u.xsl, and you can run it like this to generate the m3u playlists:

java -jar saxon8.jar ~/Music/iTunes/iTunes\ Music\ Library.xml iTunes-to-m3u.xsl

The XSLT engine used above is Saxon 8, an excellent XSLT 2.0 implementation. You might be able to use other engines too, including 1.0 ones. However if you do that you need to change the xsl:result-document to xsl:document, and make sure the engine support outputting to multiple files.

Depending on your setup, you might need to translate %20 sequences in file names to regular blanks. Since the location of the files on the slimserver box is different than that on my Mac, I also have to translate file paths. The following shell commands do it for me (I have everything packaged nicely in a shell script):

(cd /tmp
mkdir -p playlists
cd playlists
rm -f *.m3u *.new
~/bin/saxon ~/Music/iTunes/iTunes\ Music\ Library.xml ~/src/iTunes-to-m3u.xsl;
for f in *.m3u; do
  sed -e 's/%20/ /g' -e 's%/Volumes/BigDisk/Users%/home%g' <"$f" >"$";
  mv "$" "$f"
scp *.m3u music:~/Music/Playlists
Posted by ovidiu at 09:30 PM | Comments (0) |
May 04, 2007

Interview with Leslie Lamport


Mihai Budiu has an interesting interview with Leslie Lamport, the author of LaTeX among many other things.

I especially liked the part about his thoughts on how people think about and write software programs, using extreme programming, UML or other formal methodologies (I'm not too fond of either of these.)

The best of these methods trick you into thinking. They offer some incentive in the way of tools or screen-flash that sugar coats the bitter pill of having to think about what you’re doing. The worst give you a happy sense of accomplishment and leave you with no more understanding of what your program is supposed to do than you started with. The more a method depends on pictures, the more likely it is to fall in the latter class.

Posted by ovidiu at 01:05 AM | Comments (0) |
Ccol stuff
  Arduino TinyWebServer: part 3 and part 2

More from me
Picture gallery
Copyright © 2002-2011 Ovidiu Predescu.