#!/usr/bin/perl/ require 'dvrcommands.pl'; # Read in parameters from config file dvr.conf &config(); # Set some variables for time/date my ($sec,$min,$hour,$mday,$mon,$year,$wday,@yday); ($sec,$min,$hour,$mday,$mon,$year,$wday,@yday) = (localtime(time))[0,1,2,3,4,5,6,7]; my @days = ('SUNDAY','MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY'); my @months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); $mon++; if($year < 1900){ $year += 1900; } # Test to see what task we have $task = $ARGV[0]; # CHECK WHAT IS REQUIRED e.g. start or stop if($task eq "START" || $task eq "start"){ my $pid = fork(); if($pid) { &addLog("> ".&formatDate("/",$mday,$mon,$year)." ".&formatDate(":",$hour,$min,$sec)." STARTING DVR\n"); &addLog(">\tDVR HAS PID: $pid\n"); exit; } }elsif($task eq "STOP" || $task eq "stop"){ while(getPID($DVR{'dvr'})){ killIt($DVR{'dvr'}); } &addLog("> ".&formatDate("/",$mday,$mon,$year)." ".&formatDate(":",$hour,$min,$sec)." STOPPED DVR\n"); exit; }else{ print "No options specified for DVR\n"; print "Usage: perl dvr.pl start|stop\n"; exit; } #close(LOG); # Enter neverending loop that executes every minute while(1) { # Get current time ($sec,$min,$hour,$mday,$mon,$year,$wday,@yday) = (localtime(time))[0,1,2,3,4,5,6,7]; # How long to wait until waking up my $pause = 60 - $sec + int(rand(5)); $mon++; # Correct year - obviously has problems before 1900 but that is no problem ;-) if($year < 1900){ $year += 1900; } # Get schedule and return number of entries my $num = &getSchedule($DVR{'schedule'}); my $rec = 0; # Add the date to the log file at the start of each day if($hour == 0 && $min == 0){ &addLog("> ".&formatDate("/",$mday,$mon,$year)."\n"); } for($i = 0 ; $i < $num+1 ; $i++){ # Check to see if we should start recording if($schedule[$i]{'diff_start'} == 0 || ($schedule[$i]{'diff_start'} < 0 && $schedule[$i]{'diff_end'} > 0)){ $rec = 1; # Only record if not doing so already if(&getPID($DVR{'record'}) == 0){ &startRecording($schedule[$i]{'channel'},$schedule[$i]{'file'}); } } } # Should we stop recording? if($rec == 0 && &getPID($DVR{'record'}) > 0){ &addLog("> ".&formatDate(":",$hour,$min,$sec)." STOP RECORDING\n"); &killIt($DVR{'record'}); } sleep($pause); # Sleep until next minute starts }