#!/usr/bin/perl -w # # Silly perl script that reads the web directory fetched from a tivo box # (after filtering through add-newlines) and looks for episodes of # Doctor Who to download. # # Will fail miserably if the TiVo starts formatting the web page # differently... # use strict; # Get PATH set to include this script's directory and other useful bits my $newpath=`dirname $0`; chomp($newpath); $newpath=`$newpath/echo-path`; chomp($newpath); $ENV{'PATH'}=$newpath; my $topdir='/huge/vids'; my $whodir="$topdir/DoctorWho"; my $dbdir="$whodir/.data"; my $dbfile="$dbdir/allinfo.txt"; my %db; # Read in the existing database to check for already downloaded episodes # we can skip (marked with nodownload=1 after I'm sure the copy I have # is good enough that I'm unlikely to do better). my $fh; my $r; if (open($fh, '<', $dbfile)) { while (<$fh>) { chomp; if (/^\[(.+)\]$/) { my $basename = $1; $r = {}; $db{$basename} = $r; } elsif (/^([A-Za-z0-9_]+)=(.+)$/) { if (defined($r)) { my $key = $1; my $val = $2; $r->{$key} = $val; } } } close($fh); undef($fh); undef($r); } else { print "Cannot read $dbfile : $!\n"; } sub check_one_episode { my $rd = shift; my $episode_name; my $record_date; my $url; my $id; if ($rd->[1]=~/alt=\"BBCAHD\"/) { if ($rd->[2]=~/Doctor Who/) { $episode_name = $rd->[2]; chomp($episode_name); $episode_name=~s/\&[a-zA-Z0-9_]+\;//g; $episode_name=~s/^\