# Trying to get my Tivo to Tweet



## bluebeetle (Jan 22, 2002)

I've been trying to get my Tivo to tweet like a couple other people have:

http://www.mrbalky.com/2009/02/24/follow-my-tivo-on-twitter/

http://www.zatznotfunny.com/2009-02/yup-this-tivo-tweets/

I've been trying the first method by using curl to generate a nowplaying.xml The command looks like this:

curl.exe --anyauth --insecure --user tivo:******** --output tivo_nowplaying.xml "https://***.***.*.***/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes&ItemCount=50"

The problem is that the .xml file it gives me simply has this in it:

*Resource Not Found*

What's weird is I can go to the https:// address in my browser and pull it up fine. Anyone have any ideas? Or know an easier way to do this? Thanks!


----------



## dlfl (Jul 6, 2006)

Tweeting TiVo's ? God help us!


----------



## Allanon (Nov 2, 2005)

Try using wget instead.


```
wget --no-check-certificate --http-user=tivo --http-password=your-MAK-here -O nowplaying.xml "https://***.***.*.***/TiVoConnect?Command=QueryContainer&Container=&#37;2FNowPlaying&Recurse=Yes"
```
For more info try this site:

http://www.xml.com/lpt/a/1644


----------



## Dan203 (Apr 17, 2000)

I'm guessing the --insecure flag is the problem. I have never used curl.exe, but I do know that the TiVo requires a secure https connection to present you with the now playing XML. Perhaps you should read up on the parameters available to curl.exe and see if you can figure out how to get a secure connection and it will probably work.

Dan


----------



## gonzotek (Sep 24, 2004)

My ubuntu distribution of curl correctly downloaded the nowplaying xml.

```
curl --anyauth --insecure --user tivo:0123456789 --output tivo_nowplaying.xml "https://mytivodvr/TiVoConnect?Command=QueryContainer&Container=&#37;2FNowPlaying&Recurse=Yes&ItemCount=50"
```
Could it be the win32 build you're using?

/edit: Now that I think about it, does your build of curl have openssl enabled? It's been a while since I used a windows version of curl, and I seem to remember that being a concern.


----------



## bluebeetle (Jan 22, 2002)

I did have to install OpenSSL for the curl command to get that far.

When I run wget I get basically the same thing:

'XML Parsing Error: no element found'

I can try another version of curl to see if that would make a difference. Also, I'm trying to run this on a Windows 2003 server if that changes things at all.


----------



## gonzotek (Sep 24, 2004)

bluebeetle said:


> I did have to install OpenSSL for the curl command to get that far.
> 
> When I run wget I get basically the same thing:
> 
> ...


It sounds like it is connecting to the tivo, but not to the correct URL. The "
*Resource Not Found*
" message is the exact error a tivo returns if you go to a non-existent url, such as https://mytivodvr/noTplaying/index.html

Can you try using curl to pull the plain (unsecure) index page http://mytivodvr/index.html , just to verify that the address is correct and the tivo is responding as expected. You should get a complete html file that has a brief message from tivo about Home Networking features.


----------



## bluebeetle (Jan 22, 2002)

This is what I get when trying that:

XML Parsing Error: not well-formed
Location: file:///C:/Documents%20and%20Settings/Administrator/Desktop/tivo_nowplaying.xml
Line Number 11, Column 4:<![if !IE]>

<![endif]>
---^


----------



## gonzotek (Sep 24, 2004)

bluebeetle said:


> This is what I get when trying that:
> 
> XML Parsing Error: not well-formed
> Location: file:///C:/Documents%20and%20Settings/Administrator/Desktop/tivo_nowplaying.xml
> ...




Well, there should have been more than that, but that line does come from the index.html page I expected you to get. Out of curiosity, what were you trying to view the file with? If you change the extension to html, can you get the whole webpage?

Anyway, we've established you can connect to the tivo via curl, that the tivo is responding on the unsecured port 80 http interface, and is apparently responding on the secure port 443 https interface.

I wonder if the special characters in the url are giving the windows command parser a problem. You've already got it quoted, which I'd expect would be all that would be needed, but still.

