XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

Hacking the XML in Your TiVo
by Bob DuCharme | Pages: 1, 2, 3

Let's review the steps by looking at the Linux shell script that drives it. (To run it yourself, first substitute your appropriate values for your-TiVoIP-here and your-MAK-here in the shell script. This zip file stores all the scripts and stylesheets used to make this happen. It includes Windows batch file equivalents of the tivoroll.sh and nowplaying.sh files.)

#! /bin/sh

export TiVoIP=your-TiVoIP-here
export MAK=your-MAK-here

# pull the TiVoRoll XML down from the TiVo
wget --no-check-certificate --http-user=tivo --http-password=$MAK \
-O /tmp/tivoroll.xml "https://$TiVoIP/TiVoConnect?Command=QueryContainer\
&Container=%2FNowPlaying&Recurse=No"

# Convert it to HTML markup
xsltproc -o /tmp/tivoroll.html tivoroll2p.xsl /tmp/tivoroll.xml

# FTP the result to a public web server
ftp -n snee.com < tivoroll.l.ftp

The wget utility pulls down the XML we want, the libxslt XSLT processor xsltproc creates HTML from the XML, and ftp uses a script to automate the process of putting the HTML into the right directory on the snee.com server where my weblog resides.

My application that creates an Atom feed of the Now Playing list of saved episodes is almost identical to the one that creates a TiVoRoll for my weblog. The driver shell script passes a Recurse=Yes version of the URL to wget to get the details about the stored episodes, then calls xsltproc with an XSLT stylesheet that creates an Atom 1.0 file, and it finishes by using an FTP script that puts the result of the XSLT pass into a different directory on the web server (http://www.snee.com/rss/nowplaying.atom, in case you're interested in seeing what's on our TiVo). A cron job on my home Linux box runs both scripts before I get up each morning.

Querying the TiVo Desktop

The TiVo Desktop is a Windows program that, when run on your home network, lets you use your TiVo to display pictures and play music on your TV that it retrieves from the computer running the TiVo Desktop. Computers on your network can talk to the TiVo Desktop using URLs like those shown above to find out what pictures and music are available.

Because you'll be sending your queries to the Windows machine and not to the TiVo, you must first find out its IP address. The ipconfig command-line utility that comes with Windows shows you this and related information. For mine, it was 192.168.2.102, so the following URL retrieved XML that listed the high-level containers:

http://192.168.2.102:8080/TiVoConnect?Command=QueryContainer

(Note that the URL scheme prefix is http and not https and that a port number of 8080 is included in the URL.) Here is the XML that it retrieved:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<TiVoContainer>
  <Details>
    <Title>BLACKDELL</Title>
    <ContentType>x-container/tivo-server</ContentType>
    <SourceFormat>x-container/folder</SourceFormat>
    <TotalItems>2</TotalItems>
  </Details>

  <Item>
    <Details>
      <Title>Bob's Music on BLACKDELL</Title>
      <ContentType>x-container/tivo-music</ContentType>
      <SourceFormat>x-container/folder</SourceFormat>
      <LastChangeDate>0x43BB4121</LastChangeDate>

    </Details>
    <Links>
      <Content>
        <Url>/TiVoConnect?Command=QueryContainer&Container=%2FTivoMusic</Url>
        <ContentType>x-container/tivo-music</ContentType>
      </Content>
    </Links>

  </Item>
  <Item>
    <Details>
      <Title>Bob's Photos on BLACKDELL</Title>
      <ContentType>x-container/tivo-photos</ContentType>
      <SourceFormat>x-container/folder</SourceFormat>
      <LastChangeDate>0x43D40340</LastChangeDate>

    </Details>
    <Links>
      <Content>
        <Url>/TiVoConnect?Command=QueryContainer&Container=%2FTivoPhotos</Url>
        <ContentType>x-container/tivo-photos</ContentType>
      </Content>
    </Links>

  </Item>
  <ItemStart>0</ItemStart>
  <ItemCount>2</ItemCount>
</TiVoContainer>
<!-- Copyright (c) 2003-2005 TiVo Inc. All rights reserved.-->

I had given that computer the name of blackdell to distinguish it from our older, off-white Dell that is now running Ubuntu Linux, which is the machine I used to test these queries. Because I had shared the My Music and My Photos folders from my "Bob" account on the blackdell computer, the two containers listed by the URL above had titles of "Bob's Music on BLACKDELL" and "Bob's Photos on BLACKDELL." Below these titles you can see relative URLs that point to the contents of these containers. The following URL (split into two lines here) showed that the TivoPhotos container had containers named My Photos.lnk and My Pictures.lnk:

http://192.168.2.102:8080/TiVoConnect?Command=QueryContainer
&Container=%2FTivoPhotos

Those have their own URLs too, and using those and the same technique you can drill down to your actual listings of photos. These image files will have URLs that let you retrieve them; for example, the following URL retrieved I102_0248.JPG and displayed it on the Ubuntu machine's screen:

http://192.168.2.102:8080/TiVoConnect/TivoPhotos/IMy%20Pictures.lnk
/F326/F466/I102_0248.JPG

The API documention lists additional parameters to control the display of the image. For example, this URL displays the I102_0248.JPG image rotated 90 degrees:

http://192.168.2.102:8080/TiVoConnect/TivoPhotos/IMy%20Pictures.lnk
/F326/F466/I102_0248.JPG?Rotation=90

The ability to see directory listings and to retrieve JPEG and MP3 files from one home network machine to another is not in itself exciting. It's ironic that the documentation explaining how do to this with the TiVo Home Media Option API holds the key to querying the TiVo box itself, which is much more interesting. The fact that we can do this with a REST API makes it simple to play with, and makes it that much easier to script the integration of your personal TiVo data into the other metadata of your life.



1 to 4 of 4
  1. How do you get the MAK?
    2007-02-27 19:31:10 BigGrizzlyBear
  2. Updated the Windows scripts.
    2006-03-02 17:22:29 raianoat
  3. Is this possible from VB.Net without wget?
    2006-03-01 01:18:15 gpstefansson
  4. logging in
    2006-02-16 11:27:43 robertfantini
1 to 4 of 4