From 96ca91fb9d94756ef47ae1aff0a2dce00e43be74 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Thu, 18 Jan 2018 23:53:53 +0100
Subject: fix between the lines importer


diff --git a/INFO b/INFO
index 72383d4..203ea3c 100644
--- a/INFO
+++ b/INFO
@@ -1,6 +1,15 @@
 
    *** add info about other importers... ***
-   (missing: btl, dn, er, eu, fl, nw, oi, po, rs, wr)
+   (missing: dn, er, eu, fl, nw, oi, po, rs, wr)
+
+- (btl) Between the Lines
+   http://www.btlonline.org/rss/btl128.xml
+
+   Original: wöchentlich Mittwochs
+   Upload: immer am selben Tag
+   Such-Kriterium: Dateiname im format 'YYmmdd-btlv128.mp3'
+         es gibt wöchentlich neue Sendungen wir spielen jede zweite
+   RH: 2wöchentlich, Woche 2/4, Montag, 07:30-08:00
 
 - (gd) Women on Air presents: Globale Dialoge
    https://cba.fro.at/series/globale-dialoge-women-on-air/feed
@@ -55,7 +64,7 @@
        Sendung 03-2017 und 05-2017 fehlen in der CBA aber
        sind laut O94 Homepage gelaufen...
    RH: 4wöchentlich, Woche 3, Dienstag, 16:00-16:30
-       4wöchtenlich, Woche 2, Mittwoch, 14:00-14:30, Wiederholung
+       4wöchentlich, Woche 2, Mittwoch, 14:00-14:30, Wiederholung
 
 - (pv) Pura Vida Sounds:
    https://cba.fro.at/series/pura-vida-sounds/feed
diff --git a/rhautoimport-btl b/rhautoimport-btl
index a67d432..3fd662d 100755
--- a/rhautoimport-btl
+++ b/rhautoimport-btl
@@ -40,6 +40,7 @@ my $RD_GROUP = "betweenlin";
 my $PV_ID = '221';
 my $TITLE="Between the Lines";
 my $LAST_RUN = 0;
+my $upload_delay_days = 0;   # files are usally there on the same day
 
 binmode(STDIN, ":utf8");
 binmode(STDOUT, ":utf8");
@@ -47,7 +48,7 @@ binmode(STDERR, ":utf8");
 
 my $curweek = RHRD::utils::get_rd_week();
 if($curweek == 2 || $curweek == 4) {
-  print "please don't run this script in week 2 or 4!\n";
+  print "won't do anything in week 2 or 4!\n";
   rhautoimport::report_title_and_last($TITLE, 0);
   exit 42;
 }
@@ -72,20 +73,22 @@ if(scalar(@allowed_dbs) != 1) {
 my $show_id = $allowed_dbs[0]->{'SHOWID'};
 my $show_title = $allowed_dbs[0]->{'SHOWTITLE'};
 
-
 my @today = Date::Calc::Today();
 my @import_date = Date::Calc::Add_Delta_Days(@today, 7);
 @import_date = Date::Calc::Standard_to_Business(@import_date);
 $import_date[2] = 1;
-my @broadcast_date = @import_date;
-$broadcast_date[2] = 5;
-
 @import_date = Date::Calc::Business_to_Standard(@import_date);
-@broadcast_date = Date::Calc::Business_to_Standard(@broadcast_date);
+
+my @broadcast_date = Date::Calc::Add_Delta_Days(@import_date, -5);
 
 print "today: " . Date::Calc::Date_to_Text(@today) . "\n";
 print "day of next Radio Helsinki broadcast: " . Date::Calc::Date_to_Text(@import_date) . "\n";
-print "ending of current broadcast cycle: " . Date::Calc::Date_to_Text(@broadcast_date) . "\n";
+print "current broadcast cycle starts/started on: " . Date::Calc::Date_to_Text(@broadcast_date) . "\n";
+
+if(Date::Calc::Delta_Days(@broadcast_date, @today) <= $upload_delay_days) {
+  print "File won't be available by now!\n";
+  exit 42;
+}
 
 my $id = sprintf("%04d-%02d-%02d", @import_date);
 my $bd = sprintf("%04d-%02d-%02d", @broadcast_date);
-- 
cgit v0.10.2