Exporting iTunes Playlists to Tivo

This is a little thing that’s been bugging me since we got our TiVo a while back, but I never got around to solving it – exporting my music playlists from iTunes to TiVo. TiVo’s jukebox interface is simply horrendous, so playlists are an absolute must, unless you like scrolling through pages of your music collection. iTunes makes matters worse in that it doesn’t allow you to export M3U-formatted playlists, the format TiVo requires.

Sigh. A little shell scripting and awk is all that’s required to resolve this problem in short order. Here’s an awk script called m3u-ify.awk to convert an iTunes playlist (exported as plaintext) to an M3U playlist:


BEGIN {
FS = "\t"
print "#EXTM3U"
}
{
if (match($27, /\.mp3/))
{
time = $8
name = $27
location = $27

# Figure out the location from the absolute location
# that iTunes exports. Note that we remove the '- ' from
# the location, which iTunes seems to add erroneously.
# Using 'sub' is not ideal, but gensub seems flakey in
# my version of gawk, otherwise I'd use the following:
# location = gensub(/D:\\Music\\\(.*\\.*\\[0-9]*\) -\(.*\)\.mp3/, "\\1\\2", "g", location)
sub(/D:\\Music\\/, "", location)
sub(/ - /, " ", location)

# Find the name of the song - this regex is giving
# me problems in Cygwin with gawk, so I coded an
# alternate way to get to the normalized song name
# name = gensub(/D:\\Music\\.*\\.*\\[0-9]* - \(.*\)\.mp3/, "\\1", "g", name)
sub(/D:\\Music\\.*\\.*\\/, "", name)
sub(/\.mp3/, "", name)
sub(/[0-9]* - /, "", name)

print "#EXTINF:"time","name
print location
}
}

Note that my music collection is located in D:\Music (which needs to be stripped out of the file location to create the M3U file) – you will have to alter this script if to the location of your iTunes music folder.

To use the script, you’ll need awk installed on your machine (for those of you using Windows, you might try grabbing a copy of Cygwin) . To convert a playlist to M3U:

  1. Select a playlist in iTunes, export it as a text-formatted playlist (input.txt) to a folder containing the above script
  2. Open a shell prompt, go to the folder where you saved the text-formatted playlist
  3. Run awk -f m3u-ify.awk input.txt > output.m3u

You’ll now have an M3U-formatted version of your playlist. If you really want to be fancy, export all your playlists at once, and then generate a batch shell script to process them all at once by running ls -1 *.txt |sed -e 's/\(.*\)\.txt/awk -f m3u-ify.awk \"\1.txt\" > \"\1.m3u\" /g'>batch.sh. This will generate a shell script called batch.sh that will process all the text playlists in once go.

Note: I point TiVo Desktop to my iTunes folder directly – I’m not sure if this affects file location specified in the M3U or not. Your mileage may vary.

iTunes’ Music Madness

It’s been a bit hectic, what with the final two weeks of the MBA approaching, but somewhere in there I managed to download iTunes for Windows. A millionth of a second after launching the newly-installed application, I proceeded to uninstall WinAmp, saying my goodbye quickly so as not to betray my lack of emotion at its departure from my hard-drive. You know Apple is onto something when not only am I deleting the first application I’ve installed on any new machine for the past five years, but even my mother-in-law is looking at buying an iPod.

Now, I’m not one to advocate or admit to mass copyright piracy via a public medium, so let’s just say that I have a sizable digital music collection and leave it at that. But, needless to say, iTunes makes my music addiction a bit more manageable. I can sort! I can shuffle! I can even track which songs I really like, in case I get smacked in the head and forget! It’s lovely. Other people apparently think so too. While pretending to get some work done in the university library, I fired up iTunes only to be surprised by the number of other computers sharing out their music using the application’s built-in streaming capabilities. As Inspector Gadget said to Penny: Yowza!

The most interesting part about trawling through other people’s iTunes libraries is observing the variety of music to which people listen: Mozart, Pink, AC/DC, Britney Spears, Oscar Peterson, and so on. And that’s on one machine. People are shamelessly mixing and matching musical genres in their playlists with wild abandon – crazy! It’s refreshing to see so much variety in people’s musical tastes, even if some of the combinations are liable to make them as sick as a drink made from Scotch, Vodka, and Gin and served from an unclean toilet bowl. To those musical pioneers who are about to mix Joni Mitchell with a side of AC/DC and some Pavarotti: I salute you!

Apparently, my acceptance for this musical cross-breeding is not shared by all, and the latest Apple-inspired revolution has an ugly name: playlistism. That’s right, we’ve reached the level of social sophistication where judging a person on the basis of race, gender, religion, nationality, and political affiliation is not enough. We’ve pushed the boundary: now we can judge you by your previously-secret addiction to kitschy show tunes! Point and laugh everybody!