summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrhimport-oi3
-rw-r--r--rhimport.pm22
2 files changed, 23 insertions, 2 deletions
diff --git a/rhimport-oi b/rhimport-oi
index b2d5377..3ed4e5b 100755
--- a/rhimport-oi
+++ b/rhimport-oi
@@ -32,7 +32,6 @@ use File::Fetch;
use IO::Handle;
use IPC::Open3;
use HTML::Entities;
-use LWP::Simple;
use lib '/usr/local/share/rhimport/';
use rhimport;
@@ -98,7 +97,7 @@ if($current_id eq $id) {
print "looking for files like '$bdfile' in RSS Feed\n";
print " -> $RSS_URL\n";
-my $feed = XML::Feed->parse(URI->new($RSS_URL))
+my $feed = rhimport::fetch_parse_rss($RSS_URL)
or die "Error fetching feed: " . XML::Feed->errstr;
my $file = "";
diff --git a/rhimport.pm b/rhimport.pm
index 6181f56..c9035c0 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -33,6 +33,8 @@ use URI::Escape;
use POSIX;
use DateTime;
use DateTime::TimeZone;
+use LWP::Simple;
+use XML::Feed;
my $ssh_host = "airplay";
my $ssh_user = "rhimport";
@@ -67,6 +69,26 @@ sub get_rd_week
return $week;
}
+sub fetch_parse_rss
+{
+ my ($url, $ua_str) = @_;
+
+ my $uri = URI->new($url);
+ $ua_str = "Radio Helsinki - Automatic Import" unless $ua_str;
+
+ my $ua = LWP::UserAgent->new;
+ $ua->agent($ua_str);
+ $ua->env_proxy;
+ my $res = URI::Fetch->fetch($uri, UserAgent => $ua)
+ or die URI::Fetch->errstr;
+ die "This feed has been permanently removed"
+ if $res->status == URI::Fetch::URI_GONE();
+
+ my $xml = $res->content;
+
+ return XML::Feed->parse(\$xml);
+}
+
sub check_key_file
{
if(-e "$ssh_key_file") {