diff options
author | Christian Pointner <equinox@helsinki.at> | 2013-02-21 14:24:06 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2013-02-21 14:24:06 (GMT) |
commit | c71a013af3f961195ce94ac0f2d2eb6285311f62 (patch) | |
tree | 4d653f4aa9a79fb47c43fae649d00c99f16ac6b3 | |
parent | 206a1b98bce0c0e4fa4936805aa88258a3c1fb8e (diff) |
updated radio attac for new cba
-rwxr-xr-x | rhimport-ra | 76 | ||||
-rwxr-xr-x | rhimport-rs | 3 |
2 files changed, 48 insertions, 31 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') { diff --git a/rhimport-rs b/rhimport-rs index f78fbb7..322d6fc 100755 --- a/rhimport-rs +++ b/rhimport-rs @@ -139,7 +139,6 @@ my $feed = XML::Feed->parse(URI->new($RSS_URL)) my $file = ""; my $out_file = ""; - my $i = 0; for my $entry ($feed->entries) { $i++; @@ -180,8 +179,8 @@ for my $entry ($feed->entries) { last; } - last if $file != ""; } + last if $file ne ""; } if($file eq "" || !(-e "$file")) { |