#!/usr/bin/perl -w # # Retrieves previews for all MythTV recordings # # Includes use DBI; use Getopt::Long; use MythTV; # Some variables we'll use here our ($test, $format, $sleep, $width, $height, $offset); our ($dformat, $dsleep, $dwidth, $dheight, $doffset, $dport, $usage); our ($dbh, $sh, $query); our (%hosts); # Default format of URL $dformat='http://{HOST}:{PORT}/Myth/GetPreviewImage'. '?ChanId=%c&StartTime=%Y-%m-%dT%H:%i:%s'. '&Height={HEIGHT}&Width={WIDTH}&SecsIn={OFFSET}'; $dsleep=5; $dwidth=0; $dheight=100; $doffset=155; $dport=6544; # Provide default values for GetOptions $format = $dformat; $sleep = $dsleep; $width = $dwidth; $height = $dheight; $offset = $doffset; # Load the cli options GetOptions('test' => \$test, 'format=s' => \$format, 'sleep=i' => \$sleep, 'width=i' => \$width, 'height=i' => \$height, 'seconds|secs_in|secsin|offset=i' => \$offset, 'usage|help' => \$usage ); # Print usage if ($usage) { print <{'dbh'}; END { $sh->finish if ($sh); } # Get the backend(s) hostname/IP address/status port information $query = "SELECT hostname, data FROM settings WHERE value = ?;"; $sh = $dbh->prepare($query); my @row; if ($sh->execute('BackendServerIP')) { while (@row = $sh->fetchrow_array) { $hosts->{$row[0]}->{'ip'} = $row[1]; } } if ($sh->execute('BackendStatusPort')) { while (@row = $sh->fetchrow_array) { $hosts->{$row[0]}->{'port'} = $row[1]; } } # Get the list of recordings my %rows = $Myth->backend_rows('QUERY_RECORDINGS Delete'); our $show; foreach my $row (@{$rows{'rows'}}) { $show = new MythTV::Program(@$row); get_preview(); if ($sleep > 0) { sleep $sleep; } } $sh->finish if ($sh); # Get the preview sub get_preview { my $text = $show->format_name($format, ' ', ' ', 1, 0 , 1); my $host = $show->{'hostname'}; my $ip = $hosts->{$host}->{'ip'}; my $port = $hosts->{$host}->{'port'}; if (defined($ip)) { $text =~ s/{HOST}/$ip/g; } else { $text =~ s/{HOST}/$show->{'hostname'}/g; } if (defined($port)) { $text =~ s/{PORT}/$port/g; } else { $text =~ s/{PORT}/$dport/g; } $text =~ s/{WIDTH}/$width/g; $text =~ s/{HEIGHT}/$height/g; $text =~ s/{OFFSET}/$offset/g; my $filename = $show->format_name('%c_%Y%m%d%H%i%s', '-', '-', 1, 0 , 0); print("URI: $text\n"); if (! $test) { print("Requesting preview:\n"); system("wget \'$text\' -O \'$filename.png\'\n"); } }