Parse Tivo’s “Now Playing” list with 2 lines of PHP [+]

This is probably the first of several posts that will deal with this topic.

The new Tivo system software upgrade brings many interesting features to Tivo, the most well-known of which is TivoToGo, which lets you copy the video files to your PC.

However, the software upgrade also includes a web server. This means you can interact with your Tivo via any web browser on any PC. I won’t discuss all the ramifications of this right now, but one notable one is that Tivo can now produce your “Now Playing” list (a list of everything on your Tivo) as either an HTML or XML file.

The XML file is particularly exciting, because XML is very, very easy to parse nowadays. People have already parsed this XML into RSS, and I expect to be doing the same over the next couple of days.

To access your Tivo’s Now Playing list as an XML file, use this URL:
Just change the IP to the address of your Tivo, then login using the username tivo and your Media Access Key as your password.

Some of the scripts other people have released to parse this file are quite elaborate (and cool), but I wanted to demonstrate how easy it is to parse the Now Playing list into a simple HTML stream that could be easily included on any website. This took me about 10 mins to write, and it isn’t very elegant.

Here you go:

function converttivodate($format, $input){
        //borrowed from A. Cassidy Napoli's Tivo_XML script
        return date($format, hexdec($input));}

$file = "nowplaying.xml";
$sxe = simplexml_load_file($file);
foreach($sxe->Item as $item) {
        $details = $item->Details;
        echo "$details->Title: $details->EpisodeTitle<br/> 
	$details->Description (" .
	converttivodate('n/d/y G:i',$details->CaptureDate) . 
	", $details->SourceStation, $details->SourceChannel)</p>\n"; } 

That’s about 6 lines of PHP, and it’s easy to see the same (or even more) could probably be accomplished in about 2 lines. (See the update below.)

Just use include() or the Curl extensions to include the file on your site, and you’re all set. This code snippet requires PHP5’s SimpleXML support.

It produces something like this:

Law & Order: Merger
A scandal involving two wealthy families threatens McCoy and Carmichael’s chances of a conviction in the murder of a drug-addicted girl of 15. (1/26/05 15:59, TNT, 3-0)

Seinfeld: The Doorman
A doorman (Larry Miller) tries to cause trouble for Jerry; Kramer develops a male undergarment. (1/26/05 15:29, TBS, 22-0)

Malcolm in the Middle: Reese’s Apartment
Francis is determined to show his parents why they should not have kicked Reese out; Malcolm helps a football player writer a college essay. (1/26/05 14:59, WWOR, 9-0)

Leave a Reply

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