Adding iTunes+ Support to TiVo

Thursday, June 7th, 2007 @ 9:38 pm | Mac, Programming, TiVo

A little over two years ago, TiVo quietly enabled the ability to stream unprotected AAC to TiVos for use via the Home Media Option. I say quietly, because this feature required you to install lame and didn’t appear to be documented anywhere. At the time, I viewed this as a promising sign that TiVo was starting to make good on it’s then 2-year-old statement that they were looking to add AAC support to the HMO. However, it’s been another 2+ years since that time and not much has changed.

What has changed is that Apple unveiled iTunes+, complete with unprotected AAC files. In theory, these files should “just work” with TiVo’s existing AAC support. Of course, as is true of many things, the transition from theory to reality did not go as planned. As reported by The Apple Blog, iTunes+ still are not playable through HMO.

We come here not to bury TiVo, but to fix it.

On The Apple Blog, the suggested solution to this problem is to use iTunes’ Convert Selection command to convert your files to either MP3 or AAC. I’m not crazy about this, because you either take extra hard drive space storing two copies of each track or you introduce an additional lossy compression into your only copy of each track. The trick is to make TiVo Desktop recognize the “Purchased AAC audio file” type.

For the record, I’m pretty about everything that follows, but there’s always the slim chance that following my instructions could reduce you system to a smoldering pile of rubble, or something slightly less drastic. Make sure you’ve got a backup of everything and proceed at your own risk.

Inspired (heavily) by Dan Benjamin’s Building Ruby, Rails, LightTPD, and MySQL on Tiger, here we go.

What You Need

  1. Mac OS X 10.4 (previous versions might work, but I have no idea).
  2. Developer Tools
  3. TiVo Desktop
  4. Some level of comfort with the Terminal and editing some Java code.

Getting Started

Before doing anything, you need to make sure TiVo Desktop is not running. Open System Preferences and select the TiVo Desktop Preference Pane. If it says “TiVo Desktop On” underneath the TiVo logo, click the Stop button.

To keep things simple, we’re going use one working area for pretty much everything. I suggest creating a folder called tivo in your home folder. To do so, enter the following into a new Terminal window:

mkdir tivo
cd tivo

Keep the Terminal window open so you stay in this folder.

LAME

Not a social commentary on my part, LAME is the tool that TiVo Desktop uses to support AAC files. TiVO Desktop uses LAME to convert AAC files to MP3 files on-the-fly and sends the MP3 file to your TiVo. The AAC file on your hard drive remains unchanged.

You can copy the following lines into your Terminal one at a time. When the current line finished, proceed to the next line.

We’ll end up using the sudo command a few times during this process. One or more times, you may be prompted to enter your password. Do so when asked.

curl -O http://umn.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
tar xvzf lame-3.97.tar.gz
cd lame-3.97
./configure --prefix=/usr/local
make
sudo make install
cd..

If you get an error like this:

checking whether make sets $(MAKE)... no
checking for gcc... no
checking for cc... no
checking for cc... no
checking for cl... no
configure: error: no acceptable C compiler found in $PATH

then you don’t have the Developer Tools installed. You should have a copy on your Tiger CDs/DVDs or you can download a copy from the Apple Developer Connection website.

JAD

JAD is a Java Decompiler. Basically, it lets you get back to the Java source code used to create Java byte code files. The portions of TiVo Desktop we care about are written in Java, so this tool will enable us to make the necessary modifications to support iTunes+ files.

JAD is not a Universal binary — there are separate Intel and PowerPC version. Make sure you download the appropriate version. Also, I have not tested the Intel version. The JAD website indicates that the Intel version is for Mac OS X 10.4.6. I assume that means 10.4.6 or newer, but I can’t be sure.

Intel

curl -O http://www.kpdus.com/jad/macosx86/jadmx158.zip

PowerPC

curl -O http://www.kpdus.com/jad/macosx/jadap158.zip

Once you’ve downloaded jar, you expand the file and make sure jad is configured as an executable.

unzip jar158.zip
chmod a+x jad

TiVoDesktop.jar

TiVoDesktop.jar is contains the Java byte code that we’re going to be modifying. We’re going to copy this into working area before making any changes, extract the byte code from the archive, and decompile the byte code we care about back into a Java source file.

cp /Library/Application\ Support/TiVo/TiVoDesktop.jar .
jar xf TiVoDesktop.jar
./jad -sjava com/tivo/util/SoundConverter.class

Editing SoundConverter.java

The jad command above will create the SoundConverter.java file, which contains the source code for the SoundConverter class. Open this in your favorite text editor and find the method named:

public static boolean isConvertibleToMPEG(String type)

This method pretty short — only 6 lines. The first 2 lines check if a TiVo will natively support the file type. The second 2 lines check if the file type can be converted into a file type a TiVo will support. The last 2 lines indicate that the file type cannot be used with a TiVo.

It’s the second 2 lines that interested us. Specifically, this line (split into 2 lines here for readability):

if(type.equals("AAC audio file") || type.equals("AIFF audio file")
    || type.equals("Apple Lossless audio file") || type.equals("WAV audio file"))

This line sees if the file type can be converted to MP3. We need to add “Purchased AAC audio file” to this list to support iTunes+ files. So, replace the above line with the following (again, 1 line in the source file, 3 lines here for readability):

if(type.equals("AAC audio file") || type.equals("AIFF audio file")
    || type.equals("Apple Lossless audio file") || type.equals("WAV audio file")
    || type.equals("Purchased AAC audio file"))

The only change was adding || type.equals("Purchased AAC audio file") between the last two closing parenthesis.

Updating TiVoDesktop.jar

Once the source code has been edited, we need to update TiVoDesktop.jar. This involves generating the byte code for the SoundConverter class and replacing the old byte code in TiVoDesktop.jar.

javac SoundConverter.java
mv SoundConverter.class com/tivo/util/
jar uf TiVoDesktop.jar com/tivo/util/SoundConverter.class

If you get an error after running the javac command, you’ve made a mistake in your code. You can either try to find your error or you can delete the SoundConverter.java file start back at the jar command under “TiVoDesktop.jar”

Replacing TiVoDesktop.jar

Now it’s time to replace the old TiVoDesktop.jar with our updated copy.

pushd .
cd /Library/Application\ Support/TiVo/
sudo mv TiVoDesktop.jar TiVoDesktop.jar.old
popd
sudo mv TiVoDesktop.jar /Library/Application\ Support/TiVo/

Finishing Up

If you’ve gotten this far, you’re pretty much done. All that’s left is to restart the TiVo Desktop (open the TiVo Desktop Preference Pane and click Start) and start playing your iTunes+ files through your TiVo.

Theoretically (there’s that word again), this should be relatively simple for TiVo to implement. However, development of TiVo Desktop for the Mac has not proceeded at a brisk pace. It wouldn’t surprise me if the next release doesn’t come out until after the release of Leopard (assuming the current TiVo Desktop doesn’t play well with Leopard).

Since I implemented this change, the only issue I’ve seen is occasional when my TiVo is playing back the converted tracks. Since the files are being converted and streamed on demand, the skipping’s probably due to the 5-year-old computer I’m currently riding like a rented mule (the skipping didn’t occur if I left the computer alone while it was streaming). I suspect that those of you with more modern hardware won’t have any problems.

…and no, I wouldn’t suggest using this trick to try and add support for Protected AAC audio files. Something tells me the results might not be pretty.

One Response to “Adding iTunes+ Support to TiVo”

  1. Grant Says:

    Thanks, you’re a rock star for fixing this!