diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-07-27 15:21:19 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-07-27 15:21:19 (GMT) |
commit | a8f6402277ba286ae05c3dd66b1cce36e62db8f8 (patch) | |
tree | 3f009851bb747b24fd185d3364fe54255052dbfd /rhimport-eu | |
parent | 33af310d21e835c369d0cdfa4fa1e492326b5e47 (diff) |
economic update now uses a new rss feed
Diffstat (limited to 'rhimport-eu')
-rwxr-xr-x | rhimport-eu | 100 |
1 files changed, 48 insertions, 52 deletions
diff --git a/rhimport-eu b/rhimport-eu index 4678846..cfc329f 100755 --- a/rhimport-eu +++ b/rhimport-eu @@ -39,7 +39,7 @@ my $DBPW = "lldriven"; my $DB = "rivendell"; my $STAT_FILE = $ENV{'HOME'} . "/rhimport-eu.stat"; -my $API_URL = "https://api.audioboom.com/users/3848170/audio_clips"; +my $RSS_URL = "http://economicupdate.libsyn.com/rss"; my $PV_ID = '568'; my $LAST_RUN = 0; @@ -92,65 +92,61 @@ if(Date::Calc::Delta_Days(@broadcast_date, @today) <= 0) { my $id = sprintf("%04d-%02d-%02d", @import_date); my $bd = sprintf("%04d-%02d-%02d", @broadcast_date); -print "looking for files after $bd in Audioboom Clips\n"; -print " -> $API_URL\n"; +print "looking for files issued after $bd in RSS-Feed\n"; +print " -> $RSS_URL\n"; -my %h = ( 'Accept' => 'application/json; version=1' ); -my ($result, $data) = rhimport::fetch_parse_json($API_URL, "Radio Helsinki - Automatic Import", \%h); -unless ($result) { - print "Error fetching data: $data\n"; - $dbh->disconnect(); - exit 1; -} - -my @clips = @{$data->{'body'}{'audio_clips'}}; - -my $titleexp = "^Economic\\s+Update\\s*:"; +my $feed = rhimport::fetch_parse_rss($RSS_URL) + or die "Error fetching feed: " . XML::Feed->errstr; my $file = ""; my $out_file = ""; -for my $clip (@clips) { - my $sum_title = decode_entities($clip->{title}); - next unless $sum_title =~ /$titleexp/; - - my $recorded = $clip->{recorded_at}; - next unless (defined $recorded); - my $rdt = DateTime::Format::ISO8601->parse_datetime($recorded); - print " Title: $sum_title (Recorded: " . $rdt . ")\n"; - - my @recoreded_date = ($rdt->year, $rdt->month, $rdt->day); - next if(Date::Calc::Delta_Days(@broadcast_date, @recoreded_date) < 0); - - my $orig_uri = $clip->{urls}{high_mp3}; - next unless $orig_uri; - - my $uri = new URI::URL($orig_uri); - my @path = $uri->path_components; - - my $current_file = `cat $STAT_FILE`; - if($current_file eq $path[-1]) { - print "Already downloaded file of today\n"; - $dbh->disconnect(); - exit 0; - } +for my $entry ($feed->entries) { + next unless $entry->enclosure; + + my $sum_title = decode_entities($entry->title); + my $issued = $entry->issued; + next unless (defined $issued); + my $idt = DateTime::Format::ISO8601->parse_datetime($issued); + print " Title: $sum_title (Issued: " . $idt . ")\n"; + + my @issued_date = ($idt->year, $idt->month, $idt->day); + next if(Date::Calc::Delta_Days(@broadcast_date, @issued_date) < 0); + + my $j = 0; + for my $enclosure($entry->enclosure) { + $j++; + if($enclosure->type eq "audio/mpeg" || $enclosure->type eq "audio/ogg") { + my $orig_uri = $enclosure->url; + my $uri = new URI::URL($orig_uri); + my @path = $uri->path_components; + + my $current_file = `cat $STAT_FILE`; + if($current_file eq $path[-1]) { + print "Already downloaded file of today\n"; + $dbh->disconnect(); + exit 0; + } $out_file = $path[-1]; - if(!rhimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - $dbh->disconnect(); - exit 1; - } - - print " --> " . $bd . ": downloading " . $orig_uri . " .. "; - $file = "/tmp/" . $out_file; - system("wget", "--quiet", "--no-check-certificate", $orig_uri, "-O", $file); - if( $! != 0) { - $dbh->disconnect(); - die "wget returned with error: " . $!; + if(!rhimport::check_file_extension($out_file)) { + print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; + $dbh->disconnect(); + exit 1; + } + print " $j: (" . $enclosure->type . ", " . $enclosure->length . ") " . $out_file . "\n"; + print " --> downloading " . $orig_uri . " .. "; + $file = "/tmp/" . $out_file; + system("wget", "--quiet", "--no-check-certificate", $orig_uri, "-O", $file); + if( $! != 0) { + $dbh->disconnect(); + die "wget returned with error: " . $!; + } + print "ok\n"; + last; + } } - print "ok\n"; - last + last unless($file eq ""); } if($file eq "" || !(-e "$file")) { |