'v|version' => \&print_version,
'email=s@' => \@email,
'email-only-on-conflict|email-only-on-alert|email-only-on-alerts'
- => \$email_only_on_alert,
+ => \$email_only_on_alert,
'disk-space-warn=i' => \$disk_space_warn,
'guide-days-warn=i' => \$guide_days_warn,
'auto-expire-count=i' => \$auto_expire_count,
'verbose' => \$verbose,
'help|?' => \$help,
-) || pod2usage("\nUse --help for help.\n");
+ ) || pod2usage("\nUse --help for help.\n");
pod2usage(verbose => 1)
if defined $help;
. " (__channelName__)"
. (defined $description ? "\n__NODE_TEXT__" : ''),
'filter' => {
- # Only show recordings for today and tomorrow.
- 'startTime' => sub {
- my $date = substr(ParseDate($_[0]), 0, 8);
- return ! (($date cmp $today) == 0
+
+ # Only show recordings for today and tomorrow.
+ 'startTime' => sub {
+ my $date = substr(ParseDate($_[0]), 0, 8);
+ return ! (($date cmp $today) == 0
|| ($date cmp $tomorrow) == 0) }
- },
- 'rewrite' => {
- '/startTime/' => { 'T' => ' ' },
- }
- }
-);
+ },
+ 'rewrite' => {
+ '/startTime/' => { 'T' => ' ' },
+ }
+ }
+ );
# The time of the next scheduled recording.
my $next_time = 'Never';
+
# Are there any alerts that should be notified via email?
my @alerts = ();
# The blocks of output which we might generate.
my @blocks = (
+
# All the one liners together
{
'name' => 'One Liners',
'rewrite' => {
'/connected/' => { '1' => '', '0' => ' (Disconnected)' },
'/state/' => {
- '^0$' => "${safe}Idle${normal}",
- '^1$' => "${warning}Watching LiveTV${normal}",
- '^2$' => "${warning}Watching Pre-recorded${normal}",
- '^3$' => "${warning}Watching Recording${normal}",
- '^4$' => "${warning}Recording${normal}" },
- }
+ '^0$' => "${safe}Idle${normal}",
+ '^1$' => "${warning}Watching LiveTV${normal}",
+ '^2$' => "${warning}Watching Pre-recorded${normal}",
+ '^3$' => "${warning}Watching Recording${normal}",
+ '^4$' => "${warning}Recording${normal}" },
+ }
},
# What programs (if any) are being recorded right now?
'template' => "__title__ (__channelName__) Ends: __endTime__",
'rewrite' => {
'/endTime/' => { '.*T' => '' },
- },
- 'subs' => {
- 'find_next' => sub { $warn_present ||= 1; $next_time = 'now' }
- }
+ },
+ 'subs' => {
+ 'find_next' => sub { $warn_present ||= 1; $next_time = 'now' }
+ }
},
# The upcoming recordings.
'hide' => 'after',
'subs' => {
'find_next' => sub {
- my $vars = shift;
- return
- if defined $next_time && $next_time eq 'now';
-
- my $date = ParseDate($vars->{'startTime'});
- if ($next_time eq 'Never' || Date_Cmp($date, $next_time) < 0) {
- $next_time = $date
- };
- }
- }
+ my $vars = shift;
+ return
+ if defined $next_time && $next_time eq 'now';
+
+ my $date = ParseDate($vars->{'startTime'});
+ if ($next_time eq 'Never' || Date_Cmp($date, $next_time) < 0) {
+ $next_time = $date
+ };
+ }
+ }
},
# Conflicts
'subs' => {
'percent' => sub {
calc_disk_space_percentage($_[0]->{'_total_used'}, $_[0]->{'_total_total'})
+ }
}
- }
},
# Diskspace, with storage groups
'subs' => {
'percent' => sub {
calc_disk_space_percentage($_[0]->{'drive_total_used'}, $_[0]->{'drive_total_total'})
+ }
}
- }
},
# Diskspace, with storage groups and sensible XML layout.
'subs' => {
'percent' => sub {
calc_disk_space_percentage($_[0]->{'used'}, $_[0]->{'total'})
+ }
}
- }
},
# Diskspace, with storage groups and sensible XML layout.
'id' => sub { return $_[0] eq 'total' },
'used' => sub {
return ! (
- (defined $display{'Disk Space'} && $display{'Disk Space'})
- || ($_[1]->{'used'} / $_[1]->{'total'}) * 100 > $disk_space_warn)
- }
- },
+ (defined $display{'Disk Space'} && $display{'Disk Space'})
+ || ($_[1]->{'used'} / $_[1]->{'total'}) * 100 > $disk_space_warn)
+ }
+ },
'subs' => {
'percent' => sub {
calc_disk_space_percentage($_[0]->{'used'}, $_[0]->{'total'})
+ }
}
- }
},
-
# How many hours till the next recording.
{
'name' => 'Next Recording In',
'template' => '__next_time__',
'rewrite' => {
'&next_time' => sub {
- return $next_time
- if $next_time eq 'Never' || $next_time eq 'now';
+ return $next_time
+ if $next_time eq 'Never' || $next_time eq 'now';
my $delta = DateCalc('now', $next_time, undef, 1);
my $str = Delta_Format($delta, 0, '%hh Hours, %mv Minutes');
my $seconds = Delta_Format($delta, 0, '%sh');
$str =~ s/\b1 (Hour|Minute)s/1 $1/;
- $str =~ s/^0 Hours, //;
+ $str =~ s/^0 Hours, //;
$str =~ s/ 0 Minutes//;
- if ($seconds <= $recording_in_warn) {
- $warn_present ||= 1;
+ if ($seconds <= $recording_in_warn) {
+ $warn_present ||= 1;
$str = "$warning$str$normal";
- }
+ }
return $str;
- }
- },
+ }
+ },
'filter' => {
'next_time' => sub { return $_[0] eq 'now' }
- },
+ },
'sub' => sub {
return substitute_vars($_[0], { 'next_time' => $next_time });
- }
+ }
},
# Check how much Guide data we have
'filter' => {
'guideDays' => sub {
if ($_[0] > $guide_days_warn) {
- return
- (defined $display{'Guide Data'} && ! $display{'Guide Data'}) || 1;
+ return
+ (defined $display{'Guide Data'} && ! $display{'Guide Data'}) || 1;
} else {
- $warn_present ||= 1;
+ $warn_present ||= 1;
push @alerts, "GUIDE DATA";
return 0;
}
+ },
},
- },
'rewrite' => {
'&guideDays' => sub {
if ($_[0] <= $guide_days_warn) {
- $warn_present ||= 1;
+ $warn_present ||= 1;
return "$warning$_[0]$normal";
- } else {
+ } else {
return "$safe$_[0]$normal";
}
- },
+ },
'/guideThru/' => { 'T\d+:\d+:\d+' => ' ' },
'&guideThru' => sub {
if ($_[1]->{'guideDays'} <= $guide_days_warn) {
- $warn_present ||= 1;
+ $warn_present ||= 1;
return "$warning$_[0]$normal";
- } else {
+ } else {
return "$safe$_[0]$normal";
}
+ },
},
- },
},
{
'xpath' => '//Status/MachineInfo/Guide[@status=""]',
'template' => "${warning}No guide data!${normal}",
},
-);
+ );
###
### Set some useful variables
# Deal with the one liners.
if (scalar(@oneliners) > 0) {
+
# Find the longest header
my $length = 0;
for $line (@oneliners) {
- if (length($line->[0]) > $length) {
- $length = length($line->[0]);
- }
+ if (length($line->[0]) > $length) {
+ $length = length($line->[0]);
+ }
}
# Put the one liners together, with leading dots to the colon.
my $oneliners = "";
for $line (@oneliners) {
- $oneliners .= "$line->[0]"
- . ('.' x ($length - length($line->[0]))) . ": $line->[1]\n";
+ $oneliners .= "$line->[0]"
+ . ('.' x ($length - length($line->[0]))) . ": $line->[1]\n";
}
# What a hacky way of putting the one liners where I want them...
print "\n$output";
} else {
if ((! $email_only_on_alert) ||
- ($email_only_on_alert && scalar(@alerts) > 0)) {
+ ($email_only_on_alert && scalar(@alerts) > 0)) {
my $suffix = undef;
if (@alerts == 1) {
$suffix = $alerts[0];
To => \@email,
Subject => $title . (defined $suffix ? " - $suffix" : ''),
Data => $output
- );
+ );
$mail->send('sendmail');
}
alarm(30);
$status = get($url);
alarm(0);
- };
+ };
die "Sorry, failed to fetch $url: Connection to MythTV timed out.\n"
if $@;
return $xml;
}
-
# Prep the Perl MythTV API if available.
sub load_perl_api {
my $myth = undef;
print $@
if $verbose;
} else {
+
# Surpress warnings from DBI. I tried unsetting $^W but that is ignored.
local($SIG{__WARN__}) = sub { if ($verbose) { print shift } };
eval { $myth = new MythTV() };
if ($@) {
if ($verbose) {
- warn "Failed to load Perl API\n";
+ warn "Failed to load Perl API\n";
print $@;
}
} elsif ($verbose) {
my $res = eval ( "$version{$vers} $check" );
if (! defined $result || $res != 1) {
- $result = $res;
- }
+ $result = $res;
+ }
}
return
my %vars;
for my $key (@{ $block->{'attrs'} }) {
if ($key =~ /(.*?):(.*)/) {
- my $subitem = $item->findnodes($2);
+ my $subitem = $item->findnodes($2);
$vars{$1} = @{ $subitem }[0]->getAttribute($1)
if defined @{ $subitem }[0];
} else {
foreach my $row (@{$rows{'rows'}}) {
my $show;
{
+
# MythTV::Program currently has a slightly broken line with a numeric
# comparision.
local($^W) = undef;
'startTime' => strftime("%FT%T", localtime($show->{'starttime'})),
'NODE_TEXT' => $show->{'description'},
'subTitle' => $show->{'subtitle'},
- 'channelName' => $show->{'channame'},
- 'inputId' => $show->{'inputid'},
- 'chanNum' => $show->{'channum'},
- );
+ 'channelName' => $show->{'channame'},
+ 'inputId' => $show->{'inputid'},
+ 'chanNum' => $show->{'channum'},
+ );
my $str = substitute_vars($block, \%vars);
push @lines, $str
foreach my $row (reverse @{$rows{'rows'}}) {
my $show;
{
+
# MythTV::Program currently has a slightly broken line with a numeric
# comparision.
local($^W) = undef;
'channelName' => $show->{'callsign'},
'inputId' => $show->{'inputid'},
'chanNum' => $show->{'chanid'},
- );
+ );
my $str = substitute_vars($block, \%vars);
push @lines, $str
if (! defined $value) {
if ($block->{'optional'}) {
warn "Unable to find any value for $key while at $block->{'name'}, marked as optional, skipping block.\n"
- if $verbose;
- return undef;
+ if $verbose;
+ return undef;
} else {
warn "Unable to find any value for $key while looking at $block->{'name'}\n";
next;