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>585</key>
<dict>
<key>Track ID</key><integer>585</integer>
<key>Name</key><string>Hells Bells</string>
<key>Artist</key><string>AC/DC</string>
...
</dict>
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">
<dict>
<key name="Track ID" integer="585"/>
<key name="Name" string="Hells Bells"/>
<key name="Artist" string="AC/DC"/>
...
</dict>
</key>
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" >"$f.new";
mv "$f.new" "$f"
done
scp *.m3u music:~/Music/Playlists
)
|