summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-10 18:03:58 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-10 18:03:58 (GMT)
commit1261b05589dabece7e16f1c8c7577a63e64ba4b3 (patch)
tree56c9f5234469a237cef566f1948b0d6ed6b4afb7
parentd804a7fa90fc101fba6a66d06faf6289d4ca9692 (diff)
added improved fetch code which allows to set the User Agent String
-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") {