For instance, if I curl to
https://mytivodvr/TiVoConnect?


I just get

```
<h2>Resource Not Found</h2>
```

But if I curl to
https://mytivodvr/TiVoConnect?Command=QueryContainer

I get something close to the following(I tidied up the formatting a bit and changed the dvr name):

```
<?xml version="1.0" encoding="utf-8"?>
<TiVoContainer xmlns="http://www.tivo.com/developer/calypso-protocol-1.6/">
<Details>
<ContentType>x-tivo-container/tivo-server</ContentType>
<SourceFormat>x-tivo-container/tivo-dvr</SourceFormat>
<Title>mytivodvr</Title>
<TotalItems>1</TotalItems>
</Details>
<ItemStart>0</ItemStart>
<ItemCount>1</ItemCount>
<Item>
<Details>
<ContentType>x-tivo-container/tivo-videos</ContentType>
<SourceFormat>x-tivo-container/tivo-dvr</SourceFormat>
<Title>mytivodvr</Title>
<UniqueId>mytivodvr</UniqueId>
</Details>
<Links>
<Content>
<Url>https://mytivodvr:443/TiVoConnect?Command=QueryContainer&amp;Container=%2FNowPlaying</Url>
<ContentType>x-tivo-container/tivo-videos</ContentType>
</Content>
</Links>
</Item>
</TiVoContainer>
```

I won't have a chance to test anything until tomorrow (night perhaps). But try looking for any hints on the web regarding url escaping and the windows command interpreter. I don't think it's the tivo, your network, or curl (specifically) that's throwing you the curveball here. You could also try writing your command into a batch file(it'll also make it easier to go back and edit and try different things this way).


----------



## bluebeetle (Jan 22, 2002)

I tried opening the XML in both Firefox and IE. If I change it to .htm it still says 'Resource Not Found'.

I did try changing my curl command to this: https://***.*.***.***/TiVoConnect?Command=QueryContainer

And I get the same thing you did:

<?xml version="1.0" encoding="utf-8" ?> 
- <TiVoContainer xmlns="http://www.tivo.com/developer/calypso-protocol-1.6/">
- 
<ContentType>x-tivo-container/tivo-server</ContentType> 
<SourceFormat>x-tivo-container/tivo-dvr</SourceFormat> 
Tivo HD 
<TotalItems>1</TotalItems>

<ItemStart>0</ItemStart> 
<ItemCount>1</ItemCount> 
- <Item>
- 
<ContentType>x-tivo-container/tivo-videos</ContentType> 
<SourceFormat>x-tivo-container/tivo-dvr</SourceFormat> 
Tivo HD 
<UniqueId>Tivo HD</UniqueId>

- <Links>
- <Content>
https://***.***.*.***:443/TiVoConnect?Command=QueryContainer&Container=/NowPlaying 
<ContentType>x-tivo-container/tivo-videos</ContentType> 
</Content>
</Links>
</Item>
</TiVoContainer>


----------



## gonzotek (Sep 24, 2004)

bluebeetle said:


> I tried opening the XML in both Firefox and IE. If I change it to .htm it still says 'Resource Not Found'.
> 
> I did try changing my curl command to this: https://***.*.***.***/TiVoConnect?Command=QueryContainer
> 
> ...


Gotta love Windows. OK, I think I have this sorted. I'm attaching a batch file that has correctly downloaded 10 items from my NPL with curl, on Windows. The problem was with the windows command interpreter parsing the %2F. But, for me at least, it would only give a Resource Not Found error when I ran the command (with %2F) from a batch file. It wouldn't happen if I pasted the code directly into the command line. Replacing %2F with the regular forward slash: */* had it working in both the batch and command line. On my Ubuntu machine at home, %2F just worked.

So, try the batch file. You'll have to edit it with your mak and dvr address, and also remove the .txt extension to make it runnable. Don't use notepad for editing. If you don't have a good text editor, I like and suggest crimson editor, it's very useful and open source. You can get it here: http://sourceforge.net/projects/emeraldeditor/ . Don't be confused by the two project names, Emerald Editor is an incomplete rewrite of Crimson Editor and Crimson is still the recommended program.


----------



## bluebeetle (Jan 22, 2002)

Holy crap... that worked! You're awesome! Thanks for helping me with that. Now to see if I can get the other steps to work. Hopefully they won't cause me as much trouble.


----------



## bluebeetle (Jan 22, 2002)

Okay, now I seem to be having trouble running this from the command line. Here's what my batch file looks like:

"C:\Program Files\PHP\php.exe" php -f c:\tivotweet\tivotweet.php twitteruser twitterpass

When I try and fun that though I get this message:

Could not open input file: php

I'm currently running this version of PHP:

PHP 5.3.0 (cli) (built: Jun 29 2009 21:44:56)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

Any ideas?


----------



## bluebeetle (Jan 22, 2002)

Any ideas why I'm not able to open the PHP file?


----------



## gonzotek (Sep 24, 2004)

bluebeetle said:


> Any ideas why I'm not able to open the PHP file?


Try this:
"C:\Program Files\PHP\php.exe" c:\tivotweet\tivotweet.php twitteruser twitterpass

I've been playing with this script in my (very limited) spare time. I haven't had the chance to see what's happening in the code yet, but at least for me, it keeps posting old recordings over and over. I had sixty tweets go out in roughly a minute. When I have the time, I'll see what's going on (I may be doing something wrong, or the script may be broken in some simple way).


----------



## bluebeetle (Jan 22, 2002)

I was able to get by the PHP error by using this code:

curl.exe --anyauth --insecure --user tivo:MAK --output nowplaying.xml --url "https://***.***.*.***/TiVoConnect?Command=QueryContainer&Container=/NowPlaying&Recurse=Yes&ItemCount=50"


"C:\Program Files\php\php.exe" -c "C:\Program Files\php\php.ini" -f c:\tivotweet\tivotweet.php twitteruser twitterpass

But when I run it I get this message: "0 recordings in progress"

When I've tested it I've made sure that the Tivo was recording something. So you've gotten farther then I have... I can't mine to post even old recordings. Any ideas?


----------



## gonzotek (Sep 24, 2004)

bluebeetle said:


> I was able to get by the PHP error by using this code:
> 
> curl.exe --anyauth --insecure --user tivo:MAK --output nowplaying.xml --url "https://***.***.*.***/TiVoConnect?Command=QueryContainer&Container=/NowPlaying&Recurse=Yes&ItemCount=50"
> 
> ...


The tweettivo.php file, by default, looks for tivo_nowplaying.xml and the curl command you just posted outputs to nowplaying.xml. You can do any of the following:

1) change the curl command (e.g. ... --output tivo_nowplaying.xml ...)

