diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-03-12 03:33:13 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-03-12 03:33:13 (GMT) |
commit | 92f99dc3c3b1e8658b958130a6cad9928756dc0b (patch) | |
tree | af643ada9df71c295d6addc9a410cae091497c46 | |
parent | e73cabd24fcff576ba0fc503b1792082842111d7 (diff) |
remove old (no longer used) importer
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | fetch-feeds-frn.pl | 49 | ||||
-rwxr-xr-x | fetch-files-cba.pl | 87 | ||||
-rwxr-xr-x | rhautoimport-fe | 204 | ||||
-rwxr-xr-x | rhautoimport-fw | 219 | ||||
-rwxr-xr-x | rhautoimport-mz | 247 | ||||
-rwxr-xr-x | rhautoimport-o94n | 209 | ||||
-rwxr-xr-x | rhautoimport-sm | 213 | ||||
-rwxr-xr-x | rhautoimport-sv | 212 | ||||
-rwxr-xr-x | rhautoimport-ut | 199 | ||||
-rwxr-xr-x | rhautoimport-zf | 193 | ||||
-rwxr-xr-x | rhautoimport-zffe | 118 | ||||
-rwxr-xr-x | rhautoimport-zfw | 195 |
13 files changed, 1 insertions, 2146 deletions
@@ -26,7 +26,7 @@ endif .PHONY: clean distclean EXECUTABLE := rhautoimport -IMPORTER := btl dn fe fw mz nw oi o94n rs ra sm sv tr ut zf zffe zfw +IMPORTER := btl dn nw oi rs ra tr EXECUTABLES := $(IMPORTER:%=$(EXECUTABLE)-%) all: $(EXECUTABLE) diff --git a/fetch-feeds-frn.pl b/fetch-feeds-frn.pl deleted file mode 100755 index c67f799..0000000 --- a/fetch-feeds-frn.pl +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use XML::Feed; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); -$| = 1; - -my $RSS_URL_BASE = "http://freie-radios.net/portal/podcast.php?rss&serie="; -my $i = 1; -my $empty = 0; -while($empty < 100) { - my $feed = XML::Feed->parse(URI->new($RSS_URL_BASE . $i)) - or die "Error fetching feed: " . XML::Feed->errstr; - - if($feed->title eq "freie-radios.net ()") { - $empty++; - $i++; - next; - } else { - $empty = 0; - } - - print $i . ":" . $feed->title . "\n"; - $i++; -} diff --git a/fetch-files-cba.pl b/fetch-files-cba.pl deleted file mode 100755 index fec911d..0000000 --- a/fetch-files-cba.pl +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use HTML::Entities; - -$XML::Feed::MULTIPLE_ENCLOSURES=1; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if(@ARGV == 0) { - print "You have to supply a Series ID\n"; - exit 1; -} - -my $RSS_URL = "http://cba.fro.at/seriesrss/$ARGV[0]?c=Kfs2IoV2Wmd&limit=10000"; -print "Fetching files form '$RSS_URL'\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $i = 1; -for my $entry ($feed->entries) { - if($entry->enclosure) { - my $sum_title = decode_entities($entry->title); - my $sum_text = decode_entities($entry->content->body); - my $j = 1; - for my $enclosure ($entry->enclosure) { - 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; - } - - # if($i <= 100) { - # print" --> skipping " . $url . "\n"; - # last; - # } - - my $ff = File::Fetch->new(uri => $url); - print " --> downloading " . $url . " (" . $enclosure->length . " Bytes) .. "; - my $file = $ff->fetch() or die $ff->error; - print "ok\n"; - my $notefile = $file . "_notes"; - - unlink($notefile); - open(my $fhs, '>', $notefile); - binmode($fhs, ":utf8"); - print $fhs $sum_title . "\n\n" . $sum_text . "\n"; - close($fhs); - - last; - } - $j++; - } - print "\n"; - $i++; - } -} diff --git a/rhautoimport-fe b/rhautoimport-fe deleted file mode 100755 index 1a82814..0000000 --- a/rhautoimport-fe +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Date::Calc; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use IO::Handle; -use IPC::Open3; -use HTML::Entities; -use File::Touch; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-fe.stat"; -my $NOTE_FILE = $ENV{'HOME'} . "/rhautoimport-fe.last_note"; -my $NEW_FILE = $ENV{'HOME'} . "/rhautoimport-fe.is_new"; -my $RSS_URL = "http://freie-radios.net/portal/podcast.php?serie=208&rss"; -#my $PV_ID = '359'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my @today = Date::Calc::Today(); -my $dow = Date::Calc::Day_of_Week(@today); -my @tomorrow = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], 1); - -my @tmp = Date::Calc::Standard_to_Business(@today); -$tmp[2] = 1; -my @this_mon = Date::Calc::Business_to_Standard(@tmp); -my @next_mon = Date::Calc::Add_Delta_Days($this_mon[0], $this_mon[1], $this_mon[2], 7); - -my @broadcast_day = @today; -my @import_day = @tomorrow; -if ($dow == 5) { - @import_day = @next_mon; -} - -print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\n"; -print "day of Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_day) . "\n"; - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; -my $group = "vonunten"; -$dow = Date::Calc::Day_of_Week(@import_day); -$group .= "Mo" if($dow == 1); -$group .= "Di" if($dow == 2); -$group .= "Mi" if($dow == 3); -$group .= "Do" if($dow == 4); -$group .= "Fr" if($dow == 5); - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} -my $dropbox = ""; -my $to_cart = 0; - -if(scalar(@allowed_dbs) == 0) { - print "no dropbox for day in question\n"; - RHRD::rddb::closedb($dbh); - exit 0; -} -if(scalar(@allowed_dbs) != 1) { - print "found more or less than one Dropbox for this group?!\n"; - RHRD::rddb::closedb($dbh); - exit 1; -} -$dropbox = $allowed_dbs[0]->{'PATH'}; -$to_cart = $allowed_dbs[0]->{'TO_CART'}; - -my $regexp = sprintf('%04d%02d%02d.*\.mp3', $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]); -print "looking for file from " . Date::Calc::Date_to_Text(@broadcast_day) . " in RSS Feed\n"; -print " -> $RSS_URL\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $file = ""; -my $out_file = ""; -for my $entry ($feed->entries) { - if($entry->enclosure && $entry->enclosure->type eq "audio/mpeg") { - next unless $entry->enclosure->url =~ /$regexp/; - next unless $entry->enclosure->length >= (20*1024*1024); - - my $sum_title = decode_entities($entry->title); - my $sum_text = decode_entities($entry->content->body); - - my $ff = File::Fetch->new(uri => $entry->enclosure->url); - my $current_file = `cat $STAT_FILE`; - if($current_file eq $ff->output_file) { - print "Already downloaded file of today\n"; - RHRD::rddb::closedb($dbh); - exit 0; - } - $out_file = $ff->output_file; - if(!rhautoimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - RHRD::rddb::closedb($dbh); - exit 1; - } - - print $regexp . ": 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"; - - # if($#ARGV >= 0 && $ARGV[0] eq 'nopv') { - # print "not adding note to PV\n"; - # } else { - # rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", $import_day[0], $import_day[1], $import_day[2]), "1"); - # } - # print "\n"; - - unlink($NOTE_FILE); - open(my $fhs, '>', $NOTE_FILE); - binmode($fhs, ":utf8"); - print $fhs $sum_title . "\n\n" . $sum_text . "\n"; - close($fhs); - - last; - } -} -if($file eq "" || !(-e "$file")) { - print "No Entry found for " . Date::Calc::Date_to_Text(@broadcast_day) . " or download error - "; - if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "giving up, manual import necessary!!!\n"; - } else { - print "will retry later\n"; - } - exit 1; -} - -print "will import $file to dropbox $dropbox (cart=$to_cart)\n"; - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret; -my $log = rhautoimport::clear_carts($dbh, $group, $to_cart); -my $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); -$log .= $import_log; - -RHRD::rddb::closedb($dbh); - -unlink $file; - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs $out_file; -close($fhs); -touch($NEW_FILE); - -exit 0; diff --git a/rhautoimport-fw b/rhautoimport-fw deleted file mode 100755 index 2e9e932..0000000 --- a/rhautoimport-fw +++ /dev/null @@ -1,219 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Date::Calc; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use IO::Handle; -use IPC::Open3; -use HTML::Entities; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-fw.stat"; -my $LAST_FILE = $ENV{'HOME'} . "/rhautoimport-fw.last"; -my $RSS_URL = "http://cba.fro.at/seriesrss/263965?c=Kfs2IoV2Wmd"; -$XML::Feed::MULTIPLE_ENCLOSURES=1; -my $PV_ID = '382'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; -my $group = "freiewelle"; - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} - -my $idx = 0; -my $idx_reb = 1; -if(scalar(@allowed_dbs) != 2) { - print "found more or less than 2 Dropboxes for this group?!\n"; - RHRD::rddb::closedb($dbh); - exit 1; -} -my $dropbox = $allowed_dbs[$idx]->{'PATH'}; -my $to_cart = $allowed_dbs[$idx]->{'TO_CART'}; -my $dropbox_reb = $allowed_dbs[$idx_reb]->{'PATH'}; -my $to_cart_reb = $allowed_dbs[$idx_reb]->{'TO_CART'}; - -my @import_date = Date::Calc::Standard_to_Business(Date::Calc::Today()); -if($import_date[2] != 1) { - $import_date[2] = 1; - @import_date = Date::Calc::Business_to_Standard(@import_date); - @import_date = Date::Calc::Add_Delta_Days(@import_date, 7); -} else { - @import_date = Date::Calc::Business_to_Standard(@import_date); -} -my @import_date_reb = Date::Calc::Add_Delta_Days(@import_date, 4); - -print "day of next broadcast: " . Date::Calc::Date_to_Text(@import_date) . "\n"; -print "day of next rebroadcast: " . Date::Calc::Date_to_Text(@import_date_reb) . "\n"; - -my $id = sprintf("%04d-%02d-%02d", @import_date); -my $bnum = `cat $LAST_FILE`; -$bnum += 1; - -my $current_stat = `cat $STAT_FILE`; -my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/; -if($current_id eq $id) { - print "Already downloaded current file\n"; - RHRD::rddb::closedb($dbh); - exit 0; -} - -print "looking for file with number $bnum in RSS Feed\n"; -print " -> $RSS_URL\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $bdexp = sprintf("^(\\d+)", $bnum); - - -my $file = ""; -my $out_file = ""; -my $i = 0; -for my $entry ($feed->entries) { - $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 $ff = File::Fetch->new(uri => $url); - next unless (uc($ff->output_file) =~ /$bdexp/); # file not from correct day - next unless ($bnum == $1); - - my $sum_title = decode_entities($entry->title); - my $sum_text = decode_entities($entry->content->body); - - my $current_file = `cat $STAT_FILE`; - if($current_file eq $ff->output_file) { - print "Already downloaded current file\n"; - RHRD::rddb::closedb($dbh); - exit 0; - } - $out_file = $ff->output_file; - if(!rhautoimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - RHRD::rddb::closedb($dbh); - exit 1; - } - - 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"; - - rhautoimport::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"; - rhautoimport::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 or download error - "; - if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "giving up, manual import necessary!!!\n"; - } else { - print "will retry later\n"; - } - exit 1; -} - -print "will import $file to dropbox $dropbox (cart=$to_cart)\n"; -print "will import $file to rebroadcast dropbox $dropbox_reb (cart=$to_cart_reb)\n\n"; - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret; -my $log = rhautoimport::clear_carts($dbh, $group, $to_cart); -my $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); -$log .= $import_log; -$import_log = rhautoimport::clear_carts($dbh, $group, $to_cart_reb); -$log .= $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox_reb, $user, 0, $error_cb); -$log .= $import_log; - -RHRD::rddb::closedb($dbh); - -unlink $file; - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs "$id\n$out_file"; -close($fhs); - -unlink($LAST_FILE); -open($fhs, '>', $LAST_FILE); -print $fhs "$bnum"; -close($fhs); - -exit 0; diff --git a/rhautoimport-mz b/rhautoimport-mz deleted file mode 100755 index 1ed47dc..0000000 --- a/rhautoimport-mz +++ /dev/null @@ -1,247 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Switch; -use Date::Calc; -use Time::localtime; -use IO::Handle; -use IPC::Open3; -use File::Slurp; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - - -my @STATIC_FILES = ($ENV{'HOME'} . "/frontex", $ENV{'HOME'} . "/maribor" ); - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-mz.stat"; -my $ZF_NOTE_FILE = $ENV{'HOME'} . "/rhautoimport-zf.last_note"; -my $ZF_NEW_FILE = $ENV{'HOME'} . "/rhautoimport-zf.is_new"; -my $PV_ID = '352'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; - -my @today = Date::Calc::Today(); -my @next_day = Date::Calc::Add_Delta_Days(@today, 1); -my $dow = Date::Calc::Day_of_Week(@today); -if($dow == 5) { - @next_day = Date::Calc::Add_Delta_Days(@today, 3); -} - -print "today: " . Date::Calc::Date_to_Text(@today) . "\n"; -print "next day would be: " . Date::Calc::Date_to_Text(@next_day) . "\n"; -my @import_day = @next_day; -if(localtime->hour < 12) { - print "It's forenoon, assuming to import for today\n"; - @import_day = @today; -} -print "day of broadcast: " . Date::Calc::Date_to_Text(@import_day) . "\n"; - - -$dow = Date::Calc::Day_of_Week(@import_day); -my $group = ""; -switch($dow) { - case 1 { $group = "mahlzeitMo" } - case 2 { $group = "mahlzeitDi" } - case 3 { $group = "mahlzeitMi" } - case 4 { $group = "mahlzeitDo" } - case 5 { $group = "mahlzeitFr" } - else { print("invalid day of week?!\n"); exit 1; } -} - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} - -if(scalar(@allowed_dbs) != 1) { - print "found no or more than one Dropboxes for this group?!\n"; - RHRD::rddb::closedb($dbh); - exit 1; -} -my $dropbox = $allowed_dbs[0]->{'PATH'}; - - -my $import_date = sprintf("%04d-%02d-%02d", @import_day); -my $current_date = `cat $STAT_FILE`; -if($current_date eq $import_date) { - print "Already downloaded file of day in question\n"; - RHRD::rddb::closedb($dbh); - exit 0; -} - -unless(-e $ZF_NEW_FILE) { - print "zip-fm not imported yet - "; - if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "giving up, rebroadcasting last show"; - } else { - print "will retry later\n"; - exit 0, - } -} - - -sub read_first_line { - my ($file) = @_; - my @lines = read_file($file, binmode => ':utf8', err_mode => 'quiet'); - return "" unless ($lines[0]); - - chomp($lines[0]); - return $lines[0]; -}; - -sub get_note { - my ($file) = @_; - my @lines = read_file($file, binmode => ':utf8', err_mode => 'quiet'); - return "" unless ($lines[0]); - - chomp($lines[0]); - $lines[0] = "<p><strong>$lines[0]</strong></p>\n"; - return join('',@lines); -}; - -sub find_next_file { - my ($dir, $current) = @_; - - my %files = (); - opendir(my $dh, $dir) or die $!; - while (my $file = readdir($dh)) { - next if ($file =~ m/^\./); - next if ($file =~ m/_notes$/); - $files{$file} = 1; - } - closedir($dh); - - my $num = scalar keys %files; - foreach my $file (sort keys %files) { - if($file gt $current) { - return $num, $file; - } - $num--; - } - - return 0, ""; -}; - -my $sum_title = "zip-fm (WH)"; -my $sum_text = get_note($ZF_NOTE_FILE) . "<br/>\n"; - -print "\nsearching local files:\n"; - -my @files = (); -my %next_files = (); -foreach my $dir (@STATIC_FILES) { - my $file = read_first_line("$dir/.current"); - if($file eq "") { - print " $dir: skipped !!! (no .current file or no more files)\n"; - next; - } - my ($remaining, $next_file) = find_next_file($dir, $file); - if($remaining >= 1) { - print " $dir: adding $file\n (next: $next_file, $remaining files remaining)\n"; - } else { - print " $dir: adding $file\n (this was the last file!!!!)\n"; - } - $next_files{$dir} = $next_file; - - $sum_title = "$sum_title, " . read_first_line("$dir/.sum_title"); - $sum_text = $sum_text . "<br />\n" . get_note("$dir/$file" . "_notes"); - foreach my $ext ("flac", "wav", "ogg", "mp3") { - push(@files, "$dir/.jingle.$ext") if(-e "$dir/.jingle.$ext"); - } - push(@files, "$dir/$file"); -} -$sum_text = $sum_text . "<br/><br/>\n"; - -print "\nsummary:\n" . $sum_title . "\n\n" . $sum_text . "\n"; -rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_day), "1"); -print "\n"; - - -print "will import " . join(", ", @files) . " to dropbox $dropbox\n"; - - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret = 1; -my $log = rhautoimport::clear_carts($dbh, $group, 0); -my ($cart, $high_cart) = rhautoimport::get_cart_range($dbh, $group); -foreach my $file (@files) { - if($cart > $high_cart) { - print "not enough carts - will ignore remaining files!!!"; - last; - } - print " importing $file to cart $cart\n"; - my $import_log; - ($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); - $log .= $import_log; - last unless $ret; - - $cart++; -} - -RHRD::rddb::closedb($dbh); - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs $import_date; -close($fhs); - -unlink($ZF_NEW_FILE); -foreach my $dir (@STATIC_FILES) { - open(my $fhs, '>', "$dir/.current"); - print $fhs $next_files{$dir} if ($next_files{$dir}); - close($fhs); -} - -exit 0; diff --git a/rhautoimport-o94n b/rhautoimport-o94n deleted file mode 100755 index 287dee4..0000000 --- a/rhautoimport-o94n +++ /dev/null @@ -1,209 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Date::Calc; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use IO::Handle; -use IPC::Open3; -use HTML::Entities; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-o94n.stat"; -my $RSS_URL = "http://cba.fro.at/seriesrss/264131?c=Kfs2IoV2Wmd"; -$XML::Feed::MULTIPLE_ENCLOSURES=1; -my $PV_ID = '430'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; -my $group = "o94"; - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} - - -my $dropbox = ''; -my $to_cart = 0; - -for my $db (@allowed_dbs) { - if($db->{'PATH'} =~ /^\/programm\/02/) { - $to_cart = $db->{'TO_CART'}; - $dropbox = $db->{'PATH'}; - last; - } -} -if($to_cart == 0) { - print "no dropbox found for Tuesday?!\n"; - RHRD::rddb::closedb($dbh); - exit 1; -} - - -my @today = Date::Calc::Today(); -my @yesterday = Date::Calc::Add_Delta_Days(@today, -1); -my @tomorrow = Date::Calc::Add_Delta_Days(@today, 1); -my $dow = Date::Calc::Day_of_Week(@today); - -my @broadcast_day; -my @import_date; -if($dow == 1) { - @broadcast_day = @today; - @import_date = @tomorrow; -} elsif ($dow == 2) { - @broadcast_day = @yesterday; - @import_date = @today; -} else { - print "Wrong Day! Check cron script!\n"; - exit 1; -} - -print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\n"; -print "day of Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_date) . "\n"; - -my $id = sprintf("%04d-%02d-%02d", @import_date); -my $bd = sprintf("%04d-%02d-%02d", @broadcast_day); -my $bdfile = sprintf("^NACHRICHTEN%04d%02d%02d", @broadcast_day); - -print "looking for files from $bd in RSS Feed\n"; -print " -> $RSS_URL\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $file = ""; -my $out_file = ""; -my $i = 0; -for my $entry ($feed->entries) { - $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 $ff = File::Fetch->new(uri => $url); - next unless (uc($ff->output_file) =~ $bdfile); # file not from correct day - - my $sum_title = decode_entities($entry->title); - $sum_title =~ s/\s*\(ganze sendung\)//i; - my $sum_text = decode_entities($entry->content->body); - - my $current_file = `cat $STAT_FILE`; - if($current_file eq $ff->output_file) { - print "Already downloaded file of today\n"; - RHRD::rddb::closedb($dbh); - exit 0; - } - $out_file = $ff->output_file; - if(!rhautoimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - RHRD::rddb::closedb($dbh); - exit 1; - } - - print " --> " . $bdfile . ": 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"; - - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_date), "1"); - 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') { - print "giving up, manual import necessary!!!\n"; - } else { - print "will retry later\n"; - } - exit 1; -} - -print "will import $file to dropbox $dropbox (cart=$to_cart)\n"; - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret; -my $log = rhautoimport::clear_carts($dbh, $group, $to_cart); -my $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); -$log .= $import_log; - -RHRD::rddb::closedb($dbh); - -unlink $file; - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs $out_file; -close($fhs); - -exit 0; diff --git a/rhautoimport-sm b/rhautoimport-sm deleted file mode 100755 index d54718b..0000000 --- a/rhautoimport-sm +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Date::Calc; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use IO::Handle; -use IPC::Open3; -use HTML::Entities; -use LWP::Simple; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-sm.stat"; -my $RSS_URL = "http://cba.fro.at/seriesrss/263673?c=Kfs2IoV2Wmd"; -$XML::Feed::MULTIPLE_ENCLOSURES=1; -my $PV_ID = '304'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; -my $group = "soundsmove"; - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} - -if(scalar(@allowed_dbs) != 1) { - print "found more or less than one Dropbox for this group?!\n"; - RHRD::rddb::closedb($dbh); - exit 1; -} -my $dropbox = $allowed_dbs[0]->{'PATH'}; -my $to_cart = $allowed_dbs[0]->{'TO_CART'}; - -my $curweek = RHRD::utils::get_rd_week(); - -my @today = Date::Calc::Today(); -my $dow = Date::Calc::Day_of_Week(@today); -if(($curweek != 1 && $curweek != 4) || - ($curweek == 1 && $dow > 3) || - ($curweek == 4 && $dow <= 3)) { - print "File won't be available by now!\n"; - RHRD::rddb::closedb($dbh); - exit 0; -} -print "today: " . Date::Calc::Date_to_Text(@today) . "\n"; - -my @import_date = Date::Calc::Standard_to_Business(@today); -$import_date[2] = 3; -@import_date = Date::Calc::Business_to_Standard(@import_date); -if($curweek == 4) { - @import_date = Date::Calc::Add_Delta_Days(@import_date, 7); -} -print "day of next Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_date) . "\n"; - -my @broadcast_date = Date::Calc::Nth_Weekday_of_Month_Year($import_date[0], $import_date[1], 3, 1); -if(Date::Calc::Delta_Days(@broadcast_date, @import_date) <= 0) { - my @tmp_date = Date::Calc::Add_Delta_YM(@broadcast_date, 0, -1); - @broadcast_date = Date::Calc::Nth_Weekday_of_Month_Year($tmp_date[0], $tmp_date[1], 3, 1); -} -print "day of latest original broadcast before next Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@broadcast_date) . "\n"; - -if(Date::Calc::Delta_Days(@broadcast_date, @today) <= 0) { - print "File won't be available by now!\n"; - RHRD::rddb::closedb($dbh); - exit 0; -} - -my $id = sprintf("%04d-%02d-%02d", @import_date); -my $bd = sprintf("%04d-%02d-%02d", @broadcast_date); -my $bdfile = sprintf("%04d-?%02d-?%02d", @broadcast_date); - -print "looking for files from $bd in RSS Feed\n"; -print " -> $RSS_URL\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $file = ""; -my $out_file = ""; -my $i = 0; -for my $entry ($feed->entries) { - $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 $ff = File::Fetch->new(uri => $url); - next unless (uc($ff->output_file) =~ $bdfile); # file not from correct day - - my $sum_title = decode_entities($entry->title); - my $sum_text = decode_entities($entry->content->body); - - my $current_stat = `cat $STAT_FILE`; - my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/; - if($current_id eq $id && $current_file eq $ff->output_file) { - print "Already downloaded file of today\n"; - RHRD::rddb::closedb($dbh); - exit 0; - } - $out_file = $ff->output_file; - if(!rhautoimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - RHRD::rddb::closedb($dbh); - exit 1; - } - - print " --> " . $bdfile . ": 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"; - - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); - 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') { - print "giving up, manual import necessary!!!\n"; - } else { - print "will retry later\n"; - } - exit 1; -} - -print "will import $file to dropbox $dropbox (cart=$to_cart)\n"; - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret; -my $log = rhautoimport::clear_carts($dbh, $group, $to_cart); -my $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); -$log .= $import_log; - -RHRD::rddb::closedb($dbh); - -unlink $file; - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs "$id\n$out_file"; -close($fhs); - -exit 0; diff --git a/rhautoimport-sv b/rhautoimport-sv deleted file mode 100755 index 14dbc44..0000000 --- a/rhautoimport-sv +++ /dev/null @@ -1,212 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Date::Calc; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use IO::Handle; -use IPC::Open3; -use HTML::Entities; -use LWP::Simple; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-sv.stat"; -my $RSS_URL = "http://cba.fro.at/seriesrss/262457?c=Kfs2IoV2Wmd"; -$XML::Feed::MULTIPLE_ENCLOSURES=1; -my $PV_ID = '396'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; -my $group = "svetjevas"; - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} - -if(scalar(@allowed_dbs) != 1) { - print "found more or less than one Dropbox for this group?!\n"; - RHRD::rddb::closedb($dbh); - exit 1; -} -my $dropbox = $allowed_dbs[0]->{'PATH'}; -my $to_cart = $allowed_dbs[0]->{'TO_CART'}; - -my $curweek = RHRD::utils::get_rd_week(); - -my @today = Date::Calc::Today(); -my $dow = Date::Calc::Day_of_Week(@today); -if(($curweek != 3 && $curweek != 4) || - ($curweek == 4 && $dow > 2)) { - print "File won't be available by now!\n"; - RHRD::rddb::closedb($dbh); - exit 0; -} -print "today: " . Date::Calc::Date_to_Text(@today) . "\n"; - -my @import_date = Date::Calc::Standard_to_Business(@today); -$import_date[2] = 2; -@import_date = Date::Calc::Business_to_Standard(@import_date); -if($curweek == 3) { - @import_date = Date::Calc::Add_Delta_Days(@import_date, 7); -} -print "day of next Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_date) . "\n"; - -my @broadcast_date = Date::Calc::Nth_Weekday_of_Month_Year($import_date[0], $import_date[1], 7, 1); -if(Date::Calc::Delta_Days(@broadcast_date, @import_date) <= 0) { - my @tmp_date = Date::Calc::Add_Delta_YM(@broadcast_date, 0, -1); - @broadcast_date = Date::Calc::Nth_Weekday_of_Month_Year($tmp_date[0], $tmp_date[1], 7, 1); -} -print "day of latest original broadcast before next Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@broadcast_date) . "\n"; - -if(Date::Calc::Delta_Days(@broadcast_date, @today) <= 0) { - print "File won't be available by now!\n"; - RHRD::rddb::closedb($dbh); - exit 0; -} - -my $id = sprintf("%04d-%02d-%02d", @import_date); -my $bd = sprintf("%04d-%02d-%02d", @broadcast_date); -my $bdfile = sprintf("SEOI%02d%02d", $broadcast_date[2], $broadcast_date[1]); - -print "looking for files from $bd in RSS Feed\n"; -print " -> $RSS_URL\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $file = ""; -my $out_file = ""; -my $i = 0; -for my $entry ($feed->entries) { - $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 $ff = File::Fetch->new(uri => $url); - next unless (uc($ff->output_file) =~ $bdfile); # file not from correct day - - my $sum_title = decode_entities($entry->title); - my $sum_text = decode_entities($entry->content->body); - - my $current_stat = `cat $STAT_FILE`; - my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/; - if($current_id eq $id && $current_file eq $ff->output_file) { - print "Already downloaded file of today\n"; - RHRD::rddb::closedb($dbh); - exit 0; - } - $out_file = $ff->output_file; - if(!rhautoimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - RHRD::rddb::closedb($dbh); - exit 1; - } - - print " --> " . $bdfile . ": 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"; - - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); - 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') { - print "giving up, manual import necessary!!!\n"; - } else { - print "will retry later\n"; - } - exit 1; -} - -print "will import $file to dropbox $dropbox (cart=$to_cart)\n"; - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret; -my $log = rhautoimport::clear_carts($dbh, $group, $to_cart); -my $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); -$log .= $import_log; - -RHRD::rddb::closedb($dbh); - -unlink $file; - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs "$id\n$out_file"; -close($fhs); - -exit 0; diff --git a/rhautoimport-ut b/rhautoimport-ut deleted file mode 100755 index 1d53f0e..0000000 --- a/rhautoimport-ut +++ /dev/null @@ -1,199 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Date::Calc; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use IO::Handle; -use IPC::Open3; -use HTML::Entities; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-ut.stat"; -my $RSS_URL = "http://cba.fro.at/seriesrss/264016?c=Kfs2IoV2Wmd"; -$XML::Feed::MULTIPLE_ENCLOSURES=1; -my $PV_ID = '393'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; -my $group = "uton"; - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} - -my $idx = 0; -my $idx_reb = 1; -if(scalar(@allowed_dbs) != 2) { - print "found more or less than 2 Dropboxes for this group?!\n"; - RHRD::rddb::closedb($dbh); - exit 1; -} -my $dropbox = $allowed_dbs[$idx]->{'PATH'}; -my $to_cart = $allowed_dbs[$idx]->{'TO_CART'}; -my $dropbox_reb = $allowed_dbs[$idx_reb]->{'PATH'}; -my $to_cart_reb = $allowed_dbs[$idx_reb]->{'TO_CART'}; - -my @import_date = Date::Calc::Standard_to_Business(Date::Calc::Today()); -my $dow = $import_date[2]; -$import_date[2] = 3; -@import_date = Date::Calc::Business_to_Standard(@import_date); -@import_date = Date::Calc::Add_Delta_Days(@import_date, 7) if ($dow > 3); - -my @broadcast_day = Date::Calc::Add_Delta_Days(@import_date, -106); -my @import_date_reb = Date::Calc::Add_Delta_Days(@import_date, 2); -print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\n"; -print "day of Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_date) . "\n"; -print "day of Radio Helsinki rebroadcast: " . Date::Calc::Date_to_Text(@import_date_reb) . "\n"; - -my $bd = sprintf("%04d-%02d-%02d", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]); -print "looking for files from $bd in RSS Feed\n"; -print " -> $RSS_URL\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $bdexp = sprintf("^UTON%02d%02d%02d", $broadcast_day[0] % 100, $broadcast_day[1], $broadcast_day[2]); - -my $file = ""; -my $out_file = ""; -my $i = 0; -for my $entry ($feed->entries) { - $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 $ff = File::Fetch->new(uri => $url); - next unless (uc($ff->output_file) =~ $bdexp); # file not from correct day - - my $sum_title = decode_entities($entry->title); - my $sum_text = decode_entities($entry->content->body); - - my $current_file = `cat $STAT_FILE`; - if($current_file eq $ff->output_file) { - print "Already downloaded file of today\n"; - RHRD::rddb::closedb($dbh); - exit 0; - } - $out_file = $ff->output_file; - if(!rhautoimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - RHRD::rddb::closedb($dbh); - exit 1; - } - - print " --> " . $bdexp . ": 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"; - - rhautoimport::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"; - rhautoimport::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') { - print "giving up, manual import necessary!!!\n"; - } else { - print "will retry later\n"; - } - exit 1; -} - -print "will import $file to dropbox $dropbox (cart=$to_cart)\n"; -print "will import $file to rebroadcast dropbox $dropbox_reb (cart=$to_cart_reb)\n\n"; - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret; -my $log = rhautoimport::clear_carts($dbh, $group, $to_cart); -my $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); -$log .= $import_log; -$import_log = rhautoimport::clear_carts($dbh, $group, $to_cart_reb); -$log .= $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox_reb, $user, 0, $error_cb); -$log .= $import_log; - -RHRD::rddb::closedb($dbh); - -unlink $file; - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs $out_file; -close($fhs); - -exit 0; diff --git a/rhautoimport-zf b/rhautoimport-zf deleted file mode 100755 index d5d097a..0000000 --- a/rhautoimport-zf +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Date::Calc; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use IO::Handle; -use IPC::Open3; -use HTML::Entities; -use File::Touch; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-zf.stat"; -my $NOTE_FILE = $ENV{'HOME'} . "/rhautoimport-zf.last_note"; -my $NEW_FILE = $ENV{'HOME'} . "/rhautoimport-zf.is_new"; -my $RSS_URL = "http://freie-radios.net/portal/podcast.php?serie=53&rss"; -my $PV_ID = '300'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; -my $group = "zipfm"; - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} - - -my $dropbox = ""; -my $to_cart = 0; -my $dropbox_reb = ""; -my $to_cart_reb = 0; - -my @today = Date::Calc::Today(); -my $dow = Date::Calc::Day_of_Week(@today); -my @tomorrow = Date::Calc::Add_Delta_Days(@today, 1); - -my @broadcast_day = @today; -my @rebroadcast_day = @tomorrow; -print "day of broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\n"; -print "day of rebroadcast: " . Date::Calc::Date_to_Text(@rebroadcast_day) . "\n" unless $dow == 5; - -for my $href ( @allowed_dbs ) { - if ($dow == int(substr($href->{'NAME'},0,2))) { - $dropbox = $href->{'PATH'}; - $to_cart = $href->{'TO_CART'}; - } -} - -if($dropbox eq "") { - print "no dropbox for day in question\n"; - RHRD::rddb::closedb($dbh); - exit 0; -} - -my $regexp = sprintf("%04d%02d%02d", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]); -print "looking for file from " . Date::Calc::Date_to_Text(@broadcast_day) . " in RSS Feed\n"; -print " -> $RSS_URL\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $file = ""; -my $out_file = ""; -for my $entry ($feed->entries) { - if($entry->enclosure && $entry->enclosure->type eq "audio/mpeg") { - next unless $entry->enclosure->url =~ /$regexp/; - - my $sum_title = decode_entities($entry->title); - my $sum_text = decode_entities($entry->content->body); - - my $ff = File::Fetch->new(uri => $entry->enclosure->url); - my $current_file = `cat $STAT_FILE`; - if($current_file eq $ff->output_file) { - print "Already downloaded file of today\n"; - RHRD::rddb::closedb($dbh); - exit 0; - } - $out_file = $ff->output_file; - if(!rhautoimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - RHRD::rddb::closedb($dbh); - exit 1; - } - - print $regexp . ": 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"; - - if($#ARGV >= 0 && $ARGV[0] eq 'nopv') { - print "not adding note to PV for regular entry - only for rebroadcast\n"; - } else { - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @broadcast_day), "1", 1); - } - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @rebroadcast_day), "2", 0) unless $dow == 5; - print "\n"; - - unlink($NOTE_FILE); - open(my $fhs, '>', $NOTE_FILE); - binmode($fhs, ":utf8"); - print $fhs $sum_title . "\n\n" . $sum_text . "\n"; - close($fhs); - - last; - } -} -if($file eq "" || !(-e "$file")) { - print "No Entry found for " . Date::Calc::Date_to_Text(@broadcast_day) . " or download error - "; - if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "giving up, manual import necessary!!!\n"; - } else { - print "will retry later\n"; - } - exit 1; -} - -print "will import $file to dropbox $dropbox (cart=$to_cart)\n"; - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret; -my $log = rhautoimport::clear_carts($dbh, $group, $to_cart); -my $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); -$log .= $import_log; - -RHRD::rddb::closedb($dbh); - -unlink $file; - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs $out_file; -close($fhs); -touch($NEW_FILE); - -exit 0; diff --git a/rhautoimport-zffe b/rhautoimport-zffe deleted file mode 100755 index 2dfb7c1..0000000 --- a/rhautoimport-zffe +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Switch; -use Date::Calc; -use Time::localtime; -use IO::Handle; -use IPC::Open3; -use File::Slurp; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-zffe.stat"; -my $ZF_NOTE_FILE = $ENV{'HOME'} . "/rhautoimport-zf.last_note"; -my $ZF_NEW_FILE = $ENV{'HOME'} . "/rhautoimport-zf.is_new"; -my $FE_NOTE_FILE = $ENV{'HOME'} . "/rhautoimport-fe.last_note"; -my $FE_NEW_FILE = $ENV{'HOME'} . "/rhautoimport-fe.is_new"; -my $PV_ID = '359'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my @today = Date::Calc::Today(); -my $dow = Date::Calc::Day_of_Week(@today); -my @tomorrow = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], 1); - -my @tmp = Date::Calc::Standard_to_Business(@today); -$tmp[2] = 1; -my @this_mon = Date::Calc::Business_to_Standard(@tmp); -my @next_mon = Date::Calc::Add_Delta_Days($this_mon[0], $this_mon[1], $this_mon[2], 7); - -my @import_day = @tomorrow; -if ($dow == 5) { - @import_day = @next_mon; -} - -my $import_date = sprintf("%04d-%02d-%02d", @import_day); -my $current_date = `cat $STAT_FILE`; -if($current_date eq $import_date) { - print "Already created note of today\n"; - exit 0; -} - -unless(-e $ZF_NEW_FILE) { - print "zip-fm not yet imported - "; - if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "giving up, rebroadcasting last show"; - } else { - print "will retry later\n"; - exit 0, - } -} - -unless(-e $FE_NEW_FILE) { - print "focus europa not yet imported - "; - if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "giving up, rebroadcasting last show"; - } else { - print "will retry later\n"; - exit 0, - } -} - -sub get_note { - my ($file) = @_; - my @lines = read_file($file, binmode => ':utf8', err_mode => 'quiet'); - return "" unless ($lines[0]); - - chomp($lines[0]); - $lines[0] = "<p><strong>$lines[0]</strong></p>\n"; - return join('',@lines); -}; - -my $sum_title = "focus europa, zip-fm (WH)"; -my $sum_text = get_note($FE_NOTE_FILE) . "<br/>\n"; -$sum_text = $sum_text . "<br/>\n" . get_note($ZF_NOTE_FILE) . "<br/>\n"; -$sum_text = $sum_text . "<br/><br/>\n"; - -print "\nsummary:\n" . $sum_title . "\n\n" . $sum_text . "\n"; -rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_day), "1"); -print "\n"; - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs $import_date; -close($fhs); - -unlink($ZF_NEW_FILE); -unlink($FE_NEW_FILE); - -exit 0; diff --git a/rhautoimport-zfw b/rhautoimport-zfw deleted file mode 100755 index 1fdb1a0..0000000 --- a/rhautoimport-zfw +++ /dev/null @@ -1,195 +0,0 @@ -#!/usr/bin/perl -w -# -# -# rhautoimport -# -# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at> -# -# This file is part of rhautoimport. -# -# rhautoimport is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# rhautoimport is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>. -# - -use strict; -use Date::Calc; -use Time::localtime; -use XML::Feed; -use XML::Feed::Entry; -use XML::Feed::Content; -use XML::Feed::Enclosure; -use File::Fetch; -use IO::Handle; -use IPC::Open3; -use HTML::Entities; -use RHRD::rddb; - -use lib '/usr/local/share/rhautoimport/'; -use rhautoimport; - -my $STAT_FILE = $ENV{'HOME'} . "/rhautoimport-zfw.stat"; -my $RSS_URL = "http://cba.fro.at/seriesrss/263764?c=Kfs2IoV2Wmd"; -$XML::Feed::MULTIPLE_ENCLOSURES=1; -my $PV_ID = '360'; - -binmode(STDIN, ":utf8"); -binmode(STDOUT, ":utf8"); -binmode(STDERR, ":utf8"); - -if($#ARGV >= 0 && $ARGV[0] eq 'last') { - print "!!!This is the last attempt, there won't be a retry on error!!!\n" -} - -my $user = `/usr/bin/id -un`; -$user =~ s/\n//; -my $group = "zipfmwla"; - -my ($dbh, $errorstring) = RHRD::rddb::opendb(); -if(!defined $dbh) { - print "$errorstring\n"; - exit 1; -} -my @allowed_dbs = RHRD::rddb::get_dropboxes($dbh, $user, $group); -if(!defined $allowed_dbs[0] && defined $allowed_dbs[2]) { - print "$allowed_dbs[2]\n"; - exit 1; -} - -if(scalar(@allowed_dbs) != 1) { - print "found no or more than one Dropboxes for this group?!\n"; - RHRD::rddb::closedb($dbh); - exit 1; -} -my $dropbox = $allowed_dbs[0]->{'PATH'}; -my $to_cart = $allowed_dbs[0]->{'TO_CART'}; - - -my @today = Date::Calc::Today(); -my @yesterday = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], -1); -my @tomorrow = Date::Calc::Add_Delta_Days($today[0], $today[1], $today[2], 1); - -my @broadcast_day = @yesterday; -my @import_day = @today; -if(localtime->hour >= 12) { - print "It's past noon, assuming to import file from today\n"; - @broadcast_day = @today; - @import_day = @tomorrow; -} - -print "day of original broadcast: " . Date::Calc::Date_to_Text(@broadcast_day) . "\n"; -print "day of Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_day) . "\n"; - -my $id = sprintf("%04d-%02d-%02d", $import_day[0], $import_day[1], $import_day[2]); -my $bd = sprintf("%04d-%02d-%02d", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]); -print "looking for files from $bd in RSS Feed\n"; -print " -> $RSS_URL\n"; - -my $feed = XML::Feed->parse(URI->new($RSS_URL)) - or die "Error fetching feed: " . XML::Feed->errstr; - -my $bdfile = sprintf("%04d%02d%02d", $broadcast_day[0], $broadcast_day[1], $broadcast_day[2]); - -my $file = ""; -my $out_file = ""; -my $i = 0; -for my $entry ($feed->entries) { - $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 $ff = File::Fetch->new(uri => $url); - next unless (uc($ff->output_file) =~ $bdfile); # file not from correct day - - my ($sum_title, $sum_title_rest) = split(/:/, decode_entities($entry->title), 2); - my $sum_text = decode_entities($entry->content->body); - - my $current_stat = `cat $STAT_FILE`; - my ($current_id, $current_file) = $current_stat =~ m/^(.*)\n(.*)/; - if($current_id eq $id && $current_file eq $ff->output_file) { - print "Already downloaded file of today\n"; - RHRD::rddb::closedb($dbh); - exit 0; - } - $out_file = $ff->output_file; - if(!rhautoimport::check_file_extension($out_file)) { - print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; - RHRD::rddb::closedb($dbh); - exit 1; - } - - print " --> " . $bdfile . ": 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"; - - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); - 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') { - print "giving up, manual import necessary!!!\n"; - } else { - print "will retry later\n"; - } - exit 1; -} - -print "will import $file to dropbox $dropbox (cart=$to_cart)\n"; - -my $error_cb = sub { - my ($text) = @_; - - print "\n$text"; - return 0; -}; - -rhautoimport::check_key_file() or die "Import Key not found, use rhautoimport-create-id to create one\n"; - -my $ret; -my $log = rhautoimport::clear_carts($dbh, $group, $to_cart); -my $import_log; -($ret, $import_log) = rhautoimport::import_single($file, $dropbox, $user, 0, $error_cb); -$log .= $import_log; - -RHRD::rddb::closedb($dbh); - -unlink $file; - -if(!$ret) { - print "\nImport Error:\n"; - print $log; - exit 1; -} - -unlink($STAT_FILE); -open(my $fhs, '>', $STAT_FILE); -print $fhs "$id\n$out_file"; -close($fhs); - -exit 0; |