#!/usr/bin/perl # # nkf -e -Lu hoge.tvpi | tvbook.pl %stations = ( "NHK総合", "1", "NHK教育", "3", "日本テレビ", "4", "TBSテレビ","6", "フジテレビ", "8", "テレビ朝日", "10", "テレビ東京", "12" ); sub get_length { my $h, $m; my @start = split /:/, $_[0]; my @end = split /:/, $_[1]; my @time = ( $start[0], $start[1], $end[0], $end[1] ); foreach ( @time ) { s/^0//; } if ( $time[0] > $time[2]) { $h = 24 - $time[0] + $time[2]; } else { $h = $time[2] - $time[0]; } if ( $time[1] > $time[3] ) { $m = 60 - $time[1] + $time[3]; $h -= 1; } else { $m = $time[3] - $time[1]; } return $h * 60 * 60 + $m * 60; } while ( <> ) { chop; $channel = $stations{$_} if $_ =~ s/^station: //; $year = $_ if $_ =~ s/^year: //; $month = $_ if $_ =~ s/^month: //; $date = $_ if $_ =~ s/^date: //; $start = $_ if $_ =~ s/^start: //; $end = $_ if $_ =~ s/^end: //; } $year =~ s/^..//; $date = $month . $date . $year; $length = get_length( $start, $end ); $filename = time . ".avi"; $cmd = "echo tvrec.pl -c $channel -t $length -o $filename | at $start $date"; system($cmd) eq 0 or die "system $cmd faild: $?\n";