2009-04-11 Andrew Ruthven
Show the encoder details for "Recording Now".
+ Pass on that charset that MythTV gave us in any emails we send.
2009-03-31 Andrew Ruthven
Add support for the newer encoder statuses.
# Display the current status of a MythTV system.
-use LWP::Simple;
+use LWP::UserAgent;
use XML::LibXML;
use Date::Manip;
use Getopt::Long;
}
# A couple of global variables
-my ($xml, $myth);
+my ($xml, $charset, $myth);
my %version;
my $exit_value = 0;
my $result = undef;
$warn_present = 0;
if ($block->{'type'} eq 'xpath') {
- $xml ||= load_xml();
+ ($xml, $charset) = load_xml()
+ unless defined $xml;
$result = process_xml($block, $xml);
my $mail = MIME::Entity->build(
To => $c->{'email'},
Subject => $title . (defined $suffix ? " - $suffix" : ''),
+ Charset => $charset,
Data => $output
);
# Fetch the XML status from the backend.
sub load_xml {
- my $status = "";
+ my $status = '';
+ my $charset = '';
if (defined $c->{'xml_file'}) {
open (IN, "< $c->{'xml_file'}")
close IN;
} else {
my $url = "http://$c->{'host'}:$c->{'port'}/xml";
+ my $ua = LWP::UserAgent->new;
+ $ua->timeout(30);
+ $ua->env_proxy;
+ my $response;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm(30);
- $status = get($url);
+ $response = $ua->get($url);
alarm(0);
};
die "Sorry, failed to fetch $url: Connection to MythTV timed out.\n"
if $@;
- die "Sorry, failed to fetch $url.\n"
- unless defined $status;
+ die "Sorry, failed to fetch $url:\n" . $response->status_line . "\n"
+ unless $response->is_success;
+
+ $status = $response->decoded_content;
+ my $content_type = $response->header('Content-Type');
+ ($charset) = ($content_type =~ /charset="(\S+?)"/);
}
# Parse the XML
warn "Loaded XML from " . ($c->{'xml_file'} || $c->{'host'}) . "\n"
if $verbose;
- return $xml;
+ return ($xml, $charset);
}
# Prep the Perl MythTV API if available.