diff options
Diffstat (limited to 'rhimport-ra')
-rwxr-xr-x | rhimport-ra | 76 |
1 files changed, 47 insertions, 29 deletions
diff --git a/rhimport-ra b/rhimport-ra index 102e61d..eeb1efd 100755 --- a/rhimport-ra +++ b/rhimport-ra @@ -33,7 +33,8 @@ use IO::Handle; use IPC::Open3; use HTML::Entities; -use lib '/usr/local/share/rhimport/'; +#use lib '/usr/local/share/rhimport/'; +use lib './'; use rhimport; my $DBHOST = "airplay"; @@ -42,7 +43,8 @@ my $DBPW = "lldriven"; my $DB = "rivendell"; my $STAT_FILE = $ENV{'HOME'} . "/rhimport-ra.stat"; -my $RSS_URL = "http://cba.fro.at/seriesrss/192"; +my $RSS_URL = "http://cba.fro.at/seriesrss/192?dev=true"; +$XML::Feed::MULTIPLE_ENCLOSURES=1; my $PV_ID = '76'; binmode(STDIN, ":utf8"); @@ -91,39 +93,55 @@ my $feed = XML::Feed->parse(URI->new($RSS_URL)) my $bdexp = sprintf("^(\\d+)\\..*\\s*0?%d\\s*\\.\\s*0?%d\\s*\\.\\s*%4d", $broadcast_day[2], $broadcast_day[1], $broadcast_day[0]); + my $file = ""; my $out_file = ""; +my $i = 0; for my $entry ($feed->entries) { - if($entry->enclosure && $entry->enclosure->type eq "audio/mpeg") { - my $sum_title = decode_entities($entry->title); - next unless $sum_title =~ /$bdexp/; - my $sum_text = decode_entities($entry->content->body); - my $bnum = $1; - - my $ff = File::Fetch->new(uri => $entry->enclosure->url); - next unless $bnum eq substr($ff->output_file, 0, 3); - my $current_file = `cat $STAT_FILE`; - if($current_file eq $ff->output_file) { - print "Already downloaded file of today\n"; - $dbh->disconnect(); - exit 0; + $i++; + next unless $entry->enclosure; + my $j = 0; + for my $enclosure($entry->enclosure) { + $j++; + if($enclosure->type eq "audio/mpeg" || $enclosure->type eq "audio/ogg") { + print "$i/$j: (" . $enclosure->type . ", " . $enclosure->length . ") " . $enclosure->url . "\n"; + my $url = $enclosure->url; + if($url =~ /^(.*)_cut(\.[^\.]+)$/) { + $url = $1 . $2; + } + + my $sum_title = decode_entities($entry->title); + next unless $sum_title =~ /$bdexp/; + my $sum_text = decode_entities($entry->content->body); + my $bnum = $1; + + my $ff = File::Fetch->new(uri => $url); + next unless $bnum eq substr($ff->output_file, 0, 3); + my $current_file = `cat $STAT_FILE`; + if($current_file eq $ff->output_file) { + print "Already downloaded file of today\n"; + $dbh->disconnect(); + exit 0; + } + $out_file = $ff->output_file; + + print " --> " . $bnum . ": downloading " . $url . " (" . $enclosure->length . " Bytes) .. "; + $file = $ff->fetch( to => '/tmp' ) or die $ff->error; + print "ok\n"; + + print "summary:\n" . $sum_title . "\n\n" . $sum_text . "\n"; + + rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date[0], $import_date[1], $import_date[2]), "1"); + print "\n"; + rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date_reb[0], $import_date_reb[1], $import_date_reb[2]), "2"); + print "\n"; + + last; } - $out_file = $ff->output_file; - - print $bnum . ": downloading " . $entry->enclosure->url . " (" . $entry->enclosure->length . " Bytes) .. "; - $file = $ff->fetch( to => '/tmp' ) or die $ff->error; - print "ok\n"; - - print "summary:\n" . $sum_title . "\n\n" . $sum_text . "\n"; - - rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date[0], $import_date[1], $import_date[2]), "1"); - print "\n"; - rhimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_date_reb[0], $import_date_reb[1], $import_date_reb[2]), "2"); - print "\n"; - - last; } + last if $file ne ""; } + if($file eq "" || !(-e "$file")) { print "No Entry found from $bd or download error - "; if($#ARGV >= 0 && $ARGV[0] eq 'last') { |