Sunday 6 November 2011

Mythtv - Perl script to email the recordings list.

Hi All,

So, I don't want my new recordings list being available on t'interwebs, but I do have my own email server.

So I wrote some perl to parse the RSS feed and email me the results. I stuck this to a cron job and now I get a weekly email with the new recordings on.

It does need tweaking, I only want the newest recorded programs email to me. Currently this emails the lot to me. Anyway, here's the code:

#!/usr/bin/perl

use LWP::Simple;

#to read html streams

use strict;


use Mail::Sender;

my $emailmsg;


my $sender;


print "Getting Content\n";

my $content = get('http://localhost/mythweb/rss/tv/recorded') || die print "Oh fuck it";


#print $content;



$content =~ s/[^[:ascii:]]+//g; #get rid of weird chars

print 'Splitting atoms...oh LOL :-)';


print "\n";



my @lines = split(//, $content);



print "Parsing some stuff\n";

for my $line (@lines){


#print $line =~ /\(.*)\<\/title\>/;


$line =~ /\(.*)\<\/title\>/;


$emailmsg .= $1;


$line =~ /\(.*)\<\/pubDate\>/;


$emailmsg .= " - " . $1;


$emailmsg .= "\n";


#print $line =~ /\\<\!\[CDATA\[(.*)\]\]\>\<\/description\>/;


$line =~ /\\<\!\[CDATA\[(.*)\]\]\>\<\/description\>/;


$emailmsg .= $1;


$emailmsg .= "\n\n\n";


#print $emailmsg;


}




#(my $headlines) = ($content =~ /type\=\"html\"\>(.*)\<\/title\>/);


#print "$headlines\n";


$sender = new Mail::Sender {


smtp => 'IP or server address',


from => 'address@tosend.from',


auth => 'NTLM',


authid => 'username',


authpwd => 'password',


on_errors => undef,


}


or die "Can't create the Mail::Sender object: $Mail::Sender::Error\n";


$sender->Open({


to => 'who@tosendit.to',


subject => 'Mythtv recordings update'


})


or die "Can't open the message: $sender->{'error_msg'}\n";


$sender->SendLineEnc("$emailmsg");


$sender->Close()


or die "Failed to send the message: $sender->{'error_msg'}\n";



There you go. I've left my commented code in so you can see where I was going with it.

Thanks for reading,