| 1 | #!/usr/bin/perl -w |
| 2 | # |
| 3 | # Outputs information about the most-recently-recorded shows. |
| 4 | # |
| 5 | # Automatically detects database settings. |
| 6 | # |
| 7 | |
| 8 | # Includes |
| 9 | use DBI; |
| 10 | use Getopt::Long; |
| 11 | use MythTV; |
| 12 | |
| 13 | # Some variables we'll use here |
| 14 | our ($num_recordings, $live, $plain_text, $usage); |
| 15 | |
| 16 | # Default number of recent recordings to show |
| 17 | $dnum_recordings = 5; |
| 18 | |
| 19 | # Provide default values for GetOptions |
| 20 | $num_recordings = $dnum_recordings; |
| 21 | |
| 22 | # Load the cli options |
| 23 | GetOptions('num_recordings|recordings|n=s' => \$num_recordings, |
| 24 | 'live' => \$live, |
| 25 | 'plain_text|plain|text' => \$plain_text, |
| 26 | 'usage|help|h' => \$usage |
| 27 | ); |
| 28 | |
| 29 | # Print usage |
| 30 | if ($usage) { |
| 31 | print <<EOF; |
| 32 | $0 usage: |
| 33 | |
| 34 | options: |
| 35 | |
| 36 | --recordings [number of recordings] |
| 37 | |
| 38 | Outputs information on the last [number of recordings] shows recorded by |
| 39 | MythTV. To output information on all recordings, specify -1. |
| 40 | |
| 41 | default: $dnum_recordings |
| 42 | |
| 43 | --text |
| 44 | Output information in plain text format (i.e. for inclusion in an e-mail |
| 45 | notification). |
| 46 | |
| 47 | --live |
| 48 | Include information on recent LiveTV recordings. |
| 49 | |
| 50 | --help |
| 51 | |
| 52 | Show this help text. |
| 53 | |
| 54 | EOF |
| 55 | exit; |
| 56 | } |
| 57 | |
| 58 | # Connect to mythbackend |
| 59 | my $Myth = new MythTV(); |
| 60 | |
| 61 | # Get the list of recordings |
| 62 | my $count = 0; |
| 63 | my %rows = $Myth->backend_rows('QUERY_RECORDINGS Delete'); |
| 64 | our $show; |
| 65 | foreach my $row (@{$rows{'rows'}}) { |
| 66 | last unless (($count < $num_recordings) || ($num_recordings < 0)); |
| 67 | $show = new MythTV::Program(@$row); |
| 68 | # Skip LiveTV recordings? |
| 69 | next unless (defined($live) || $show->{'recgroup'} ne 'LiveTV'); |
| 70 | # Format the starttime |
| 71 | # Since format_name() formats for filenames, use "placeholders" for |
| 72 | # characters that are illegal on some filesystems. |
| 73 | my $starttime = $show->format_name('%nslash%j, %gcolon%i %A'); |
| 74 | $starttime =~ s/slash/\//; |
| 75 | $starttime =~ s/colon/:/; |
| 76 | if (defined($plain_text)) { |
| 77 | text_print($starttime); |
| 78 | } |
| 79 | else { |
| 80 | status_print($starttime, $count); |
| 81 | } |
| 82 | $count++; |
| 83 | } |
| 84 | |
| 85 | # Print the output for use in the backend status page. |
| 86 | sub status_print { |
| 87 | my $starttime = shift; |
| 88 | my $count = shift; |
| 89 | print("Recent Recordings:<div class=\"schedule\">") if ($count == 0); |
| 90 | print("<a href=\"#\">$starttime - $show->{'callsign'} - "); |
| 91 | print("$show->{'title'} - $show->{'subtitle'}<br />"); |
| 92 | print("<span><strong>$show->{'title'}</strong> $starttime<br />"); |
| 93 | print("<em>$show->{'subtitle'}</em><br /><br />"); |
| 94 | print("$show->{'description'}<br /></span></a><hr />"); |
| 95 | print("</div>") if ($count == ($num_recordings - 1)); |
| 96 | print("[]:[]recording$count"); |
| 97 | print("[]:[]$starttime - $show->{'title'} - $show->{'subtitle'}\n"); |
| 98 | } |
| 99 | |
| 100 | # Print the output in plain text format |
| 101 | sub text_print { |
| 102 | my $starttime = shift; |
| 103 | print("$starttime - $show->{'callsign'} - $show->{'title'} - "); |
| 104 | print("$show->{'subtitle'}\r\n$show->{'description'}\r\n\r\n"); |
| 105 | } |