From bbc151dcd8d88f543454cb282e1dac01ef720894 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 12 Mar 2016 23:36:21 +0100 Subject: import for rebroadcast at radioattac works now diff --git a/rhautoimport-ra b/rhautoimport-ra index aaa1e0a..3cf2843 100755 --- a/rhautoimport-ra +++ b/rhautoimport-ra @@ -50,7 +50,6 @@ if(!defined $allowed_dbs[0] && defined $allowed_dbs[1]) { exit 1; } - my $idx = 0; my $idx_reb = 1; if(scalar(@allowed_dbs) != 2) { @@ -62,6 +61,7 @@ my $show_title = $allowed_dbs[$idx]->{'SHOWTITLE'}; my $show_id_reb = $allowed_dbs[$idx_reb]->{'SHOWID'}; my $show_title_reb = $allowed_dbs[$idx_reb]->{'SHOWTITLE'}; + my @today = Date::Calc::Standard_to_Business(Date::Calc::Today()); $today[2] = 1; my @broadcast_day = Date::Calc::Business_to_Standard(@today); @@ -83,6 +83,9 @@ my $bdexp = sprintf("^(\\d+)\\..*\\s*0?%d\\s*[.,]\\s*0?%d\\s*[.,]\\s*%4d", $broa my $uri = ""; my $file = ""; +my $sum_title = ""; +my $sum_text = ""; + my $i = 0; for my $entry ($feed->entries) { $i++; @@ -97,7 +100,8 @@ for my $entry ($feed->entries) { $orig_uri = $1 . $2; } - my $sum_title = decode_entities($entry->title); + $sum_title = decode_entities($entry->title); + $sum_text = decode_entities($entry->content->body); next unless $sum_title =~ /$bdexp/; my $bnum = $1; @@ -116,13 +120,7 @@ for my $entry ($feed->entries) { exit 1; } - my $sum_text = decode_entities($entry->content->body); 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"; - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_date_reb), "2"); - print "\n"; - last; } } @@ -138,19 +136,36 @@ if($uri eq "") { exit 1; } -print "will import '$uri' to show $show_id, $show_title\n\n"; -print "will import '$uri' to rebroadcast $show_id_reb, $show_title_reb\n\n"; +print "will import '$uri' to show $show_id, $show_title\n"; +my ($ret, $log, $keptfile_uri) = rhautoimport::import_uri($show_id, $uri->as_string, "keep"); +if($ret == 0) { + print "\nImport Success:\n\n"; + print $log; + rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_date), "1"); + print "\n"; + if(!defined($keptfile_uri)) { + print "rhimportd didn't provide a clue where to find the kept file... will import '$uri' to rebroadcast $show_id_reb, $show_title_reb\n"; + ($ret, $log) = rhautoimport::import_uri($show_id_reb, $uri->as_string); + } else { + print "re-using kept file '$keptfile_uri' to import rebroadcast $show_id_reb, $show_title_reb\n"; + ($ret, $log) = rhautoimport::import_uri($show_id_reb, $keptfile_uri, "delete-with-dir"); + } -my ($ret, $log) = rhautoimport::import_uri($show_id, $uri->as_string); # TODO: file-policy: keep -# TODO: import to $show_id_reb with file-policy: delete-with-dir -if($ret) { + if($ret == 0) { + print "\nImport Success:\n\n"; + print $log; + rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_date_reb), "2"); + } else { + print "\nImport Error:\n\n"; + print $log; + exit 1; + } +} else { print "\nImport Error:\n\n"; print $log; exit 1; } -print "\nImport Success:\n\n"; -print $log; unlink($STAT_FILE); open(my $fhs, '>', $STAT_FILE); diff --git a/rhautoimport.pm b/rhautoimport.pm index 588d13b..a0684ce 100644 --- a/rhautoimport.pm +++ b/rhautoimport.pm @@ -134,11 +134,11 @@ sub parse_result } $log .= "rhimportd returned: OK (Cart: " . $cart . ", Cut: " . $cut; - $log .= ", source file: '" . $source_file . "'" if defined($source_file); + $log .= ", source file: '" . $source_file . "'" if(defined($source_file) && $source_file ne ""); $log .= ")\n"; unlink($donefile); - return (0, $log); + return (0, $log, $source_file); } sub import_uri @@ -147,7 +147,7 @@ sub import_uri my %request; $request{'LOGIN_NAME'} = RD_USER; - $request{'SHOW_ID'} = $show_id; + $request{'SHOW_ID'} = int($show_id); $request{'CLEAR_SHOW_CARTS'} = JSON::true; $request{'SOURCE_URI'} = $uri; $request{'SOURCE_FILE_POLICY'} = $file_policy if $file_policy; @@ -188,8 +188,8 @@ sub import_uri } $log .= "import is done ... took " . $duration . " seconds!\n"; - my ($ret, $tmplog) = parse_result($donefile); - return $ret, $log . $tmplog; + my ($ret, $tmplog, $keptfile_uri) = parse_result($donefile); + return $ret, $log . $tmplog, $keptfile_uri; } sub pv_add_note -- cgit v0.10.2