TiVoConnect Hacking

Tonite I set out to make my Tivo use my remotely-hosted Linux webserver as my MP3 server. The eventual goal is to teach WinAmp to play from the same collection of files, so that I can have one copy of my mp3’s in the “cloud” and still get access to them easily on each device.

The first step was to investigate the TiVo Developers info. There I found a tar.gz file with some stuff in it that implemented the funky XML messages TiVo needs to know what’s in the directory tree. I fetched it put it in a directory on my webserver.

Next, I realized I needed a beacon that I could point my TiVo at using “Manually Add Server…”. So I put this script together, using the beacon message doc as guidance, and the helpful beacon captures at KahunaBurger. Here is my beacon program:

#!/usr/bin/perl -w

$| = 1;

$host=`uname -n`;
$hostid=`hostid`;
$plat=`uname -a`;

chomp $host;
chomp $hostid;
chomp $plat;

print "TiVoConnect=1
Machine=$host
Identity=hostid-$hostid
Method=Connected
Platform=$plat
Services=TiVoMediaServer:80/http
";

while (<STDIN>) {
# ignore it
}
exit 0;

I run it with a command like this: tcpserver -d -v `uname -n` 2190 ~/bin/tivo-beacon. You can find tcpserver at the ucspi-tcp page on djb’s site.

Next, you need to arrange for URL’s like http://ip-addr/TiVoConnect?params... to turn into hits on the example.cgi script from the tarball. This turns out to be harder than necessary for two reasons. First, since TiVo only knows the IP address, not the hostname, it can’t fetch from a name-based virtual. Second, a bug in TiVo’s implementation of HTTP redirects makes the name change to lower case.

To get around the no-virtuals problem, I had to put a symlink in the root of the real webserver pointing at my home directory, where my virtuals run from. I have root, so it was no problem.

Next, I renamed “example.cgi” to “index.cgi” and added a local .htaccess file that enabled CGI (“Options +ExecCGI”). Alas, that didn’t work because Apache issues a redirect from http://ip-addr/TiVoConnect?params... to http://ip-addr/TiVoConnect/?params.... Note the trailing slash. That is correct behavior when accessing a directory, and it shouldn’t be a problem. But since TiVo uncapitalizes the contents of the Location header when it follows an HTTP redirect it ends up trying to fetch http://ip-addr/ticoconnect/?params. So, you have to make a symlink in lowercase too.

You also need to edit the first bit of example.cgi and tell it where your photos and/or MP3’s are.

After doing all that (and remembering that your webserver has a firewall, and it needs a hole poked for port 2190), it all just magically works! OK, well not really. It’s working some, but things are seriously flaky at this point still. I’ve just noticed that they don’t seem to be following the discovery spec when they send via TCP, so I’m going to try to copy the thing they are doing and see if maybe things will get better.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *