From: Andrew Ruthven Date: Mon, 19 Nov 2007 08:22:38 +0000 (+1300) Subject: Possibly show the amount of time until the next recording. X-Git-Tag: 0.5~25 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec62e4b96e88d41c35d6af6d03e39d569f06722f;p=mythtv-status.git Possibly show the amount of time until the next recording. --- diff --git a/ChangeLog b/ChangeLog index fdea564..7095094 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ Now we should any schedule conflicts, or if the MythTV Perl API isn't usable, a warning. (This is because we need to be able to read the mysql.txt file and connect to the database to use the API, ick.) + Display the amount of time until the next recording. 2007-11-17 Andrew Ruthven Add support for printing colour in the encoder status display. diff --git a/bin/mythtv-status b/bin/mythtv-status index 6d180df..71c32d3 100755 --- a/bin/mythtv-status +++ b/bin/mythtv-status @@ -60,16 +60,19 @@ my %defaults = ( || ($date cmp $tomorrow) == 0) } }, 'rewrite' => { - 'startTime' => { 'T' => ' ' }, + '/startTime/' => { 'T' => ' ' }, } } ); +my $next_time = undef; + # The blocks of output which we might generate. my @blocks = ( # Date/Time from server { 'name' => 'Status', + 'type' => 'xpath', 'xpath' => "//Status", 'attrs' => [ qw/time date/ ], 'template' => "__date__, __time__", @@ -79,12 +82,13 @@ my @blocks = ( # Info about the encoders. { 'name' => 'Encoders', + 'type' => 'xpath', 'xpath' => "//Status/Encoders/Encoder", 'attrs' => [ qw/hostname id state connected/ ], 'template' => "__hostname__ (__id__) - __state____connected__", 'rewrite' => { - 'connected' => { '1' => '', '0' => ' (Disconnected)' }, - 'state' =>{ '^0$' => "${safe}Idle${normal}", + '/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}", @@ -95,27 +99,69 @@ my @blocks = ( # What programs (if any) are being recorded right now? { 'name' => 'Recording Now', + 'type' => 'xpath', 'xpath' => "//Status/Encoders/Encoder/Program", 'attrs' => [ qw/title endTime/ ], 'template' => "__title__ (Ends: __endTime__)", - 'rewrite' => { - 'endTime' => { 'T' => ' ' }, + 'rewrite' => { + '/endTime/' => { 'T' => ' ' }, + }, + 'subs' => { + 'find_next' => sub { $next_time = 'now' } } }, # The upcoming recordings. { 'name' => 'Scheduled Recordings', + 'type' => 'xpath', 'xpath' => '//Status/Scheduled/Program', 'defaults' => 'schedule', + 'subs' => { + 'find_next' => sub { + my $vars = shift; + return + if $next_time eq 'now'; + + my $date = ParseDate($vars->{'startTime'}); + if (! defined $next_time || Date_Cmp($date, $next_time) < 0) { + $next_time = $date + }; + } + } }, # Conflicts { 'name' => 'Schedule Conflicts', - 'Perl MythTV' => 1, + 'type' => 'Perl MythTV API', 'defaults' => 'schedule', }, + + # How many hours till the next recording. + { + 'name' => 'Time till next recording', + 'type' => 'sub', + 'format' => 'one line', + 'template' => '__next_time__', + 'rewrite' => { + '&next_time' => sub { + return "Never" + unless defined $next_time; + + my $str = Delta_Format(DateCalc('now', $next_time, undef, 1), 0, '%hh Hours, %mv Minutes'); + $str =~ s/\b1 (Hour|Minute)s/1 $1/; + $str =~ s/^0 Hours, //; + $str =~ s/ 0 Minutes//; + + return $str; + } + }, + 'filter' => { + 'next_time' => sub { return $_[0] eq 'now' } + } + }, + ); ### @@ -163,11 +209,14 @@ for my $block (@blocks) { } my $output = undef; - if (defined $block->{'xpath'}) { + if ($block->{'type'} eq 'xpath') { $output = process_xml($block, $xml); - } elsif (defined $block->{'Perl MythTV'}) { + } elsif ($block->{'type'} eq 'Perl MythTV API') { $output = process_perl($block, $myth); + + } elsif ($block->{'type'} eq 'sub') { + $output = substitute_vars($block, { 'next_time' => $next_time }); } if (defined $output) { @@ -260,15 +309,22 @@ sub substitute_vars { if defined $block->{'filter'}{$key} && &{ $block->{'filter'}{$key} }($value); - if (defined $block->{'rewrite'}{$key}) { + if (defined $block->{'rewrite'}{"/$key/"}) { my ($search, $replace); - while (($search, $replace) = each %{ $block->{'rewrite'}{$key} } ) { + while (($search, $replace) = each %{ $block->{'rewrite'}{"/$key/"} } ) { $value =~ s/$search/$replace/g; } + } elsif (defined $block->{'rewrite'}{"&$key"}) { + $value = &{ $block->{'rewrite'}{"&$key"} }($value); } $template =~ s/__${key}__/$value/g; } + + my ($name, $sub); + while (($name, $sub) = each %{ $block->{'subs'} }) { + &$sub($vars); + } return defined $skip ? undef : $template; } @@ -354,6 +410,11 @@ Up to 10 programs which are scheduled to be recorded today and tomorrow. Any upcoming schedule conflicts (not just limited to today or tomorrow). +=item Time till next recording + +If there are no recordings currently happening, then the amount of time until +the next recording is displayed. + =back =head1 AUTHOR