#!/usr/bin/perl ########################################### # ftivo - FTP shows off of TiVo # Mike Schilli, 2004 (m@perlmeister.com) ########################################### use warnings; use strict; my $TIVO_IP = "192.168.0.11"; my $TIVO_PORT = 3105; my $TAR_CMD = "tar"; my $RC_FILE = "$ENV{HOME}/.ftivorc"; my %CONF = (); our $CVSVERSION = '$Revision: 1.9 $'; use Net::FTP; use Log::Log4perl qw(:easy); use File::Copy; Log::Log4perl->easy_init( { level => $DEBUG, layout => "%m%n", }); # Configure parameters, using .ftivorc or defaults configure(); my $regex = $ARGV[0]; die "usage: $0 regex" unless defined $regex; $regex = qr/$regex/; INFO "Connecting to $CONF{IP_ADDR} ..."; my $ftp = Net::FTP->new($CONF{IP_ADDR}, Port => $TIVO_PORT, Passive => 0, ); $ftp->login(); $ftp->binary(); $ftp->cwd("tmf") or die "Cannot chdir to tmf"; my @files = $ftp->ls(); my @relevant; for(@files) { next unless /$regex/; $| = 1; print "$_ ([y]/n)"; my $yesno = ; next if $yesno =~ /n/i; last if $yesno =~ /q/i; push @relevant, $_; } for(@relevant) { INFO "Fetching $_"; $ftp->get("$_"); process($_); } $ftp->quit(); ################################################## sub process { ################################################## my($file) = @_; # {The Wire}{2003-07-06}{The Prologue}... # {08.30 PM Sun Jul 06, 2003}{HBOP}.tmf if($file !~ m#{(.*?)}{.*?}{(.*?)}#) { ERROR " Title not recognized"; return; } my $title = "$1 $2"; $title =~ s/[\d-]+/ /g; $title =~ s/ +/-/g; $title =~ s/}//g; $title =~ s/{//g; $title = lc($title); INFO " Title: '$title'"; INFO " untarring"; $file =~ s/"/\\"/g; system("$TAR_CMD xf \"$file\"") and die "Cannot untar"; for my $part () { $part =~ /(\d+)/; move $part, "$title-$1.ty" or die "Cannot move"; INFO " $title-$1.ty ready"; } unlink "showing.xml"; unlink $file; } ################################################## sub configure { ################################################## if(open FILE, "<$ENV{HOME}/.ftivorc") { while() { chomp; next if /^\s*#/; my($key, $val) = split / /, $_; $CONF{$key} = $val; } close FILE; } if(! exists $CONF{IP_ADDR}) { $| = 1; print "What's your TiVo's IP address: "; my $in = ; if($in =~ /(\S+)/) { $CONF{IP_ADDR} = $1; } config_write(); } } ################################################## sub config_write { ################################################## open FILE, ">$RC_FILE" or die "Cannot open $RC_FILE ($!)"; for(keys %CONF) { print FILE "$_ $CONF{$_}\n"; } close FILE; } __END__ =head1 NAME ftivo - FTP shows off of TiVo =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS ftivo =head1 DESCRIPTION So you've read "Hacking TiVo" by Jeff Keegan and installed the FTP server running on port 3105 to extract recorded shows? And you want a convenient interface to select *.tmf files by a regular expression, transfer them over to your computer, extract their *.ty parts, rename and store them? Read on, C is for you. If you've got all of the above, then you just need to configure C by adapting it to your local requirements. Check these lines before you start it and make sure it reflects your installation: my $TIVO_IP = "192.168.0.11"; my $TIVO_PORT = 3105; my $TAR_CMD = "tar"; Most likely the TiVo's IP address will be different on your home network, so just adapt it to the local setting. Now, the best way to explain C is to print a sample session retrieving all "Simpsons" shows: $ ftivo "The Simpsons" Connecting to 192.168.0.11 ... {The Simpsons}{2003-01-12}{The Dad Who Knew Too Little}{07.00 PM Sun Jun 15, 2003}{KTVU}.tmf ([y]/n)y Fetching {The Simpsons}{2003-01-12}{The Dad Who Knew Too Little}{07.00 PM Sun Jun 15, 2003}{KTVU}.tmf Title: 'the-simpsons-the-dad-who-knew-too-little' untarring the-simpsons-the-dad-who-knew-too-little-00.ty ready In this case, there was only one show on the TiVo matching the regular expression C, and it was selected by agreeing with C. Entering C would have suppressed this particular match, but would have continued prompting for other matches. Entering C will abort the questioning and start retrieving the previously selected shows. C will go ahead and FTP the selected *.tmf files from the TiVo, C them to extract their *.ty part(s) and rename it/them to the-simpsons-the-dad-who-knew-too-little-00.ty and also treat their followup parts like *-01.ty, *-02.ty, etc. These files can then be viewed with the TiVo-adapted C. =head1 LEGALESE Copyright 2004 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR 2004, Mike Schilli