2) pass nowplaying.xml to tivotweet.php as the third argument(e.g. "C:\Program Files\php\php.exe" -c "C:\Program Files\php\php.ini" -f c:\tivotweet\tivotweet.php twitteruser twitterpass nowplaying.xml)

3) Modify the tweettivo.php to look for a different default filename.

Changing the curl command is probably the best option. I still haven't had the chance to really grok the code in tweettivo.php, and while changing the expected input filename shouldn't be a problem, I don't like to start messing with other people's code until I can really understand it.


----------



## bluebeetle (Jan 22, 2002)

I did change everything so it was using nowplaying.xml.

I think the problem might be in the first part of the code:

<?
require_once( 'class_tivo_xml.php' );

if ( $argc < 3 )
{
echo 'USAGE: '.$argv[0].": BlueBeetleTivo ***** [BlueBeetleTivo [C:\tivotweet\nowplaying.xml [C:\tivotweet\oldTivoData.php [<no tweet>]]]]\n";
exit( 1 );
}

$mastersName = 'BlueBeetleTivo';
$inputFile = dirname($_SERVER['PHP_SELF']).'/nowplaying.xml';
$oldDataFile = dirname($_SERVER['PHP_SELF']).'/oldTivoData.php';

$twitterUser=$argv[1];
$twitterPW=$argv[2];

I was a little unsure about which values at the top to change. Does it look alright to you?


----------



## magnus (Nov 12, 2004)

How much tweet would a Tivo tweet if a Tivo could tweet on twitter?


----------



