From 3bf65f5733177b0624bb4f08f9c9ba295f0336f7 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Thu, 15 Sep 2016 16:26:46 +0200
Subject: rhrd-schedules generate supports multi-show as well


diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules
index 9147e64..b198a9e 100755
--- a/utils/rhrd-schedules
+++ b/utils/rhrd-schedules
@@ -22,7 +22,6 @@
 
 use strict;
 
-use lib '../lib';
 use RHRD::rddb;
 use RHRD::utils;
 use DateTime;
@@ -46,13 +45,18 @@ sub generate
     return 1;
   }
 
+  my $week = RHRD::utils::get_rd_week(DateTime->new(year => $year, month => $month, day => $day, hour => 12));
+
   my ($showid_min, $showid_max, $errorstring) = RHRD::rddb::get_showid_range($ctx);
   unless(defined $showid_min) {
     print STDERR "$showid_max: $errorstring\n";
     return 1;
   }
-
-  ## TODO: get multi-show id range as well
+  (my $mshowid_min, my $mshowid_max, $errorstring) = RHRD::rddb::get_multi_showid_range($ctx);
+  unless(defined $mshowid_min) {
+    print STDERR $mshowid_max . ": " . $errorstring . "\n";
+    return 1;
+  }
 
   my $errcnt = 0;
   my @shows = ();
@@ -68,25 +72,35 @@ sub generate
     next if ($start->year != $year || $start->month != $month || $start->day != $day);
 
     if($showid < 0) {
-      print "WARNING: skipping entry whith unset automation id -> $start: $title ($pvid)\n";
+      print "WARNING: skipping entry with unset automation id -> $start: $title ($pvid)\n";
       $errcnt++;
       next;
     }
-    ## include multi-show ranges for this check
-    if ($showid < $showid_min || $showid > $showid_max) {
-      print "WARNING: skipping entry whith out of range automation id ($showid) -> $start: $title ($pvid)\n";
+    if ($showid >= $mshowid_min && $showid <= $mshowid_max) {
+      my ($show, $status, $errorstring) = RHRD::rddb::get_multi_show_info($ctx, $showid);
+      unless(defined $show) {
+        print "WARNING: skipping entry with multi-show ($showid), reason: $errorstring -> $start: $title ($pvid)\n";
+        next;
+      }
+      my $realshowid = $show->{'SHOWS'}->{$week};
+      unless($showid > 0) {
+        print "WARNING: skipping entry with multi-show ($showid) that has no entry for Week $week -> $start: $title ($pvid)\n";
+        next
+      }
+      #print "multi: mapping $showid to $realshowid\n";
+      $showid = $realshowid;
+    } elsif ($showid < $showid_min || $showid > $showid_max) {
+      print "WARNING: skipping entry with out-of-range automation id ($showid) -> $start: $title ($pvid)\n";
       next;
     }
 
-    ## if is-multi-show: get real show-id from multi-show...
-
     (my $exists, my $status, $errorstring) = RHRD::rddb::check_show_exists($ctx, $showid);
     unless(defined $exists) {
       print STDERR "$status: $errorstring\n";
       return 1;
     }
     if($exists != 1) {
-      print "WARNING: skipping entry whith not existing automation id ($showid) -> $start: $title ($pvid)\n";
+      print "WARNING: skipping entry with not existing automation id ($showid) -> $start: $title ($pvid)\n";
       next;
     }
 
-- 
cgit v0.10.2