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:

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.


On occasion I pretend to be a guitarist. Honing my solo improvisational skills is a difficult task, especially given that half the time I’m practicing on my own without the benefit of a band to provide the backing track. Practicing scales or jamming over top of CDs is one approach, but there’s only so much you can do. Sometimes I use Transcribe! to loop sections of CDs without lead guitar, but that can get really repetitive and limit the usefulness of the exercise.

Recently, it occurred to me that what I really want is the equivalent of karaoke tracks, but for guitar. Imagine if you could buy electronic versions of a song with one of the instruments removed from the track. Guitarists could mute the guitar track; drummers could mute the drum track; bass players could mute the bass track. Musicians could go to a web site, pick which instrument they wanted removed from the master recording, and purchase and download the result in GarageBand format.

Sounds like a nice way for the record industry to pick up another bunch of cash from its massive back catalog. Add in performance rights and high-end versions of the tracks that allow the performer to tweak the mix themselves to create a “professional” version for working solo musicians. Of course, longer term, I expect artists will shortcut this whole process and release their source tracks for free directly to the public as a way of encouraging remixes (just like Trent Reznor did with his recent album).

Take it one step further, and you could totally transform the idea of karaoke clubs. Instead of just having karaoke where people get up and sing, you could have karaoke nights where individual musicians could play without needing to assemble a whole band.