-
Notifications
You must be signed in to change notification settings - Fork 0
/
rg_guide.pl
1450 lines (1174 loc) · 42.3 KB
/
rg_guide.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#
# Personal ReplayGuide
# by Lee Thompson <[email protected]>
# with bits by Kanji T. Bates
# Theme Stuff based upon ReplaySchedule.pl by Kevin J. Moye
# $Id: rg_guide.pl,v 1.5 2003/11/04 00:31:05 pvanbaren Exp $
#
# SCHEDULE RESOLVER MODULE: RG_GUIDE
#
#------------------------------------------------------------------------------------
# This file is part of Personal ReplayGuide (C) 2003 by Lee Thompson
#
# Personal ReplayGuide 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 2 of the License, or
# (at your option) any later version.
#
# Personal ReplayGuide 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 Personal ReplayGuide; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#-----------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------
#
# The Schedule interface must define the following functions.
# All functions must be defined
#
# getFreshScheduleTable ( $replayid )
# - $replayid is the database identifier of the unit to check
# - download a fresh set of schedule information from the replaytv
# - must save the schedule information so a cached copy can be loaded later
# - returns 0 if successful
#
# getCachedScheduleTable ( $replayid )
# - $replayid is the database identifier of the unit to check
# - load in the previously cached copy of the schedule information
# - returns 0 if successful
#
# ProcessScheduleTable ( )
# - called after all tables are loaded, but prior to displaying any details
# - prepares the schedule information for use and initialize any related variables
# - does not return any value
#
# compareScheduleTable ( $Stmt )
# - $Stmt is a database query statement that returns the list of shows
# to be displayed
# - process all schedule tables to prepare scheduling details
# and priorities for the selected shows
# - called after all tables are loaded, but prior to displaying any details
# - does not return any value
#
# getScheduleDetails ( $programid , $timing )
# - $programid is the database identifier the program to check
# - $timing is 0 for a past show, 1 for a present show, 2 for a future show
# - returns an icon or text string to be inserted into the html code
# indicating if the show is to scheduled to be recorded.
# - returns a "" string if no information available
# - may set the global $bgcolor variable to determing table background color
#
# AboutScheduler
# - Returns optional text which is placed in the program log file.
#
# SchedulerDoBatchUpdate
# - If some type of nightly processing is perferred or required this should
# return true (1), otherwise return 0.
#
# SchedulebarSupported
# - If the module supports the ScheduleBar (within replayguide.pl) this should
# return true (1), otherwise return 0.
#
# ToDoSupported
# - If the module supports the ToDo List (within replayguide.pl) this should
# return true (1), otherwise return 0.
#
#-----------------------------------------------------------------------------------
require HTTP::Request;
require HTTP::Headers;
require LWP::UserAgent;
use Time::Local;
use POSIX qw( strftime getcwd );
my $_version = "Personal ReplayGuide|Simple Scheduler Resolver Module|1|1|201|Lee Thompson,Philip Van Baren,Kanji T. Bates,Kevin J. Moye";
#------------------------------------------------------------------------------------
# Determine Current Directroy
#------------------------------------------------------------------------------------
$current_dir = getcwd;
$current_dir .= "/";
#------------------------------------------------------------------------------------
# Get script pathname, unfortunately on Apache on Win32 $0 is not reliable since
# for some reason it gets changed to an 8.3 pathname.
#
# IIS and Apache both provide long filename pathnames in environment variables so
# if it's an 8.3 we look there. If we don't find it, we just tough it out.
#------------------------------------------------------------------------------------
$script_pathname = $0;
if ($0 =~ /\~/) {
if (length($ENV{SCRIPT_FILENAME}) > 0 ) {
$script_pathname = $ENV{SCRIPT_FILENAME};
}
if (length($ENV{PATH_TRANSLATED}) > 0 ) {
$script_pathname = $ENV{PATH_TRANSLATED};
}
}
#------------------------------------------------------------------------------------
# Get the path that the script is in
#------------------------------------------------------------------------------------
(my $path,my $basename) = $script_pathname =~ m|^(.*[/\\])([^/\\]+?)$|;
#------------------------------------------------------------------------------------
# PRG_HOME is an override environment variable
#------------------------------------------------------------------------------------
if (length($ENV{PRG_HOME}) > 0) {
$path = $ENV{PRG_HOME};
}
#------------------------------------------------------------------------------------
# Normalize the path
#------------------------------------------------------------------------------------
$path =~ s/\\/\//g;
#------------------------------------------------------------------------------------
# If the current working directory is not where we need to be, change paths.
#------------------------------------------------------------------------------------
$changed_path = -1;
if (($current_dir ne $path) && ($path ne "")) {
if (chdir $path) {
$changed_path = 1;
}else{
$changed_path = 0;
}
}
#------------------------------------------------------------------------------------
# Load Libraries
#------------------------------------------------------------------------------------
require 'rg_replay.pl';
#------------------------------------------------------------------------------------
# Set up module identification
#------------------------------------------------------------------------------------
my $module_name = "";
(my $debug_package, my $debug_filename, my $debug_line, my $debug_subroutine, my $debug_hasargs, my $debug_wantarray, my $debug_evaltext, my $debug_isrequire) = caller(0);
if (length($debug_evaltext) > 0) {
$module_name = $debug_evaltext;
}else{
if ($path eq "") {
$basename = $script_pathname;
}
$module_name = $basename;
}
$prg_module{$module_name} = $_version;
#------------------------------------------------------------------------------------
# Set up locals
#------------------------------------------------------------------------------------
my $program_starttime = "";
my $program_title = "";
my $program_tuning = "";
my $program_minutes = 0;
my $program_quality = 2;
my $program_guaranteed = 1;
my $program_recurring = 1;
my $program_category = 0;
my $program_beforepad = 0;
my $program_afterpad = 0;
my $program_daysofweek = 127;
my $program_keep = 1;
my $program_replaytv = 0;
my $program_stop = "";
my $program_length = 0;
my $program_icon = "";
my $program_true_start = "";
my $display_time = "";
my $showlist = "";
#------------------------------------------------
sub getCachedScheduleTable {
my $retcode = 0;
my $replayid = shift;
#-------------------------------------------------------------------
# Read the snapshot files into memory
#-------------------------------------------------------------------
my $replayaddr = $rtvaddress{$replayid};
my $replaylabel = $rtvlabel{$replayid};
if (open(SNAPSHOT,"<$rtv_snapshotpath/$replayaddr.bin")) {
binmode SNAPSHOT;
($junk,$junk,$junk,$junk,$junk,$junk,$junk,$size,$junk,$junk,$junk,$junk,$junk) = stat("$rtv_snapshotpath/$replayaddr.bin");
read SNAPSHOT,$snapshotbody,$size;
close SNAPSHOT;
if (length($snapshotbody) == $size) {
$retcode = 0;
writeDebug("Using cached GuideSnapshot for ReplayTV \#$replayid \"$replaylabel\" at $replayaddr");
}else{
writeDebug("Warning! Attempt to read '$rtv_snapshotpath/$replayaddr.bin' failed (wrong size)");
$retcode = 1;
}
}else{
writeDebug("Warning! Attempt to open '$rtv_snapshotpath/$replayaddr.bin' failed (not present)");
$retcode = 1;
}
return $retcode;
}
#------------------------------------------------
sub ProcessScheduleTable {
# Process the schedule tables to create ReplayTV Events
#---------------------------------------------------------------------------
#-------------------------------------------------------------------
# Collect ReplayTV Events
#-------------------------------------------------------------------
$eventcount = collectRTVChannels($replaylist,1);
writeDebug("There are $eventcount ReplayTV Events");
}
#------------------------------------------------
sub getFreshScheduleTable {
# Refresh the tables used to determine scheduled programs
#---------------------------------------------------------------------------
my $retcode = 0;
my $replayid = shift;
my $replayaddr = $rtvaddress{$replayid};
my $replaylabel = $rtvlabel{$replayid};
my $snapshottime = time;
my $specialdebug = 0;
$guideptr = 0;
if ($specialdebug) {
writeDebug("getFreshScheduleTable::starting($replayid)");
}
if (length($replayaddr) < 1) {
writeDebug("getFreshScheduleTable::replayaddr is null");
if ($specialdebug) {
writeDebug("getFreshScheduleTable::Exiting(1)");
}
return 1;
}
if ($rtvport{$replayid} != 80) {
$replaycmd = "http://$replayaddr:$rtvport{$replayid}/http_replay_guide-get_snapshot?guide_file_name=0";
}else{
$replaycmd = "http://$replayaddr/http_replay_guide-get_snapshot?guide_file_name=0";
}
$ua = LWP::UserAgent->new;
$request = HTTP::Request->new(GET => $replaycmd);
$response = $ua->request($request);
if ($response->is_success) {
writeDebug("Downloaded GuideSnapshot from ReplayTV \#$replayid \"$replaylabel\" at $replayaddr using $replaycmd");
$guidesnapshot = $response->content;
} else {
#
# If we can't contact the unit, try to just use the
# cache.
#
writeDebug("Warning! Could Not Contact $replayaddr for a fresh snapshot");
if (open(SNAPSHOT,"<$rtv_snapshotpath/$replayaddr.bin")) {
binmode SNAPSHOT;
($junk,$junk,$junk,$junk,$junk,$junk,$junk,$size,$junk,$junk,$junk,$junk,$junk) = stat("$rtv_snapshotpath/$replayaddr.bin");
read SNAPSHOT,$snapshotbody,$size;
close SNAPSHOT;
if (length($snapshotbody) == $size) {
writeDebug("getFreshScheduleTable::Warning! Using cached information for ReplayTV \#$replayid \"$replaylabel\" at $replayaddr");
if ($specialdebug) {
writeDebug("getFreshScheduleTable::Exiting(0)");
}
return 0;
}else{
writeDebug("getFreshScheduleTable::Attempt to read cached '$rtv_snapshotpath/$replayaddr.bin' failed (wrong size)");
if ($specialdebug) {
writeDebug("getFreshScheduleTable::Exiting(1)");
}
return 1;
}
}else{
writeDebug("getFreshScheduleTable::Attempt to open cached '$rtv_snapshotpath/$replayaddr.bin' failed (not present)");
if ($specialdebug) {
writeDebug("getFreshScheduleTable::Exiting(1)");
}
return 1;
}
}
#--------------------------------------------------------------
# Strip off extra bits
#--------------------------------------------------------------
if ($specialdebug) {
writeDebug("getFreshScheduleTable::Trimming Data");
}
$snapshotbody = "";
($guidetag,$junk,$snapshotbody,$junk2) = split(/#####/, $guidesnapshot, 9);
#--------------------------------------------------------------
# Update Database
#--------------------------------------------------------------
if ($specialdebug) {
writeDebug("getFreshScheduleTable::Parsing Header");
}
&ParseRTVHeader;
if ($specialdebug) {
writeDebug("getFreshScheduleTable::SV: $guideheader{snapshotversion} OS: $guideheader{osversion} CC: $guideheader{channelcount}");
writeDebug("getFreshScheduleTable::$category");
}
my $replayosversion = $guideheader{snapshotversion} * 10 + 30 + $guideheader{osversion};
my $guideversion = $guideheader{snapshotversion};
my $categories = $category;
$Stmt = "UPDATE $db_table_replayunits SET categories = '$categories', " .
"replayosversion = '$replayosversion', " .
"guideversion='$guideversion'" .
"WHERE replayid = '$replayid';";
# $Stmt = "UPDATE $db_table_replayunits SET lastsnapshot = $snapshottime WHERE replayid = '$replayid';";
#--------------------------------------------------------------
# Dump Snapshot to Disk
#--------------------------------------------------------------
if ($specialdebug) {
writeDebug("getFreshScheduleTable::Dumping to Disk");
}
if (open(SNAPSHOT,">$rtv_snapshotpath/$replayaddr.bin")) {
binmode SNAPSHOT;
print SNAPSHOT $snapshotbody;
close SNAPSHOT;
my $db_handle = &StartDSN;
if (sqlStmt($db_handle,$Stmt)) {
writeDebug("getFreshScheduleTable::Refresh for ReplayTV \#$replayid \"$replaylabel\" at $replayaddr successful, cache saved successfully, database update successful");
}else{
writeDebug("getFreshScheduleTable::Refresh for ReplayTV \#$replayid \"$replaylabel\" at $replayaddr successful, cache saved successfully, database update failed");
}
endDSN("",$db_handle);
undef $db_handle;
}else{
writeDebug("getFreshScheduleTable::Warning! Attempt to write '$rtv_snapshotpath/$replayaddr.bin' failed");
}
if ($specialdebug) {
writeDebug("getFreshScheduleTable::Exiting(0)");
}
return 0;
}
#------------------------------------------------
sub compareScheduleTable {
# Compare the scheduled events with the displayed events
# This assumes $Stmt is defined such that it returns the displayed events
#---------------------------------------------------------------------------
my $Stmt = shift;
writeDebug("Building show list for $sql_start through $sql_end");
writeDebug("Building show list containing channels $inp_firsttune - $inp_lasttune");
writeDebug("SQL: $Stmt");
my $db_handle = &StartDSN;
my $sth = sqlStmt($db_handle,$Stmt);
if ($sth) {
while ( $row = $sth->fetchrow_hashref ) {
$program_id = $row->{'programid'};
$program_start = sqltotimestring($row->{'starttime'});
$program_true_start = $program_start;
$program_stop = sqltotimestring($row->{'endtime'});
$program_true_stop = $program_stop;
$program_title = $row->{'title'};
$program_subtitle = $row->{'subtitle'};
$program_desc = $row->{'description'};
$program_tuning = $row->{'tuning'};
$program_channel = $row->{'channel'};
$program_category = $row->{'category'};
$program_mpaarating = $row->{'mpaarating'};
$program_vchiprating = $row->{'vchiprating'};
$program_episodenum = $row->{'episodenum'};
$program_movieyear = int $row->{'movieyear'};
$program_stereo = int $row->{'stereo'};
$program_repeat = int $row->{'repeat'};
$program_starrating = $row->{'starrating'};
$program_captions = $row->{'captions'};
if (as_epoch_seconds($program_stop) < as_epoch_seconds($program_start)) {
$program_stop = as_time_string($rng_end);
$fudged_length = 1;
}
#-------------------------------------------------------------------
# Prepare Variables and Calculate Running Time
#-------------------------------------------------------------------
$program_length = getMinutes($program_start,$program_stop);
$display_length = $program_length;
if ($program_id eq $prev_id) {
next;
}
$tempvar = isScheduled($program_true_start,$program_channel,$program_title,$program_repeat);
if (length($tempvar) > 0) {
if (length($showlist) > 0) {
$showlist .= "|";
}
$showlist .= $tempvar;
}
$prev_id = $program_id;
}
}
endDSN("",$db_handle);
undef $db_handle;
return 1;
}
#------------------------------------------------
sub getScheduleDetails {
#
# Check if a show is scheduled, and if so, return an icon
#---------------------------------------------------------------------------
my $inp_programid = shift;
my $inp_timing = shift;
my $retval = "";
my $theme_icon = "";
my $specialdebug = 0;
my $Stmt = "";
if ($specialdebug) {
writeDebug("getScheduleDetails::starting($inp_programid,$inp_timing)");
}
my $db_handle = &StartDSN;
$Stmt = "SELECT * FROM $db_table_tvlistings WHERE programid = '$inp_programid';";
my $sth = sqlStmt($db_handle,$Stmt);
if ($specialdebug) {
writeDebug("getScheduleDetails::DSN: $db_handle STH: $sth ($Stmt)");
}
if ( $sth ) {
$row = $sth->fetchrow_hashref;
$program_starttime = sqltotimestring($row->{'starttime'});
$program_true_start = $program_starttime;
$program_stop = sqltotimestring($row->{'endtime'});
$program_tuning = int $row->{'tuning'};
$program_title = $row->{'title'};
$program_subtitle = $row->{'subtitle'};
$program_desc = $row->{'description'};
$program_category = $row->{'category'};
$program_advisories = $row->{'advisories'};
$program_mpaarating = $row->{'mpaarating'};
$program_vchiprating = $row->{'vchiprating'};
$program_episodenum = $row->{'episodenum'};
$program_movieyear = int $row->{'movieyear'};
$program_stereo = int $row->{'stereo'};
$program_repeat = int $row->{'repeat'};
$program_starrating = $row->{'starrating'};
$program_captions = $row->{'captions'};
$program_channel = $row->{'channel'};
($program_stars,$junk) = split(/\//,$program_starrating);
$fudged_length = 0;
if (as_epoch_seconds($program_stop) < as_epoch_seconds($program_starttime)) {
$program_stop = as_time_string($rng_end);
$fudged_length = 1;
}
$program_length = getMinutes($program_starttime,$program_stop);
}else{
writeDebug("getScheduleDetails::Lookup Failed: $Stmt / Error: " . &GetLastSQLError());
}
endDSN($sth,$db_handle);
if ($rtvaccess > 0) {
if ($specialdebug) {
writeDebug("getScheduleDetails::rtvaccess enabled, getting schedule icons");
writeDebug("getScheduleDetails::$program_true_start,$program_channel,$program_title,$program_repeat");
}
$isScheduled = isScheduled($program_true_start,$program_channel,$program_title,$program_repeat);
if ($specialdebug) {
writeDebug("getScheduleDetails::isScheduled: $isScheduled");
writeDebug(as_hhmm(as_epoch_seconds($program_true_start)));
}
if (length($isScheduled) > 0) {
$retval .= buildIcon($isScheduled);
if ($showrtvthemes) {
if (length($showlist) < 1) {
$theme_icon = getThemeIcon($isScheduled);
}else{
$theme_icon = getThemeIcon($showlist);
}
}
$retval .= $theme_icon;
}
}else{
if ($specialdebug) {
writeDebug("getScheduleDetails::rtvaccess disabled");
}
$isScheduled = 0;
}
#-------------------------------------------------------------------
# Color Code the Column
#-------------------------------------------------------------------
if (length($theme_icon)) {
$bgcolor = $color_theme[ $inp_timing ];
} elsif(length($retval)) {
$bgcolor = $color_scheduled[ $inp_timing ];
}
if ($specialdebug) {
writeDebug("getScheduleDetails::exiting($retval)");
}
return $retval;
}
#---------------------------------------------------------------------------------------
sub getThemeIcon {
#
# Return the Icon for the Theme Recording
#
# Parameter: rtvevent structure, separate multiples with a |
#
# ------------------------------------------------------------------------------
my $rtvdata = shift;
my $specialdebug = 0; # Enable Debug Logging
my $programtitle = $program_title;
my $retaddr = "";
my $themetext = "";
my $theme_icon_alt = "";
my $themeicon = "";
my $ctr = 0;
my $overlap_flag = 0;
my $curr_rtv = "";
my $curr_show = "";
my $slotstart = as_epoch_seconds($program_true_start);
my $slotstop = as_epoch_seconds($program_stop) - 1;
my $showstart = 0;
my $showstop = 0;
my $laststart = 0;
my $laststop = 0;
my $lasttuning = 0;
my $lastcreate = 0;
my $lastguaranteed = 0;
my $lasttype = 0;
if ($specialdebug) {
writeDebug("getThemeIcon::starting($rtvdata)");
writeDebug("getThemeIcon::" . as_hhmm(as_epoch_seconds($program_true_start)) . " for $program_tuning ($program_channel) \"$programtitle\"");
}
if (length($rtvdata) < 1) {
#----------------------------------------------
# No scheduled data, nothing to do!
#----------------------------------------------
if ($specialdebug) {
writeDebug("getThemeIcon::nothing to do");
writeDebug("getThemeIcon::(exiting)");
}
return $retval;
}else{
if ($specialdebug) {
writeDebug("getThemeIcon::$rtvdata");
}
}
if (length(isTheme($program_title)) < 1) {
#----------------------------------------------
# Not a theme, might as well just quit now!
#----------------------------------------------
if ($specialdebug) {
writeDebug("getThemeIcon::$program_title is not a theme");
writeDebug("getThemeIcon::(exiting)");
}
return $retval;
}
#------------------------------------------------------
# Initialize
#------------------------------------------------------
for ( split /,/, $replaylist ) {
/,/;
$curr_rtv = $rtvaddress{$_};
$ctr = 0;
do {
$ctr++;
$curr_show = $scheduledshows{$curr_rtv}[$ctr];
$scheduledshows{$curr_rtv}[$ctr] = "";
} while (length($curr_show) > 0);
$retval{$curr_rtv} = "";
}
#-----------------------------------------------------
# For each Replay build a list of shows that overlap
# with the slot.
#
# (Basically this sorts by address)
#-----------------------------------------------------
for ( split /,/, $replaylist ) {
/,/;
$curr_rtv = $rtvaddress{$_};
$ctr = 0;
for ( split /\|/, $rtvdata ) {
/\|/;
(my $replayid,my $rtveventtime,my $guaranteed,my $channeltype,my $daysofweek,my $channelflags,my $beforepadding,my $afterpadding,my $showlabel,my $channelname,my $themeflags,my $themestring,my $thememinutes,my $rtvcreate,my $scheduledtime,my $programtuning,my $displaylength,my $programtruestart) = split(/;/,$_);
$eventtime = timegm(gmtime($rtveventtime));
$showstart = $scheduledtime;
$showstop = $scheduledtime + ($displaylength * 60) -1;
if ($curr_rtv eq $rtvaddress{$replayid}) {
$overlap_flag = 0;
$overlap_flag = &doTimesOverlap($slotstart,$slotstop,$showstart,$showstop);
if ($specialdebug) {
writeDebug("getThemeIcon::$replayid,OF:$overlap_flag,SLOTS:$slotstart,SLOTE:$slotstop,SHOWS:$showstart,SHOWE:$showstop;EVENT:$eventtime;CT:$channeltype;SL:$showlabel");
}
if ($overlap_flag) {
$ctr++;
$scheduledshows{$rtvaddress{$replayid}}[$ctr] = $_;
if ($specialdebug) {
writeDebug("getThemeIcon::found a candidate for $rtvaddress{$replayid} (#$ctr)");
}
}
}
}
}
#----------------------------------------------------
# Now that we have the list of potentials we need
# to do conflict resolution (if there's more than one
# qualifying show) for each Replay.
#----------------------------------------------------
if ($specialdebug) {
writeDebug("getThemeIcon::resolving conflicts");
}
for ( split /,/, $replaylist ) {
/,/;
$curr_rtv = $rtvaddress{$_};
$ctr = 0;
if ($specialdebug) {
writeDebug("getThemeIcon::resolving conflicts for $curr_rtv");
}
do {
$ctr++;
$curr_show = $scheduledshows{$curr_rtv}[$ctr];
if ($specialdebug) {
writeDebug("getThemeIcon::$curr_rtv: $ctr \"$curr_show\"");
}
if (length($curr_show) > 0) {
(my $replayid,my $rtveventtime,my $guaranteed,my $channeltype,my $daysofweek,my $channelflags,my $beforepadding,my $afterpadding,my $showlabel,my $channelname,my $themeflags,my $themestring,my $thememinutes,my $rtvcreate,my $scheduledtime,my $programtuning,my $displaylength,my $programtruestart) = split(/;/,$curr_show);
$eventtime = timegm(gmtime($rtveventtime));
if (length($showlabel) > 0) {
$showlabel = normalizertvname($showlabel);
}
if (length($themestring) > 0) {
$themestring = normalizertvname($themestring);
}
if ($specialdebug) {
writeDebug("getThemeIcon::$curr_rtv: $channeltype $showlabel ");
}
$showstart = $scheduledtime;
$showstop = $scheduledtime + ($displaylength * 60) -1;
$overlap_flag = 0;
$overlap_flag = doTimesOverlap($showstart,$showstop,$laststart,$laststop);
if ($overlap_flag > 0) {
if ($specialdebug) {
writeDebug("getThemeIcon::$curr_rtv: $channeltype $showlabel: Overlap Detected. Using Mode: $rtv_version{$replayid} for Conflict Checks for $showlabel ($themestring) type: $channeltype");
}
if ($rtv_version{$replayid} == 2) {
#--------------------------------------------------------
# 5.x Conflict Resolution
#--------------------------------------------------------
if ($rtvcreate > $lastcreate) {
$retval{$curr_rtv} = $image_tw;
}else{
$retval{$curr_rtv} = $image_tl;
}
}else{
#--------------------------------------------------------
# 4.x Conflict Resolution
#--------------------------------------------------------
if ($programtuning > $lasttuning) {
$retval{$curr_rtv} = $image_tw;
}else{
$retval{$curr_rtv} = $image_tl;
}
}
#---------------------------------------------------------------
# If the previous one is guaranteed and this one isn't, this one
# will lose.
#---------------------------------------------------------------
if ($specialdebug) {
writeDebug("getThemeIcon::$curr_rtv: $channeltype $showlabel: checking guaranteed levels $guaranteed vs $lastguaranteed");
}
if ($guaranteed > $lastguaranteed) {
$retval{$curr_rtv} = $image_tw;
}else{
$retval{$curr_rtv} = $image_tl;
}
#---------------------------------------------------------------
# If it's up against a replaychannel (recurring or single) it
# loses immediately.
#
# NOTE: This may no longer be true for 5.0
#
#---------------------------------------------------------------
if ($specialdebug) {
writeDebug("getThemeIcon::$curr_rtv: $channeltype $showlabel: checking to see if current overlap is not a theme ($channeltype)");
}
if (($channeltype == 1) || ($channeltype == 3 )) {
$retval{$curr_rtv} = $image_tl;
if (($programtuning == $lasttuning) && ($lasttype == 2)){
#-------------------------------------------------------
# If it matches as both a replaychannel AND a theme,
# just hide the theme.
#
# If you'd rather see both comment the following line
# out.
#
#-------------------------------------------------------
$retval{$curr_rtv} = "";
}
next;
}
#---------------------------------------------------------------
# If the theme just won't fit, it goes away.
#---------------------------------------------------------------
if ($speicaldebug) {
writeDebug("getThemeIcon::$curr_rtv: $channeltype $showlabel: checking to see if $display_length fits in $thememinutes");
}
if ($thememinutes < $display_length) {
$retval{$curr_rtv} = $image_tl;
}
$lasttuning = $programtuning;
$lastcreate = $rtvcreate;
$lastguaranteed = $guaranteed;
$lasttype = $channeltype;
}else{
if ($channeltype == 2) {
if ($specialdebug) {
writeDebug("getThemeIcon::$curr_rtv: $channeltype $showlabel: won due to no overlap");
}
$retval{$curr_rtv} = $image_tw;
$lasttuning = $programtuning;
$lastcreate = $rtvcreate;
$lastguaranteed = $guaranteed;
$lasttype = $channeltype;
}else{
if ($specialdebug) {
writeDebug("getThemeIcon::$curr_rtv: $channeltype $showlabel: no winner this round (not a theme)");
}
}
}
$laststart = $showstart;
$laststop = $showstop;
}
#-------------------------------------------------------
# If the only entry for this Replay's slot is a theme
# it wins automatically if the show fits in the theme.
#-------------------------------------------------------
if (($ctr == 2) && (length($scheduledshows{$curr_rtv}[$ctr]) < 1)) {
(my $replayid,my $rtveventtime,my $guaranteed,my $channeltype,my $daysofweek,my $channelflags,my $beforepadding,my $afterpadding,my $showlabel,my $channelname,my $themeflags,my $themestring,my $thememinutes,my $rtvcreate,my $scheduledtime,my $programtuning,my $displaylength,my $programtruestart) = split(/;/,$scheduledshows{$curr_rtv}[1]);
if ($channeltype == 2) {
if ($specialdebug) {
writeDebug("getThemeIcon::$themestring is winning by default");
}
if ($specialdebug) {
writeDebug("getThemeIcon::checking to see if $display_length fits in $thememinutes");
}
if ($thememinutes < $display_length) {
$retval{$curr_rtv} = $image_tl;
}else{
$retval{$curr_rtv} = $image_tw;
}
}
}
} while (length($curr_show) > 0);
}
#----------------------------------------------------
# By this point we should have a winner for each
# Replay in the list.
#
# $retval{address} contains the winning or losing
# image name ($image_tw or $image_tl) - or null.
#----------------------------------------------------
#----------------------------------------------------
# Build the icon for each Replay
#----------------------------------------------------
for ( split /,/, $replaylist ) {
/,/;
if (length($retval{$rtvaddress{$_}}) > 0 ) {
if (length($themeicon) > 0) {
$themeicon .= " / ";
}
if ($retval{$rtvaddress{$_}} eq $image_tl) {
$themetext = "Theme in Conflict";
}
if ($retval{$rtvaddress{$_}} eq $image_tw) {
$themetext = "Theme";
}
$theme_icon_alt = $rtvlabel{$_} . " - " . $themetext;
if ($showrtvicons) {
if (length($retval{$rtvaddress{$_}})) {
if (substr($retval{$rtvaddress{$_}},0,7) eq "http://" ) {
$themeicon .= "<img src=$retval{$rtvaddress{$_}} ALT=\"$theme_icon_alt\">";
}else{
$themeicon .= "<img src=$imagedir/$retval{$rtvaddress{$_}} ALT=\"$theme_icon_alt\">";
}
if ($showrtvtext) {
$themeicon .= "($theme_icon_alt)";
}
}
}else{
if ($retval{$rtvaddress{$_}} eq $image_tl) {
$themetext = "Theme in Conflict";
}
if ($retval{$rtvaddress{$_}} eq $image_tw) {
$themetext = "Theme";
}
if ($showrtvtext) {
$themeicon .= "$theme_icon_alt: $themetext";
}
}
}
}
#----------------------------------------------------
# Exit
#----------------------------------------------------
if ($specialdebug) {
writeDebug("getThemeIcon::themeicon: $themeicon");
writeDebug("getThemeIcon::(exiting)");
}
return $themeicon;
}
#---------------------------------------------------------------------------------------
sub buildIcon {
#
# Build a RTV Status Icon
#
# Parameter: one or more rtvevent structs separated by a |
#
# ------------------------------------------------------------------------------
my $rtvdata = shift;
my $retval = "";
my $program_icon = "";
my $program_icon_alt = "";
my $program_text = "";
if (length($rtvdata) < 1) {
return $retval;
}
for ( split /\|/, $rtvdata ) {
/\|/;
(my $replayid,my $rtveventtime,my $guaranteed,my $channeltype,my $daysofweek,my $channelflags,my $beforepadding,my $afterpadding,my $showlabel,my $channelname,my $themeflags,my $themestring,my $thememinutes,my $rtvcreate,my $scheduledtime,my $programtuning,my $displaylength,my $programtruestart) = split(/;/,$_);
my $recurring = 0;