Apr 9 2003

TiVo + Home Media Option + Email

Oh, this is pretty funny. Just a few days ago when the home media option from TiVo (http://www.tivo.com/) came out, of course I had to be among the first ones to install it. Now we have the TiVo unit in the living room connected to the home network (using a wireless USB network adapter) and I can share pictures/music from my desktop system with the TiVo unit allowing me to do slideshows on the TV-set and stream radio stations over to the living room.

This is really pretty cool.

So, besides sharing images/mp3s – what else can you do? Well, I went over to http://www.tivo.com/developer/ and downloaded the protocol specifications for the Home Media Option. It shows how TiVo’s beacon works (how different units find each other and find out what services they have to offer) and how the http-based Media Server Protocol works.

I went ahead and modified the existing example of a Media Server to serve previews of my email through the TiVo. This worked nice, however did not coexist with the TiVo Media Server, because I did not find a way how I could convince the TiVoBeacon service on my system to advertise my custom service besides the TiVoServer services. So, I scratched that idea for the moment and went a different route.

Using perl (from http://www.activestate.com/Products/ActivePerl/) and some addon modules (GD, Mail::Internet, Mail::POP3Client, File::Path, File::Spec) which were easily installed via the Perl Package Manager (ppm) I created a script which would “render” email messages into PNG files. I shared a new folder (D:\DigitalPhotos\Tivo\EMail in this case) through the TiVo Desktop Server and used the script below (which is invoked on a regular basis through “Scheduled Tasks”) to get my email from a number of POP3 servers and create a PNG file for each message.

This allows me to preview messages on my TV when I’m not at my computer. This does not mean that I’m soo addicted to email that I have to watch it on the TV screen and it does also not mean that I’m really that often in front of the tube (fact is, that we spend less time in front of the TV since we got the TiVo unit).

The output looks something like this:
message-06.png

And here is the script that fetches and renders email messages. It’s a non-desctructive fetch, which means that messages stay on the server.

#!c:\perl\bin\perl.exe
use strict;
use File::Path;
use File::Spec;
use GD;
use Mail::POP3Client;
use Mail::Internet;
use constant DESTINATION   => q{d:\DigitalPhotos\Tivo\EMail};
use constant PREVIEW_LINES => 100;
use constant WIDTH         => 640;
use constant HEIGHT        => 480;
use constant HEADER_FONT   => gdMediumBoldFont;
use constant BODY_FONT     => gdLargeFont;
my @accounts = (
    {
     DESC      => q{thoellri@foobar.com},
     USER      => "thoellri",
     AUTH_MODE => "PASS",
     PASSWORD  => "password",
     HOST      => "pop3.foobar.com"
    },
    {
     DESC      => q{tobias@somewhere.com},
     USER      => "tobias",
     AUTH_MODE => "PASS",
     PASSWORD  => "password",
     HOST      => "mail.somewhere.com"
    },
);
for my $account (@accounts) {
    # erase existing messages
    rmtree([ File::Spec->catfile(DESTINATION, $account->{DESC}) ], 0, 0);
    my $pop = new Mail::POP3Client (%$account);
    unless ($pop) { warn "Couldn't connect\n"; next; }
    my $count = $pop->Count;
    if ($count <0) { warn "Authorization failed"; next; }
    next if($count == 0); # no new messages
    # create new directory for messages
    mkpath([ File::Spec->catfile(DESTINATION, $account->{DESC}) ], 0, 0711);
    for my $num (1..$count) {
	my @preview=$pop->HeadAndBody($num,100);
	my $mail=Mail::Internet->new(\@preview);
	my $header=$mail->head;
	my $image=render($mail);
	my $out=File::Spec->catfile(DESTINATION, $account->{DESC},qq{message-}.
                      sprintf("%02d",$num).qq{.png});
	open(OUT, qq{>$out});
	binmode OUT;
	print OUT $image->png;
	close(OUT);
    }
    $pop->Close;
}
sub render {
    my($m)=@_;
    my $header=$m->head();
    my $im = new GD::Image(WIDTH, HEIGHT);
    # allocate some colors
    my $white = $im->colorAllocate(255,255,255);
    my $black = $im->colorAllocate(0,0,0);
    my $gray = $im->colorAllocate(20,20,20);
    my $red = $im->colorAllocate(255,0,0);
    my $blue = $im->colorAllocate(0,0,255);
    my $y=2;
    $im->string(HEADER_FONT, 5,$y, "Date:    ".$header->get('Date'), $black);$y+=10;
    $im->string(HEADER_FONT, 5,$y, "From:    ".$header->get('From'), $black);$y+=10;
    $im->string(HEADER_FONT, 5,$y, "To:      ".$header->get('To'), $black);$y+=10;
    $im->string(HEADER_FONT, 5,$y, "Subject: ".$header->get('Subject'), $blue);$y+=10;
    $im->string(HEADER_FONT, 5,$y, "-" x 80, $black);$y+=8;
    foreach my $line (@{$m->body()}) {
	chomp($line);
	$im->string(BODY_FONT, 5, $y, $line, $gray);
	$y+=13; last if($y>=HEIGHT);
    }
    return $im;
}

Of course those usernames/hostnames/passwords are just samples and need to be customized for your environment.
And depending on the size of your TV-set you may have to tweak those values for HEADER_FONT and BODY_FONT.

Let me know, if it works for you as well ….

15 Responses to “TiVo + Home Media Option + Email”

  • me Says:

    Does anyone else cringe when they see paths containing things like “C:” and “D:”? When is Windows going to step into the 1980s and drop CP/M?

  • Dan Isaacs Says:

    Be careful what you wish for. I’m content to deal with C:\ from a company that put home directories in a folder called “Documents and Settings”.

  • Randal L. Schwartz Says:

    It might have been interesting to convert the email to audio using Festival, and then listening to your email instead of looking at it!

  • emory Says:

    You could do that, too, Randal. Take Festival output, convert to mp3, listen on the TiVo.

    Interesting idea.

  • temp1234 Says:

    Wouldn’t it be possible to use the Tivo Broadcast protocol to write an app which “pretends” it’s a Tivo DVR and initiate “copy” m2v files from a Tivo DVR unit? I guess which I’m trying to say is that this copy from one room to another idea is nothing more than 2 DVRs exchanging files. This one, one does not have to “hack” / “open” a Tivo unit and bastardize the Linux logon in order to get the m2v files off of a DVR unit. I’m not expert but would that work?

  • Jeff Says:

    I love the idea of emulating a Tivo. I think that aside from ripping the files from the Tivo, you could basically create a very nice “media center.” HMO already allows you to send images and mp3s. I would kill for the ability to stream video (Divx or mpeg2) to the Tivo and be able to watch it on my TV. Once that’s accomplished i’m definetly buying HMO. BTW, if anyone knows how to do this already, PLEASE drop me an e-mail (jmg352@stern.nyu.edu)

  • Michael Says:

    Only problem with the idea of emulating the tvbus protocol is the fact that the existing DVR(s) will only send messages (other than the initial announcement) to a DVR it has been told uses the home media option. IE: When you purchase the option for a DVR it is sent information on all DVR(s) in the LAN thet have been authorised to receive content. If you throw together a server which announces itself as a DVR and send it any tvbus messages, you will get the standard “Not an Authorized DVR message every time.” This happens in either direction since both ends must be authenticated before transactions can proceed.

  • cejay Says:

    Can someone help me with the script above? I looked for GD and installed every GD module I saw.. and the script dies looking for GD.pm / i dloaded the pkg again via the internet, but am not sure how to get it installed in the right dirs.. I also didnt see a file called MAIL-INTERNET on the search with ppm.
    help
    cj

  • cejay Says:

    ok.. i found gd.pm finally.. now i cant find mail/internet.pm dont see it on ppm.. and am going to hunt on google.com now for it.. ideas?

  • cejay Says:

    O well.. solved it all tonite.. dloaded mailtools.ppd from a website.. and finally got everything working.. and i can view my mail on my tivo!
    cj

  • bill Says:

    What I REALLY want to do, is the ability to take the video file off TIVO to my computer harddrive and make backups on my DVD burner. There are several shows on now playing on my “copy to tape, i want to save them” list, but it is very time consuming. There must be a way, I can’t believe TIVO would not have this a part of the service of HMO. I know there are probably “studio” reasons why they haven’t but they are not here to satisfy the studios, they are here presumably to satisfy us. I guess the answer is to by a “home media” computer and skip TIVO and their high priced service altogether?

    Anyone? Ideas? Solution? (if you do reply please copy me at my email address, I am not good about checking forums regularly

    thanks
    bill

  • Taylor Says:

    just wanted to say nice site!

    Taylor

  • Tobias Says:

    Dear Taylor (taylorjohnson4352@hotmail.com)- how would you know that this is a nice site? According to my access logs you’ve only left a comment (with a link to your worthless page) and did not even look at a single entry on kahunaburger.com.

  • Robert Says:

    I’ve been looking at different scripts to generate graphics on the fly, with the goal of generating and emailing passwords without them being sent in clear text. Your TiVo+PNG+Email scheme gives me good ideas. Thanks.

Leave a Reply