Which recorder.pl

From MythTV Official Wiki
Revision as of 07:50, 11 April 2010 by Sphery (talk | contribs) (Add which_recorder.pl)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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


Parses the backend log file and includes information on which capture card was used to record shows.

Usage

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

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

If you have multiple backends, which_recorder.pl 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).


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 $log_file = shift;

#2008-08-30 15:59:41.969 scheduler: Started recording: Not My Life: channel 1651 on cardid 1, sourceid 1

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>)
{
    if (/^(.*) scheduler: Started recording: (.*): channel (\d+) on cardid (\d+), sourceid (\d+)/)
    {
        print "<h3>Capture Information</h3><div class=\"schedule\""
          if ($index == 0);
        $index++;
        ($time, $title, $chanid, $cardid, $sourceid) = ($1, $2, $3, $4, $5);
        if ($title =~ /(.+) "(.*)"/)
        {
            $title = $1;
            $subtitle = $2;
        }
        else
        {
            $subtitle = '';
        }
        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";
    }
}
print "</div>" if ($index > 0);

close $fh;