## gonzotek (Sep 24, 2004)

bluebeetle said:


> I did change everything so it was using nowplaying.xml.
> 
> I think the problem might be in the first part of the code:
> 
> ...


No, that USAGE line shouldn't be modified. I would start with a fresh copy of the tweettivo.php file downloaded from Mr. Balky's website. Then run it like so:

php tivotweet.php twitteruser twitterpass INPUT_FILE

From your posts, this is as close to exactly what you should run as I can guess:
"C:\Program Files\PHP\php.exe" c:\tivotweet\tivotweet.php BlueBeetleTivo twitterpass nowplaying.xml

I'm using the same command with my twitter credentials and it is connecting and tweeting (too much in fact, but that's another issue altogether).


----------



## bluebeetle (Jan 22, 2002)

Well, I started with a fresh tweettivo.php file and change the batch file to match your descriptiong below. However it's still saying 0 recordings in progress. And it's still not tweeting for some reason.

Should it be sending a tweet even if there aren't any recording currently in progress? So I guess I'm having two issues... 1) I can't seem to get it to tweet period. 2) It's not showing any recordings.

Here is some code from the nowplaying.xml:


```
<?xml version="1.0" encoding="utf-8" ?> 
- <TiVoContainer xmlns="http://www.tivo.com/developer/calypso-protocol-1.6/">
- <Details>
  <ContentType>x-tivo-container/tivo-videos</ContentType> 
  <SourceFormat>x-tivo-container/tivo-dvr</SourceFormat> 
  <Title>Now Playing</Title> 
  <LastChangeDate>0x4A957820</LastChangeDate> 
  <TotalItems>94</TotalItems> 
  <UniqueId>/NowPlaying</UniqueId> 
  </Details>
  <SortOrder>Type,CaptureDate</SortOrder> 
  <GlobalSort>Yes</GlobalSort> 
  <ItemStart>0</ItemStart> 
  <ItemCount>20</ItemCount> 
- <Item>
- <Details>
  <ContentType>video/x-tivo-raw-tts</ContentType> 
  <SourceFormat>video/x-tivo-raw-tts</SourceFormat> 
  <Title>Star Trek: Enterprise</Title> 
  <SourceSize>1390411776</SourceSize> 
  <Duration>0</Duration> 
  <CaptureDate>0x4A957820</CaptureDate> 
  <EpisodeTitle>Bounty</EpisodeTitle> 
  <Description>T'Pol goes through a cycle during which she must mate or die; a bounty hunter kidnaps Archer to return him to the Klingons for punishment. Copyright Tribune Media Services, Inc.</Description> 
  <SourceChannel>701</SourceChannel> 
  <SourceStation>ALTHDNET</SourceStation> 
  <InProgress>Yes</InProgress> 
  <HighDefinition>No</HighDefinition> 
  <ProgramId>EP4465830052</ProgramId> 
  <SeriesId>SH446583</SeriesId> 
  <EpisodeNumber>51</EpisodeNumber> 
  <ByteOffset>0</ByteOffset> 
  <TvRating>5</TvRating> 
  </Details>
- <Links>
```
Anything else you can think of I should check or change? How does it determine when something is currently being recorded? I would think it's not seeing that correctly for some reason.


----------



## bluebeetle (Jan 22, 2002)

