Difference between revisions of "Which recorder.pl"

From MythTV Official Wiki
Jump to: navigation, search
m (Forgot script info category)
(New logging regex.)
 
(9 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{Wrongtitle|which_recorder.pl}}
 
{{Wrongtitle|which_recorder.pl}}
 
{{Script info
 
{{Script info
|author=unknown
+
|author=Michael T. Dean
 
|short=Show which card recorded shows
 
|short=Show which card recorded shows
 
|long=Parses the backend log file and outputs information on which capture card was used to record shows, formatted for inclusion in the backend status page.
 
|long=Parses the backend log file and outputs information on which capture card was used to record shows, formatted for inclusion in the backend status page.
 
|category=Miscellaneous Status Information Scripts
 
|category=Miscellaneous Status Information Scripts
|file=which_recorder.pl}}
+
|file=which_recorder.pl
 +
|S21=yes|S22=yes|S23=yes|S24=yes}}
  
'''which_recorder.pl''' parses the backend log file and outputs information on which capture card was used to record shows, formatted for inclusion in the backend status page.
+
'''which_recorder.pl''' parses the master backend log file and outputs information on which capture card was used to record shows, formatted for inclusion in the backend status page.
  
 
= Usage =
 
= Usage =
  
  which_recorder.pl /path/to/backend/log/file
+
  which_recorder.pl /path/to/master/backend/log/file
  
Because <code>which_recorder.pl</code> displays information about all recordings in your log file, you'll probably want to rotate your logs occasionally.
+
Because <code>which_recorder.pl</code> displays information about all recordings in your log file, you'll probably want to [[:Category:Log Rotation Configuration Files|rotate your log files]] occasionally.
  
If you have multiple backends, <code>which_recorder.pl</code> will only show information about shows recorded on the backend that runs the script (or, technically, only shows information about shows described in the log file specified, so you could have a slave push its log file to the master occasionally and run the script twice--once for each log file--but that's an exercise left for the reader).
+
If you have multiple backends, <code>which_recorder.pl</code> must be run against the master backend log file. The master backend must be run with a verbose level that includes the "general" verbose messages (which is part of the default verbosity).
 +
 
 +
To output the information to the console, rather than use it in the Miscellaneous Status Info section of the backend status page, you may call the script with the <code>--text</code> argument.
 +
 
 +
  which_recorder.pl --text /path/to/master/backend/log/file
 +
 
 +
= The Script =
  
 
{{Code box|which_recorder.pl|
 
{{Code box|which_recorder.pl|
Line 23: Line 30:
 
# Parses the backend log file and includes information on which capture card was used to record shows.
 
# Parses the backend log file and includes information on which capture card was used to record shows.
  
 +
my ($time, $title, $subtitle, $chanid, $cardid, $sourceid);
 +
my $index = 0;
 +
 +
sub print_text
 +
{
 +
    print "$time - $title";
 +
    print ": $subtitle" if ($subtitle);
 +
    print "\n";
 +
    print " - Capture Card ID: $cardid\n";
 +
    print " - Video Source ID: $sourceid\n";
 +
    print " -      Channel ID: $chanid\n";
 +
}
 +
 +
sub print_xml
 +
{
 +
    print "<a href=\"#\">$time - $title";
 +
    print ": $subtitle" if ($subtitle);
 +
    print " - Capture Card: $cardid<br />".
 +
          "<span><strong>$title</strong> $time<br />";
 +
    print "<em>$subtitle</em><br />" if ($subtitle);
 +
    print "<br />Channel ID: $chanid<br />Capture Card ID: $cardid<br />".
 +
          "Video Source ID: $sourceid<br /></span></a><hr />";
 +
    # For XML parsers
 +
    print "[]:[]capture_info$index\[]:[]time='$time':title='$title'".
 +
          ":subtitle='$subtitle':chanid='$chanid':cardid='$cardid'".
 +
          ":sourceid='$sourceid'\n";
 +
}
 +
 +
my $mode = shift;
 
my $log_file = shift;
 
my $log_file = shift;
  
#2008-08-30 15:59:41.969 scheduler: Started recording: Not My Life: channel 1651 on cardid 1, sourceid 1
+
if ($mode ne "--text")
 +
{
 +
    $log_file = $mode;
 +
}
  
 
open($fh, "<$log_file") or die "Unable to open log file '$log_file', stopping:";
 
open($fh, "<$log_file") or die "Unable to open log file '$log_file', stopping:";
 
my ($time, $title, $chanid, $cardid, $sourceid);
 
my $subtitle;
 
my $index = 0;
 
  
 
while (<$fh>)
 
while (<$fh>)
 
{
 
{
     if (/^(.*) scheduler: Started recording: (.*): channel (\d+) on cardid (\d+), sourceid (\d+)/)
+
     if (/^(.*)(?:\d(?: I )?|I.* -) (?:Started|Tuning) recording: (.*): channel (\d+) on cardid (\d+), sourceid (\d+)/)
 
     {
 
     {
 
         print "<h3>Capture Information</h3><div class=\"schedule\""
 
         print "<h3>Capture Information</h3><div class=\"schedule\""
           if ($index == 0);
+
           if (($index == 0) && ($mode ne "--text"));
 
         $index++;
 
         $index++;
 
         ($time, $title, $chanid, $cardid, $sourceid) = ($1, $2, $3, $4, $5);
 
         ($time, $title, $chanid, $cardid, $sourceid) = ($1, $2, $3, $4, $5);
         if ($title =~ /(.+) "(.*)"/)
+
         if (($title =~ /"?(.+)"?:"?(.*)"?/) || ($title =~ /(.+) "(.*)"/))
 
         {
 
         {
 
             $title = $1;
 
             $title = $1;
Line 50: Line 85:
 
             $subtitle = '';
 
             $subtitle = '';
 
         }
 
         }
         print "<a href=\"#\">$time - $title";
+
         $title =~ s/^"//;
         print ": $subtitle" if ($subtitle);
+
         $subtitle =~ s/^"//;
         print " - Capture Card: $cardid<br />".
+
         $title =~ s/"$//;
              "<span><strong>$title</strong> $time<br />";
+
         $subtitle =~ s/"$//;
         print "<em>$subtitle</em><br />" if ($subtitle);
+
        if ($mode eq "--text")
         print "<br />Channel ID: $chanid<br />Capture Card ID: $cardid<br />".
+
         {
              "Video Source ID: $sourceid<br /></span></a><hr />";
+
            print_text;
         # For XML parsers
+
         }
         print "[]:[]capture_info$index\[]:[]time='$time':title='$title'".
+
         else
              ":subtitle='$subtitle':chanid='chanid':cardid='$cardid'".
+
        {
              ":sourceid='$sourceid'\n";
+
            print_xml;
 +
        }
 
     }
 
     }
 
}
 
}
print "</div>" if ($index > 0);
+
print "</div>" if (($index > 0) && ($mode ne "--text"));
  
 
close $fh;
 
close $fh;
 
</pre>
 
</pre>
 
}}
 
}}
 +
 +
Regarding the above script:-
 +
 +
On 10/11/2013 09:57 PM, Stephen Worthington [http://www.gossamer-threads.com/lists/mythtv/users/555313#555313 wrote]
 +
>I had to modify it to make it work with the current log file format.  I
 +
> commented out the big if at line 45 and replaced it with this:
 +
>
 +
>      if (/^([A-Z][a-z][a-z] [ 0-9]\d \d\d:\d\d:\d\d) .* Tuning recording: (.*): channel (\d+) on cardid (\d+), sourceid (\d+)/)
 +
>
 +
> See here for how to make it work with mythweb:
 +
>
 +
> http://www.mythtv.org/wiki/Miscellaneous_Status_Information
 +
>
 +
> Of course, that only makes available the information in the current
 +
> log file, so if you need to use it a long time after the recording was
 +
> made it will be gone.
 +
 +
[[User:Stevegoodey|Stevegoodey]] 14:36, 23 October 2013 (UTC)
 +
  
 
[[Category:Miscellaneous_Status_Information_Scripts]]
 
[[Category:Miscellaneous_Status_Information_Scripts]]

Latest revision as of 14:36, 23 October 2013

Important.png Note: The correct title of this article is which_recorder.pl. It appears incorrectly here due to technical restrictions.


Author Michael T. Dean
Description Parses the backend log file and outputs information on which capture card was used to record shows, formatted for inclusion in the backend status page.
Supports Version21.png  Version22.png  Version23.png  Version24.png  


which_recorder.pl parses the master backend log file and outputs information on which capture card was used to record shows, formatted for inclusion in the backend status page.

Usage

which_recorder.pl /path/to/master/backend/log/file

Because which_recorder.pl displays information about all recordings in your log file, you'll probably want to rotate your log files occasionally.

If you have multiple backends, which_recorder.pl must be run against the master backend log file. The master backend must be run with a verbose level that includes the "general" verbose messages (which is part of the default verbosity).

To output the information to the console, rather than use it in the Miscellaneous Status Info section of the backend status page, you may call the script with the --text argument.

 which_recorder.pl --text /path/to/master/backend/log/file

The Script

Script.png which_recorder.pl

#!/usr/bin/perl -w
#
# Parses the backend log file and includes information on which capture card was used to record shows.

my ($time, $title, $subtitle, $chanid, $cardid, $sourceid);
my $index = 0;

sub print_text
{
    print "$time - $title";
    print ": $subtitle" if ($subtitle);
    print "\n";
    print " - Capture Card ID: $cardid\n";
    print " - Video Source ID: $sourceid\n";
    print " -      Channel ID: $chanid\n";
}

sub print_xml
{
    print "<a href=\"#\">$time - $title";
    print ": $subtitle" if ($subtitle);
    print " - Capture Card: $cardid<br />".
          "<span><strong>$title</strong> $time<br />";
    print "<em>$subtitle</em><br />" if ($subtitle);
    print "<br />Channel ID: $chanid<br />Capture Card ID: $cardid<br />".
          "Video Source ID: $sourceid<br /></span></a><hr />";
    # For XML parsers
    print "[]:[]capture_info$index\[]:[]time='$time':title='$title'".
          ":subtitle='$subtitle':chanid='$chanid':cardid='$cardid'".
          ":sourceid='$sourceid'\n";
}

my $mode = shift;
my $log_file = shift;

if ($mode ne "--text")
{
    $log_file = $mode;
}

open($fh, "<$log_file") or die "Unable to open log file '$log_file', stopping:";

while (<$fh>)
{
    if (/^(.*)(?:\d(?: I )?|I.* -) (?:Started|Tuning) recording: (.*): channel (\d+) on cardid (\d+), sourceid (\d+)/)
    {
        print "<h3>Capture Information</h3><div class=\"schedule\""
          if (($index == 0) && ($mode ne "--text"));
        $index++;
        ($time, $title, $chanid, $cardid, $sourceid) = ($1, $2, $3, $4, $5);
        if (($title =~ /"?(.+)"?:"?(.*)"?/) || ($title =~ /(.+) "(.*)"/))
        {
            $title = $1;
            $subtitle = $2;
        }
        else
        {
            $subtitle = '';
        }
        $title =~ s/^"//;
        $subtitle =~ s/^"//;
        $title =~ s/"$//;
        $subtitle =~ s/"$//;
        if ($mode eq "--text")
        {
            print_text;
        }
        else
        {
            print_xml;
        }
    }
}
print "</div>" if (($index > 0) && ($mode ne "--text"));

close $fh;

Regarding the above script:-

On 10/11/2013 09:57 PM, Stephen Worthington wrote

>I had to modify it to make it work with the current log file format.  I 
> commented out the big if at line 45 and replaced it with this:
>
>      if (/^([A-Z][a-z][a-z] [ 0-9]\d \d\d:\d\d:\d\d) .* Tuning recording: (.*): channel (\d+) on cardid (\d+), sourceid (\d+)/)
>
> See here for how to make it work with mythweb:
>
> http://www.mythtv.org/wiki/Miscellaneous_Status_Information
>
> Of course, that only makes available the information in the current 
> log file, so if you need to use it a long time after the recording was 
> made it will be gone.

Stevegoodey 14:36, 23 October 2013 (UTC)