I've made progress! I can now get it to tweet, but when it did it sent this as it's tweet (http://www.twitter.com/BlueBeetleTivo):

"$tweetTxt"

Also, I'm getting these messages from the command line:


```
Warning: include(c:\tivotweetc:\tivotweet\oldTiVoData.php): failed to open strea
m: Invalid argument in C:\tivotweet\tivotweet.php on line 33

Warning: include(): Failed opening 'c:\tivotweetc:\tivotweet\oldTiVoData.php' fo
r inclusion (include_path='.;C:\php5\pear') in C:\tivotweet\tivotweet.php on lin
e 33
0 recordings in progress

Warning: fopen(c:\tivotweetc:\tivotweet\oldTiVoData.php): failed to open stream:
 Invalid argument in C:\tivotweet\tivotweet.php on line 88
can't open old data file
```


----------



## MrBalky (Sep 14, 2005)

Michael,

I have to say I was startled to see a link to my hack on the forums here...

Checking your tivo's twitter page, it looks like you never got this working, but if you're still interested in trying to get it going, I can explain that error you're getting. On line 33, the PHP script is trying to load up the now playing state from the last time the script ran. By default it stores that info in the file "oldTiVoData.php" in the same directory where the script lives.

Now possibly you've modified the PHP to do something different (and I may have modified it since you last downloaded it), but on my current version, on line 12 it's building the full path name of the previous state file (oldTiVoData.php), and in your case, for some reason, you're getting the directory multiple times.

My original version of tweettivo.php accepts all parameters on the command line as well. Maybe you could try changing you command line to put all the options on it. Does this code still exist in my original php script?:

```
if ( $argc > 3 )
  $mastersName = $argv[3];
if ( $argc > 4 )
  $inputFile = $argv[4];
if ( $argc > 5 )
  $oldDataFile = $argv[5];
if ( $argc > 6 )
  $noTweet = $argv[6];
```
If so, try this command line:

```
"C:\Program Files\php\php.exe" -c "C:\Program Files\php\php.ini" -f c:\tivotweet\tivotweet.php BlueBeetleTivo twitterpass CeruleanScarab "c:\tivotweet\tivo_nowplaying.xml" "c:\tivotweet\oldTiVoData.php" TRUE
```
It makes the command line crazy long, but should avoid the problem with your PHP installation's PHP_SELF variable. The parameters to tivotweet.php, in order:

Your TiVo's twitter user name
Your TiVo's twitter password
Your twitter user name (An experiment to see if the tivo could tweet "MrBalky just started watching blah". Didn't work.)
The file downloaded from the tivo by curl (now_playing.xml)
The file containing the last state of the now playing list (oldTiVoData.php)
TRUE or FALSE. If false, no actual tweet would be sent; this was for testing.

HTH. If you've given up on it long ago, sorry to dig it up again!

I actually stumbled on this looking to see if there was a way to get at the TiVo's to do list via a similar XML mechanism, so if anybody knows if it's available, I'd love to know too.


----------



## bluebeetle (Jan 22, 2002)

Hey, thanks for the post! I'd kind of put it on the back burner and always meant to come back to it. I've modified the script so it now looks like this:


```
curl.exe --anyauth --insecure --user tivo:******* --output nowplaying.xml --url "https://192.168.1.104/TiVoConnect?Command=QueryContainer&Container=/NowPlaying&Recurse=Yes&ItemCount=20"


"C:\Program Files\php\php.exe" -c "C:\Program Files\PHP\php.ini" -f c:\tivotweet\tivotweet.php BlueBeetleTivo ******* "c:\tivotweet\tivo_nowplaying.xml" "c:\tivotweet\oldTiVoData.php"
```
The problem looks like now that when I run the script it says "0 recordings in progress." Even though there are currently two happening right now. Any ideas why it wouldn't be picking up the recordings?


----------



## MrBalky (Sep 14, 2005)

Was it recording something you specifically requested or a tivo suggestion? IIRC, the XML nowplaying list always has your items at the top and tivo suggestions at the bottom. The URL you're requesting from the tivo is limiting the number of items to 20 (ItemCount=20 in the query string). If you're like me, there are always more than 20 programs vying for my attention.

So the first thing I would try is to request more program info (like 50 or something) and see what happens. If you get the same kind of result, post up the contents of your now_playing.xml file. (If you don't want to post it in public, you could always PM it to me.)

Mine tweet tivo script is still working fine, but maybe you're getting some different XML schema from your device.


----------



## bluebeetle (Jan 22, 2002)

It was recording something that I told it to record. I changed it to request 100 items and it's still doing the same thing. Here is a copy of my nowplaying.xml:


```
<?xml version="1.0" encoding="utf-8" ?> 
- <TiVoContainer xmlns="http://www.tivo.com/developer/calypso-protocol-1.6/">
- <Details>
  <ContentType>x-tivo-container/tivo-videos</ContentType> 
  <SourceFormat>x-tivo-container/tivo-dvr</SourceFormat> 
  <Title>Now Playing</Title> 
  <LastChangeDate>0x4B7C7154</LastChangeDate> 
  <TotalItems>88</TotalItems> 
  <UniqueId>/NowPlaying</UniqueId> 
  </Details>
  <SortOrder>Type,CaptureDate</SortOrder> 
  <GlobalSort>Yes</GlobalSort> 
  <ItemStart>0</ItemStart> 
  <ItemCount>88</ItemCount> 
- <Item>
- <Details>
  <ContentType>video/x-tivo-raw-tts</ContentType> 
  <SourceFormat>video/x-tivo-raw-tts</SourceFormat> 
  <Title>Pokemon: DP Galactic Battle</Title> 
  <SourceSize>3221225472</SourceSize> 
  <Duration>2997000</Duration> 
  <CaptureDate>0x4B7C6DE8</CaptureDate> 
  <EpisodeTitle>Three Sides to Every Story</EpisodeTitle> 
  <SourceChannel>77</SourceChannel> 
  <SourceStation>TOONP</SourceStation> 
  <InProgress>Yes</InProgress> 
  <HighDefinition>No</HighDefinition> 
  <ProgramId>EP011524230032</ProgramId> 
  <SeriesId>SH01152423</SeriesId> 
  <EpisodeNumber>1232</EpisodeNumber> 
  <ByteOffset>0</ByteOffset> 
  <TvRating>1</TvRating> 
  </Details>
- <Links>
- <Content>
  <Url>http://192.168.1.104:80/download/Pokemon%20DP%20Galactic%20Battle.TiVo?Container=%2FNowPlaying&id=2445521</Url> 
  <ContentType>video/x-tivo-raw-tts</ContentType> 
  <Available>No</Available> 
  </Content>
- <CustomIcon>
  <Url>urn:tivo:image:in-progress-recording</Url> 
  <ContentType>image/*</ContentType> 
  <AcceptsParams>No</AcceptsParams> 
  </CustomIcon>
- <TiVoVideoDetails>
  <Url>https://192.168.1.104:443/TiVoVideoDetails?id=2445521</Url> 
  <ContentType>text/xml</ContentType> 
  <AcceptsParams>No</AcceptsParams> 
  </TiVoVideoDetails>
  </Links>
  </Item>
- <Item>
```



MrBalky said:


> Was it recording something you specifically requested or a tivo suggestion? IIRC, the XML nowplaying list always has your items at the top and tivo suggestions at the bottom. The URL you're requesting from the tivo is limiting the number of items to 20 (ItemCount=20 in the query string). If you're like me, there are always more than 20 programs vying for my attention.
> 
> So the first thing I would try is to request more program info (like 50 or something) and see what happens. If you get the same kind of result, post up the contents of your now_playing.xml file. (If you don't want to post it in public, you could always PM it to me.)
> 
> Mine tweet tivo script is still working fine, but maybe you're getting some different XML schema from your device.


----------



## MrBalky (Sep 14, 2005)

Is that all that was in your now playing XML file? There should have been 88 <item> nodes in the XML.

Still, that first node is the program that was being recorded (the customicon-url node contains "urn:tivo:image:in-progress-recording"), so that will be enough for me to work with.

The script output is still "0 recordings in progress"?

-- edit --
Yeah, I can repro this behavior. Don't really know what the problem is; I'll have to do some more digging. I can't explain why it's still working fine for me.


----------



## bluebeetle (Jan 22, 2002)

There was more to the XML file I just included the first part.

Perhaps I could try your files and see if those make a difference?


----------



## MrBalky (Sep 14, 2005)

No need. I can repro this. I can't promise a timely fix, though. Got a few irons in the fire...


----------



## bluebeetle (Jan 22, 2002)

I understand, thanks! I appreciate you looking at it. 



MrBalky said:


> No need. I can repro this. I can't promise a timely fix, though. Got a few irons in the fire...


----------



## MrBalky (Sep 14, 2005)

Trying to figure out why it wasn't working, I was looking through the class_tivo_xml file, but realized it would take more work to fully understand the failure than to just rewrite it. (I didn't write it, it's pretty old code, and there are easier ways to parse XML in PHP these days.)

So start by downloading http://www.mrbalky.com/wp-content/uploads/tweettivo/parse_tivo_xml.php.txt and rename it by taking the .txt off the end.

Then test it on your xml file thusly:

```
"C:\Program Files\php\php.exe" -c "C:\Program Files\PHP\php.ini" -f "c:\tivotweet\parse_tivo_xml.php" "c:\tivotweet\tivo_nowplaying.xml"
```
It should dump all the program info it parsed. You are specifically looking for the "customicon" value of "urn:tivo:image:in-progress-recording", something like this:

```
[8] => Array
   (
       [title] => XXI Winter Olympics
       [sourcesize] => 20950548480
       [duration] => 14392000
       [capturedate] => 0x4B7CEC78
       [description] => From Vancouver, B.C. Snowboarding: men's halfpipe semifinal, Gold Medal final; speed skating: men's 1000m Gold Medal final; short track: men's 5000m relay semifinal, 1000m; skiing: women's downhill Gold Medal final. Copyright Tribune Media Services, Inc.
       [sourcechannel] => 653
       [sourcestation] => KUSADT
       [episodetitle] => Snowboarding, Speed Skating, Skiing
       [byteoffset] => 0
       [customicon] => urn:tivo:image:in-progress-recording
       [content] => http://192.168.1.124:80/download/XXI&#37;20Winter%20Olympics.TiVo?Container=%2FNowPlaying&id=2095444
       [tivovideodetails] => https://192.168.1.124:443/TiVoVideoDetails?id=2095444
   )
```
If that works (and assuming you haven't changed the original), download the new tweettivo script at http://www.mrbalky.com/wp-content/uploads/tweettivo/tweetTiVo.php.txt, and again rename without the .txt.

If you have changed the original, the only difference is that at the top it now includes parse_tivo_xml.php, instead of class_tivo_xml.php, and around line 26 replaces this code

```
$tivoParser = new Tivo_XML();
$tivoParser->init();
$programs = $tivoParser->parseTiVoXML( $inputFile );
```
with this

```
$nowPlaying = parseTiVoXML( $inputFile );
$programs = $nowPlaying['programs'];
```


----------



## bluebeetle (Jan 22, 2002)

This is the command I ran:


```
C:\tivotweet>"C:\php\php.exe" -c "C:\PHP\php.ini" -f "c:\tivotweet\parse_tivo_xm
l.php" "c:\tivotweet\tivo_nowplaying.xml"
```
I only changed the directory to reflect where my PHP files were located.

This is the output it produced:


```
<?
function parseTiVoXML( $inputFile, $tivoPort = 80 )
{
  // Start with an empty now playing list
  $nowPlaying = array();
  $nowPlaying['programs'] = array();

  # Load up the tivo now playing xml
  $xml = file_get_contents( $inputFile );

  # Parse it
  $doc = new DOMDocument();
  if( $doc->loadXML($xml) === FALSE )
  {
    echo( "ERROR: Could not parse XML\n" );
    exit( 1 );
  }

  // Grab the node that tells us what kind of XML it is.  It'd better be TiVoCon
tainer!
  if( $doc->firstChild->nodeName != 'TiVoContainer' )
  {
    echo( "ERROR: Input does not seem to be a TiVo container\n" );
    return( $nowPlaying );
  }

  $entries = $doc->getElementsByTagName("Item");

  // Summary for the nowplaying list
  $nowPlaying['lastchangedate'] = $doc->getElementsByTagName("LastChangeDate")->
item(0)->textContent;
  $nowPlaying['totalitems']     = $doc->getElementsByTagName("TotalItems")->item
(0)->textContent;
  $nowPlaying['ItemStart']  = $doc->getElementsByTagName("ItemStart")->item(0)->
textContent;
  $nowPlaying['ItemCount'] = $doc->getElementsByTagName("ItemCount")->item(0)->t
extContent;

  // build the array of all programs
  for ( $i=0; $i<$entries->length; $i++ )
  {
    $item = $entries->item($i);
    $details = $item->getElementsByTagName('Details')->item(0);
    $links = $item->getElementsByTagName('Links')->item(0);

    // Get a mess o' details
    $currentProgram = array();
    $currentProgram['title'] = $details->getElementsByTagName('Title')->item(0)-
>textContent;
    $currentProgram['sourcesize'] = $details->getElementsByTagName('SourceSize')
->item(0)->textContent;
    $currentProgram['duration'] = $details->getElementsByTagName('Duration')->it
em(0)->textContent;
    $currentProgram['capturedate'] = $details->getElementsByTagName('CaptureDate
')->item(0)->textContent;
    $currentProgram['description'] = $details->getElementsByTagName('Description
')->item(0)->textContent;
    $currentProgram['sourcechannel'] = $details->getElementsByTagName('SourceCha
nnel')->item(0)->textContent;
    $currentProgram['sourcestation'] = $details->getElementsByTagName('SourceSta
tion')->item(0)->textContent;
    $currentProgram['episodetitle'] = $details->getElementsByTagName('EpisodeTit
le')->item(0)->textContent;
    $currentProgram['byteoffset'] = $details->getElementsByTagName('ByteOffset')
->item(0)->textContent;

    // The item may not have a custom icon node, so check for null before using
it
    $currentProgram['customicon'] = $links->getElementsByTagName('CustomIcon')->
item(0);
    if ( $currentProgram['customicon'] != '' )
      $currentProgram['customicon'] = $currentProgram['customicon']->getElements
ByTagName('Url')->item(0)->textContent;

    // Put the download link into the current program
    $content = $links->getElementsByTagName('Content')->item(0);
    $content = $content->getElementsByTagName('Url')->item(0)->textContent;
    if ( $tivoPort != 80 )
       $content = str_replace( ':80', ":$tivoPort", $content );
    $currentProgram['content'] = $content;

    // Put the video details link into the current program
    $videoDetails = $links->getElementsByTagName('TiVoVideoDetails')->item(0);
    $currentProgram['tivovideodetails'] = $videoDetails->getElementsByTagName('U
rl')->item(0)->textContent;

    // Add the current program to the list of programs
    $nowPlaying['programs'][] = $currentProgram;
  }

  return( $nowPlaying );
}

// Test the parser.  *Should* only run if this script is called directly and not
 included.
$ndx = strrpos( __FILE__, $argv[0] );
if ( $ndx == ( strlen(__FILE__) - strlen($argv[0]) ) )
  print_r( parseTiVoXML( $argv[1] ) );
?>
```


----------



## MrBalky (Sep 14, 2005)

Ah, that's the PHP short_open_tag setting. You have 2 choices:

edit php.ini and change "short_open_tag=Off" to "short_open_tag=On"
edit both parse_tivo_xml.php and tweetTiVo.php and change the first line from "<?" to "<?php"

Sorry; I'm lazy and use the <? instead of <?php all the time, so I've done the php.ini thing, and am always forgetting that the most portable thing is <?php.


----------



## bluebeetle (Jan 22, 2002)

Now I'm getting a "ERROR: Could not parse XML"

Does the tivo_nowplaying.xml already need to be created?


----------



## MrBalky (Sep 14, 2005)

That script is just the parser; it doesn't download from the TiVo or anything, so yes, you should have already gotten the XML from the tivo. It's much like the tweettivo.php script in that way; you have to first run the curl command to get the XML from the tivo.


----------



## fsnertz (Mar 14, 2009)

This discussion is neat and all, and I don't mean to hijack (and I don't really think I am, actually).

But I want the converse - I want to tie a Twitter account to my TiVo, so that if I direct-message (DM) a Twitter account that's tied to my TiVo, the message will appear on the TV screen.

This would be great for when my wife and son are watching TV, and I'm ready to leave the office, or perhaps notify the watcher with Caller ID info of the ringing phone, or display a Tweet that the washer or dryer just stopped its cycle...

I could write something like this for Myth, MCE or the like. How about it, TiVo?


----------



## Plugh (Nov 3, 2005)

I noticed that Tivo has stopped hosting the namespace file at 
http www tivo com /developer/calypso-protocol-1.6/
Does anyone know the new location?


----------

