-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhdhr_VCR.applescript
3308 lines (3116 loc) · 179 KB
/
hdhr_VCR.applescript
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
global Local_env
global Show_info
global Locale
global Hostname
global Channel_list
global HDHR_DEVICE_LIST
global Idle_timer
global Idle_timer_default
global Idle_count_delay
global Idle_count
global Idle_timer_dateobj
global Version_local
global Version_remote
global Version_url
global Online_detected
global Hdhr_detected
global Hdhr_config
global Hdhr_setup_folder
global Notify_upnext
global Notify_recording
global Hdhr_setup_ran
global Configfilename_json
global Logfilename
global Time_slide
global Dialog_timeout
global Temp_dir
global Config_dir
global Log_dir
global Back_channel
global Config_version
global Debugger_apps
global Local_ip
global Fail_count
--Icons
global Icon_record
global Shutdown_reason
global Lf
global Logger_levels
global Logger_levels_all
global Loglines_written
global Loglines_max
global Missing_tuner_retry_count
global Check_after_midnight_time
global First_open
global Show_status_list
global LibScript
## Since we use JSON helper to do some of the work, we should declare it, so we dont end up having to use tell blocks everywhere. If we declare 1 thing, we have to declare everything we are using.
use AppleScript version "2.4"
use scripting additions
use application "JSON Helper"
########## These are reserved handlers, we do specific things in them ##########
on loadIcons(caller)
try
set Icon_record to {Warning_icon:character id {9888, 65039}, Play_icon:character id 9654, Record_icon:character id 128308, Recordsoon_icon:character id 11093, Tv_icon:character id 128250, Plus_icon:character id 10133, Single_icon:character id {49, 65039, 8419}, Series_icon:character id 128257, Series1_icon:character id 128258, Inactive_icon:character id 9940, Edit_icon:character id {9999, 65039}, Soon_icon:character id 128284, Disk_icon:character id 128190, Update_icon:character id 8682, Stop_icon:character id 9726, Up_icon:character id 128316, Up1_icon:character id 128314, Up2_icon:character id 9195, Check_icon:character id 9989, Uncheck_icon:character id 10060, Futureshow_icon:character id {9197, 65039}, Calendar_icon:character id 128197, Calendar2_icon:character id 128198, Hourglass_icon:character id 8987, Film_icon:character id 127910, Back_icon:character id 8592, Done_icon:character id 9989, Running_icon:character id {127939, 8205, 9794, 65039}, Add_icon:character id 127381}
on error errmsg
return false
end try
return true
end loadIcons
on setup_script(caller)
try
set Local_env to (name of current application)
set Lf to "
"
set Version_local to "20240907"
set Config_version to 1
set temp_info to (system info)
set Local_ip to IPv4 address of temp_info
set Locale to user locale of temp_info
set Hostname to host name of temp_info
set Hdhr_setup_folder to "Volumes:"
set Configfilename_json to ((name of me) & "-" & Hostname & ".json") as text
set Logfilename to (name of me) & ".log" as text
set Version_url to "https://raw.githubusercontent.com/identd113/hdhr_VCR-AS/master/version.json"
set Version_remote to "0"
set Idle_count_delay to 0
set Config_dir to path to documents folder
do shell script "mkdir -p ~/Library/Caches/" & (name of me) & "/"
copy (current date) to Idle_timer_dateobj
set Debugger_apps to {"Script Editor", "Script Debugger", "Smile"}
on error errmsg
return false
end try
return true
end setup_script
on setup_globals(caller)
try
set Fail_count to 5
set HDHR_DEVICE_LIST to {}
set Show_info to {}
set Hdhr_config to {}
set Notify_upnext to 35
set Notify_recording to 15.5
set Time_slide to 0
set Dialog_timeout to 60
set Idle_timer to 6
set Idle_timer_default to 10
set Idle_count to 0
set Temp_dir to alias "Volumes:"
set Online_detected to false
set Hdhr_detected to false
set Back_channel to missing value
set Missing_tuner_retry_count to 0
set Shutdown_reason to "No shutdown attempted"
set Show_status_list to {}
on error errmsg
return false
end try
return true
end setup_globals
on setup_logging(caller)
try
set Log_dir to alias ((path to library folder from user domain) & "Logs" as text)
set Logger_levels_all to {"INFO", "WARN", "ERROR", "NEAT", "FATAL", "DEBUG", "TRACE"}
if Local_env is in Debugger_apps then
set Logger_levels to Logger_levels_all
else
set Logger_levels to {"INFO", "WARN", "ERROR", "NEAT", "FATAL"}
end if
set Loglines_written to 0
set Loglines_max to 2000 + ((length of Show_info) * 100)
on error errmsg
return false
end try
return true
end setup_logging
on run {}
-- This is the handler that loads first after the app is launched.
copy (round (random number from 1000 to 9999)) to run_uniq
set errloc to ""
set startup_success to false
set progress description to "Setting up script..."
if my setup_script(run_uniq) is true then
set progress description to "Setting up globals..."
if my setup_globals(run_uniq) is true then
set progress description to "Setting up logging..."
if my setup_logging(run_uniq) is true then
set progress description to "Setting up icons..."
if my loadIcons(run_uniq) is true then
set startup_success to true
set progress description to "Loading " & name of me & " " & Version_local
else
set errloc to "loadIcons"
end if
else
set errloc to "Logging"
end if
else
set errloc to "Globals"
end if
else
set errloc to "Setup"
end if
if errloc is not "" then
--log "THE_ERROR: " & errloc
end if
if Locale is not "en_US" then
display dialog "Due to poor planning on my part, only en_US regions can use this script, sorry!"
quit {}
return
end if
if startup_success is true then
my logger(true, "init(" & run_uniq & ")", "INFO", "***** Starting " & name of me & " " & Version_local & " *****")
## Lets check for a new version! This will trigger OSX to prompt for confirmation to talk to JSONHelper, the library we use for JSON related matters.
my check_version(run_uniq)
if Online_detected is true then
my HDHRDeviceDiscovery("run(" & run_uniq & ")", "")
else
my logger(true, "init(" & run_uniq & ")", "ERROR", "online_detected is " & Online_detected)
end if
my logger(true, "run(" & run_uniq & ")", "INFO", "AreWeOnline: " & my AreWeOnline("run(" & run_uniq & ")"))
my showPathVerify("run(" & run_uniq & ")", "")
my show_info_dump("run(" & run_uniq & ")", "", false)
my existing_shows("run(" & run_uniq & ")")
set First_open to true
my logger(true, "run(" & run_uniq & ")", "INFO", "Initial main() skipped, to be run at the end of idle")
if First_open is false then
my main("run(" & run_uniq & ")", "run")
end if
try
-- my loadlib()
end try
if Local_env is in Debugger_apps then
my main("run(debug_loop)", "run")
end if
my build_channel_list("run(" & run_uniq & ")", "")
if Local_env is not in Debugger_apps then
my rotate_logs("run(" & run_uniq & ")", (Log_dir & Logfilename as text))
end if
end if
my logger(true, "run(" & run_uniq & ")", "INFO", "End of run() handler")
end run
on loadlib()
tell application "Finder"
set loaded_auth_script_path to (path to documents folder as text) & "hdhr_VCR_lib.scpt"
set loaded_auth_script_alias to loaded_auth_script_path as alias
end tell
-- Load the script using the alias
set LibScript to load script loaded_auth_script_alias
load_hdhrVCR_vars() of LibScript
log LibScript
end loadlib
## This script will loop through this every 12 seconds, or whatever the return value is (Idle_timer), in second is at the bottom of this handler.
on idle
copy (round (random number from 1000 to 9999)) to idle_uniq
copy (current date) to cd
copy cd + (Idle_timer) to cd_object
if Idle_timer is not Idle_timer_default then
my logger(true, "idle(" & idle_uniq & ")", "INFO", "START Idle_timer: " & Idle_timer)
end if
if "TRACE" is in Logger_levels then
set progress description to "Start Idle Loop"
set progress total steps to 2
set progress completed steps to 1
delay 0.1
end if
if cd is greater than Idle_timer_dateobj and Idle_timer is not Idle_timer_default then
set Idle_timer to Idle_timer_default
my logger(true, "idle(" & idle_uniq & ")", "TRACE", "idle_timer set to " & Idle_timer_default)
set Idle_timer_dateobj to cd
end if
try
set Idle_count to Idle_count + Idle_timer
--my logger(true, "idle(1.5)", "DEBUG", "Idle seconds: " & Idle_count)
try
if length of HDHR_DEVICE_LIST is greater than 0 then
repeat with i2 from 1 to length of HDHR_DEVICE_LIST
if hdhr_guide_update of item i2 of HDHR_DEVICE_LIST is not missing value then
if minutes of (cd) is in {2, 32} then
if ((cd) - (hdhr_guide_update of item i2 of HDHR_DEVICE_LIST)) div 60 is greater than or equal to 5 then
my logger(true, "idle4(" & idle_uniq & ")", "INFO", "Periodic update of tuner " & device_id of item i2 of HDHR_DEVICE_LIST & ", last update: " & hdhr_guide_update of item i2 of HDHR_DEVICE_LIST)
try
with timeout of 15 seconds
my HDHRDeviceDiscovery("idle5(" & idle_uniq & ")", device_id of item i2 of HDHR_DEVICE_LIST)
end timeout
my save_data("idle5.1(" & idle_uniq & ")")
on error errmsg
my logger(true, "idle6(" & idle_uniq & ")", "ERROR", "Unable to update HDHRDeviceDiscovery, errmsg " & errmsg)
end try
my logger(true, "idle7(" & idle_uniq & ")", "INFO", "Tuners refresh complete")
else
--my logger(true, "idle8(" & idle_uniq & ")", "WARN", "HDHR update did not run, last run: " & hdhr_guide_update of item i2 of HDHR_DEVICE_LIST)
end if
end if
end if
end repeat
else
try
my logger(true, "idle91(" & idle_uniq & ")", "WARN", "No HDHR Device Detected")
my HDHRDeviceDiscovery("idle51(" & idle_uniq & ")", "")
end try
end if
on error errmsg
my logger(true, "idle8(" & idle_uniq & ")", "ERROR", "An error occured: " & errmsg as text)
end try
try
if length of Show_info is greater than 0 and length of HDHR_DEVICE_LIST is greater than 0 then
repeat with i from 1 to length of Show_info
repeat 1 times
if show_active of item i of Show_info is true then
if show_next of item i of Show_info is less than or equal to cd_object then
if show_recording of item i of Show_info is false then
if my HDHRDeviceSearch("idle71(" & idle_uniq & ")", hdhr_record of item i of Show_info) is 0 then
--We could walk the user through reassigning a tuner.
if Missing_tuner_retry_count is less than or equal to 3 then
my logger(true, "idle81(" & idle_uniq & ")", "WARN", "The tuner, " & hdhr_record of item i of Show_info & ", does not exist, refreshing tuners")
my HDHRDeviceDiscovery("idle82(" & idle_uniq & ")", hdhr_record of item i of Show_info)
set Missing_tuner_retry_count to Missing_tuner_retry_count + 1
else if Missing_tuner_retry_count is greater than 3 then
my logger(true, "idle83(" & idle_uniq & ")", "WARN", "Missing tuner, errmsg: " & hdhr_record of item i of Show_info)
end if
exit repeat
end if
if show_end of item i of Show_info is less than or equal to (cd) then
my logger(true, "idle9(" & idle_uniq & ")", "INFO", show_title of item i of Show_info & " ends at " & show_end of item i of Show_info)
if show_is_series of item i of Show_info is true then
set show_next of item i of Show_info to my nextday("idle10(" & idle_uniq & ")", show_id of item i of Show_info)
my logger(true, "idle91(" & idle_uniq & ")", "WARN", show_title of item i of Show_info & " is a series, but passed")
exit repeat
else if show_is_sport of item i of Show_info is false then
set show_active of item i of Show_info to false
my logger(true, "idle92(" & idle_uniq & ")", "WARN", show_title of item i of Show_info & " is a single, and passed, so it was deactivated")
exit repeat
end if
end if
set show_runtime to (show_end of item i of Show_info) - (cd)
set tuner_status_result to my tuner_status2("idle15(" & idle_uniq & ")", hdhr_record of item i of Show_info)
if tunermax of tuner_status_result is greater than tuneractive of tuner_status_result then
--my logger(true, "idle()", "INFO", "2-2")
my logger(true, "idle(" & idle_uniq & ")", "DEBUG", show_title of item i of Show_info)
my logger(true, "idle(" & idle_uniq & ")", "DEBUG", show_next of item i of Show_info)
my logger(true, "idle(" & idle_uniq & ")", "DEBUG", show_time of item i of Show_info)
my logger(true, "idle(" & idle_uniq & ")", "DEBUG", show_end of item i of Show_info)
if item 2 of my showid2PID("idle155(" & idle_uniq & ")", show_id of item i of Show_info, false, true) is {} then
my record_now("idle32(" & idle_uniq & ")", (show_id of item i of Show_info), show_runtime, true)
if (show_fail_count of item i of Show_info) is less than Fail_count then
display notification "Ends " & my short_date("rec started", show_end of item i of Show_info, false, false) with title Recordsoon_icon of Icon_record & " Started Recording on (" & hdhr_record of item i of Show_info & ")" subtitle quote & show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info & " (" & my channel2name("idle16(" & idle_uniq & ")", show_channel of item i of Show_info as text, hdhr_record of item i of Show_info) & ")"
set notify_recording_time of item i of Show_info to (cd) + (2 * minutes)
end if
else
my logger(true, "idle(156)", "WARN", "Recording already in progeress, marking " & show_id of item i of Show_info & " as recording")
set show_recording of item i of Show_info to true
end if
else
display notification Hourglass_icon of Icon_record & " Delaying for " & Idle_timer & " seconds" with title "Tuner unavailable (" & hdhr_record of item i of Show_info & ")" subtitle show_title of item i of Show_info
end if
else --show_recording true
if (show_end of item i of Show_info) - (cd) is less than or equal to Idle_timer then
my delay_idle_loop("idle(" & idle_uniq & ")", 1)
end if
if notify_recording_time of item i of Show_info is less than (cd) or notify_recording_time of item i of Show_info is missing value then
display notification "Ends " & my short_date("rec progress", show_end of item i of Show_info, false, false) & " (" & (my ms2time("idle(19)", (show_end of item i of Show_info) - (cd), "s", 3)) & ") " with title Record_icon of Icon_record & " Recording in progress (" & hdhr_record of item i of Show_info & ")" subtitle quote & show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info & " (" & my channel2name("idle20(" & idle_uniq & ")", show_channel of item i of Show_info as text, hdhr_record of item i of Show_info) & ")"
set notify_recording_time of item i of Show_info to (cd) + (Notify_recording * minutes)
my logger(true, "idle21(" & idle_uniq & ")", "INFO", "Recording in progress for " & quote & (show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info & ", ends in " & my ms2time("idle_rip(19.1)", (show_end of item i of Show_info) - (cd), "s", 3)) & ", Next Update: " & time string of (notify_recording_time of item i of Show_info))
my tuner_inuse("idle22(" & idle_uniq & ")", hdhr_record of item i of Show_info)
my update_folder("idle(22.2)", show_dir of item i of Show_info)
--set notify_recording_time of item i of Show_info to (cd) + (Notify_recording * minutes)
end if
set check_showid_recording to item 2 of my showid2PID("idle(" & idle_uniq & ")", show_id of item i of Show_info, false, false)
--fix might need to check to make sure there is a value here.
my logger(true, "idle21-2(" & idle_uniq & ")", "TRACE", "check_showid_recording: " & check_showid_recording)
if length of check_showid_recording is 0 then
my delay_idle_loop("idle(" & idle_uniq & ")", 1)
my logger(true, "idle21-21(" & idle_uniq & ")", "WARN", show_title of item i of Show_info & " (" & show_id of item i of Show_info & ") is marked as recording, but we do not have a valid PID, setting show_recording to false")
set show_recording of item i of Show_info to false
end if
end if
else --show time has not passed.
if (notify_upnext_time of item i of Show_info is less than (cd) or notify_upnext_time of item i of Show_info is missing value) and (show_next of item i of Show_info) - (cd) is less than or equal to 1 * hours and show_recording of item i of Show_info is false then
--my logger(true, "idle()", "INFO", "1-2")
display notification "Starts: " & my short_date("idle11(" & idle_uniq & ")", show_next of item i of Show_info, false, false) & " (" & my ms2time("idle12(" & idle_uniq & ")", ((show_next of item i of Show_info) - (cd)), "s", 3) & ")" with title Film_icon of Icon_record & " Next Up on (" & hdhr_record of item i of Show_info & ")" subtitle quote & show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info & " (" & my channel2name("idle13(" & idle_uniq & ")", show_channel of item i of Show_info, hdhr_record of item i of Show_info) & ")"
my logger(true, "idle14(" & idle_uniq & ")", "INFO", "Next Up: " & quote & show_title of item i of Show_info & quote & " on " & hdhr_record of item i of Show_info)
set notify_upnext_time of item i of Show_info to (cd) + (Notify_upnext * minutes)
end if
end if
end if
if show_recording of item i of Show_info is true then
my logger(true, "idle(" & idle_uniq & ")", "TRACE", "Show end for " & show_title of item i of Show_info & " is " & show_end of item i of Show_info)
my logger(true, "idle(" & idle_uniq & ")", "TRACE", cd)
if (show_end of item i of Show_info) is less than or equal to cd then
set show_recording of item i of Show_info to false
set show_last of item i of Show_info to show_end of item i of Show_info
set temp_guide_data to my channel_guide("idle(23 recording_ended)", hdhr_record of item i of Show_info, show_channel of item i of Show_info, show_time of item i of Show_info)
-- FIX The show may not be done recording, so this may not be sticky. If we could verify that the PID is gone, then we can attempt to update the file.
set temp_OriginalAirdate to {}
try
set temp_OriginalAirdate to my getTfromN(OriginalAirdate of temp_guide_data)
on error errmsg
my logger(true, "idle(OriginalAirdate)", "WARN", "OriginalAirdate does not exist for " & quote & show_title of item i of Show_info & quote)
end try
try
if (temp_OriginalAirdate) is not {} then
--if (OriginalAirdate of temp_guide_data) is not {} then
set temp_dateobject to my epoch2datetime("idle(epoch)", temp_OriginalAirdate)
my logger(true, "idle(epoch)", "INFO", "Epoch time converted to dateobject")
try
if show_recording_path of item i of Show_info is not in {missing value, {}, ""} then
my date2touch("idle(set_date_modified)", temp_dateobject, show_recording_path of item i of Show_info)
my logger(true, "idle(epoch)", "INFO", "Successfully modified the date of " & quote & show_title of item i of Show_info & quote)
end if
on error errmsg
my logger(true, "idle(epoch)", "WARN", "Unable to modify date of " & quote & show_title of item i of Show_info & quote & ", errmsg: " & errmsg)
end try
my logger(true, "idle24.5(" & idle_uniq & ")", "INFO", "OriginalAirdate of " & quote & show_title of item i of Show_info & quote & " " & temp_OriginalAirdate)
end if
on error errmsg
my logger(true, "idle_epoch(" & idle_uniq & ")", "WARN", "Epoch time NOT converted, errmsg: " & errmsg)
set temp_OriginalAirdate to "Failed"
end try
if show_is_series of item i of Show_info is true then
set show_next of item i of Show_info to my nextday("idle24(" & idle_uniq & ")", show_id of item i of Show_info)
set show_recorded_today of item i of Show_info to true
set show_fail_count of item i of Show_info to 0
my logger(true, "idle25(" & idle_uniq & ")", "INFO", "Recording Complete for " & quote & (show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info))
display notification "Next Showing: " & my short_date("idle26(" & idle_uniq & ")", show_next of item i of Show_info, false, false) with title Stop_icon of Icon_record & " Recording Complete" subtitle (quote & show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info & " (" & my channel2name("idle(27)", show_channel of item i of Show_info as text, hdhr_record of item i of Show_info) & ")")
else
if show_is_sport of item i of Show_info is false then
set show_active of item i of Show_info to false
set show_fail_count of item i of Show_info to 0
my logger(true, "idle28(" & idle_uniq & ")", "INFO", "Recording Complete for " & quote & (show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info & " and marked inactive"))
display notification "Show marked inactive" with title Stop_icon of Icon_record & " Recording Complete" subtitle (quote & show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info & " (" & my channel2name("idle27(" & idle_uniq & ")", show_channel of item i of Show_info as text, hdhr_record of item i of Show_info) & ")")
else
my logger(true, "idle28(" & idle_uniq & ")", "INFO", show_title of item i of Show_info & " is a sport, and we are in bonus time")
-- FIX We do not want to automatically mark sport shows as inactive, brecause we might be in the bonus 30 minutes.
end if
end if
try
if show_time_orig of item i of Show_info is not in {missing value, "missing value"} and (show_time of item i of Show_info as number) is not (show_time_orig of item i of Show_info as number) and show_active of item i of Show_info is true then
my logger(true, "idle281(" & idle_uniq & ")", "INFO", "Show: " & show_title of item i of Show_info & " reverted to " & show_time_orig of item i of Show_info & ", was " & show_time of item i of Show_info)
set show_time of item i of Show_info to show_time_orig of item i of Show_info
end if
on error errmsg
my logger(true, "idle282(" & idle_uniq & ")", "WARN", "Show " & show_title of item i of Show_info & " unable to revert to show_time_orig, err: " & errmsg)
end try
end if
else if show_is_series of item i of Show_info is false and show_end of item i of Show_info is less than or equal to (cd) and show_active of item i of Show_info is true then
set show_active of item i of Show_info to false
my logger(true, "idle29(" & idle_uniq & ")", "INFO", "Show: " & show_title of item i of Show_info & " was deactivated, as it is a single, and recording time has passed")
display notification "Show: " & show_title of item i of Show_info & " removed" with title Stop_icon of Icon_record
end if
end repeat
end repeat
else
my logger(true, "idle30(" & idle_uniq & ")", "WARN", "There are no shows setup for recording. If you are seeing this message, and wondering if the script is actually working, it is")
set Idle_timer to 30
end if
on error errmsg
my logger(true, "idle311(" & idle_uniq & ")", "ERROR", errmsg)
end try
on error errmsg
my logger(true, "idle31(" & idle_uniq & ")", "ERROR", errmsg)
end try
--FIX added check for is recording.
if my check_after_midnight("idle(" & idle_uniq & ")") is true then
--if my check_after_midnight("idle(" & idle_uniq & ")") is true then
repeat with i from 1 to length of Show_info
set show_recorded_today of item i of Show_info to false
end repeat
end if
if First_open is true and Idle_count_delay = 0 then
my logger(true, "idle(" & idle_uniq & ")", "INFO", "Now running intial main() at end of idle loop")
my main("idle(" & idle_uniq & ")", "run")
end if
if "TRACE" is in Logger_levels then
set progress description to "END Idle Loop"
set progress completed steps to 2
delay 0.5
end if
my delay_idle_loop("idle(" & idle_uniq & ")", -1)
if Idle_timer is not Idle_timer_default then
my logger(true, "idle(" & idle_uniq & ")", "INFO", "END Idle_timer: " & Idle_timer)
end if
return Idle_timer
end idle
on delay_idle_loop(caller, the_delay)
my logger(true, "delay_idle_loop(" & caller & ")", "TRACE", Idle_count_delay)
if the_delay is less than or equal to 0 then
set Idle_count_delay to 0
else
set Idle_count_delay to Idle_count_delay + the_delay
my temp_auto_delay("delay_idle_loop(" & caller & ")", the_delay)
end if
end delay_idle_loop
on temp_auto_delay(caller, thesec)
set Idle_timer to thesec
copy ((current date) + thesec) to Idle_timer_dateobj
my logger(true, "temp_auto_delay(" & caller & ")", "TRACE", "idle_timer set to " & thesec)
end temp_auto_delay
on reopen {}
my logger(true, "reopen()", "INFO", "User clicked in Dock")
my main("reopen", "reopen()")
end reopen
on quit {}
my logger(true, "quit()", "INFO", "quit() called. We have written " & Loglines_written & " lines")
--add check to see if we are recording.
set hdhr_quit_record to false
set hdhr_quit_record_titles to {}
repeat with i from 1 to length of Show_info
if show_recording of item i of Show_info is true then
set hdhr_quit_record to true
set end of hdhr_quit_record_titles to quote & show_title of item i of Show_info & quote & " on " & show_channel of item i of Show_info
end if
end repeat
if hdhr_quit_record is true then
set systemShutdown to my isSystemShutdown("quit()")
my logger(true, "quit()", "INFO", "systemShutdown: " & systemShutdown)
my logger(true, "quit()", "INFO", "The following shows are marked as currently recording: " & my stringlistflip("quit()", hdhr_quit_record_titles, ",", "string"))
if systemShutdown is false then
try
activate me
end try
set quit_response to button returned of (display dialog "Do you want to cancel these recordings already in progress?" & return & return & my stringlistflip("quit()", hdhr_quit_record_titles, return, "string") buttons {"Go Back", "Yes", "No"} default button 3 with title my check_version_dialog("quit()") giving up after Dialog_timeout with icon caution)
my logger(true, "quit()", "INFO", "quit() user choice for killing shows: " & quit_response)
else
my logger(true, "quit()", "INFO", "" & Shutdown_reason & " detected, killing all recordings, and saving config file")
set quit_response to "Yes"
end if
else
-- my logger(true, "quit()", "INFO", "3SAVE")
my save_data("quit(noshows)")
continue quit
end if
if quit_response is "Yes" then
repeat with i2 from 1 to length of Show_info
if show_recording of item i2 of Show_info is true then
set show_recording of item i2 of Show_info to false
my showid2PID("quit()", show_id of item i2 of Show_info, true, true)
end if
end repeat
my save_data("quit(yes)")
continue quit
end if
if quit_response is "No" then
my save_data("quit(no)")
continue quit
end if
if quit_response is "Go Back" then
my main("quit", "quit(home)")
return
end if
end quit
########## END of reserved handlers ##########
########## These are custom handlers. These are the heart of the script. ##########
on hdhrGRID(caller, hdhr_device, hdhr_channel)
my logger(true, "hdhrGRID(" & caller & ", " & hdhr_device & ", " & hdhr_channel & ")", "INFO", "Started hdhrGRID")
set hdhrGRID_sort to {Back_icon of Icon_record & " Back"}
set Show_status_list to {Back_icon of Icon_record & " Back"}
set hdhrGRID_temp to my channel_guide("hdhrGRID(" & caller & ")", hdhr_device, hdhr_channel, "")
if hdhrGRID_temp is false then
display notification with title "Channel " & hdhr_channel & " has no guide data" subtitle hdhr_device
return false
end if
try
my logger(true, "hdhrGRID(" & caller & ")", "INFO", "Shows returned: " & length of Guide of hdhrGRID_temp & ", channel: " & hdhr_channel & ", hdhr_device: " & hdhr_device)
on error
my logger(true, "hdhrGRID(" & caller & ")", "ERROR", "Unable to get a length of hdhrGRID_temp")
end try
repeat with i from 1 to length of Guide of hdhrGRID_temp
try
set temp_title to (title of item i of Guide of hdhrGRID_temp & " " & quote & EpisodeTitle of item i of Guide of hdhrGRID_temp) & quote
on error
set temp_title to (title of item i of Guide of hdhrGRID_temp)
end try
--Grab the start and end date, so we can pass use this to determine if the show is recording.
set temp_start to my epoch2datetime("hdhrGRID_start(" & caller & ")", my getTfromN(StartTime of item i of Guide of hdhrGRID_temp))
set temp_end to my epoch2datetime("hdhrGRID_end (" & caller & ")", my getTfromN(EndTime of item i of Guide of hdhrGRID_temp))
--my logger(true, "hdhrGRID(" & caller & ")", "ERROR", class of (temp_start))
set show_status to my show_record("hdhrGRID(" & caller & ")", hdhr_device, hdhr_channel, temp_start, temp_end)
set end of Show_status_list to show_status
set end of hdhrGRID_sort to (status_icon of show_status) & " " & my padnum("hdhrGRID", word 2 of my short_date("hdhrGRID1(" & caller & ")", temp_start, false, false), true) & "-" & my padnum("hdhrGRID", word 2 of my short_date("hdhrGRID(" & caller & ")", temp_end, false, false), true) & " " & temp_title
end repeat
set hdhrGRID_selected to choose from list hdhrGRID_sort with prompt ("Channel " & hdhr_channel & " (" & GuideName of hdhrGRID_temp & ")" & return & "Current Time: " & word 2 of my short_date("hdhrGRID(" & caller & ")", (current date), false, false)) cancel button name "Manual Add" OK button name "Next.." with title my check_version_dialog(caller) default items item 1 of hdhrGRID_sort with multiple selections allowed
if hdhrGRID_selected is not {Back_icon of Icon_record & " Back"} then
set selected_show to my list_position("hdhrGRID100(" & caller & ")", hdhrGRID_selected, hdhrGRID_sort, true)
else
set selected_show to 0
my logger(true, "hdhrGRID(" & caller & ")", "INFO", "User pressed back")
end if
my logger(true, "hdhrGRID(" & caller & ")", "INFO", "selected_show: " & selected_show)
if selected_show is greater than or equal to 1 and the_show_id of item selected_show of Show_status_list is not missing value then
my logger(true, "hdhrGRID(" & caller & ")", "INFO", "Editing, instead of adding show")
set Back_channel to hdhr_channel
my validate_show_info("hdhrGRID(" & caller & ")", (the_show_id of item selected_show of Show_status_list), true)
return false
end if
try
if Back_icon of Icon_record & " Back" is in hdhrGRID_selected then
my logger(true, "hdhrGRID(" & caller & ")", "INFO", "Back to channel list " & hdhr_channel)
set Back_channel to hdhr_channel
return true
end if
on error errmsg
my logger(true, "hdhrGRID(" & caller & ")", "WARN", "Back failed, errmsg: " & errmsg)
end try
if my epoch2datetime("hdhrGRID2(" & caller & ")", EndTime of item ((my list_position("hdhrGRID1(" & caller & ")", hdhrGRID_selected, hdhrGRID_sort, false)) - 1) of Guide of hdhrGRID_temp) is less than (current date) then
my logger(true, "hdhrGRID(" & caller & ")", "WARN", "The show time has already passed, returning...")
display notification "The show has already passed, refreshing tuner...."
my HDHRDeviceDiscovery("hdhrGRID(" & caller & ")", hdhr_device)
set Back_channel to hdhr_channel
return true
end if
if hdhrGRID_selected is not false then
set list_position_response to {}
my logger(true, "hdhrGRID(" & caller & ")", "INFO", "Returning guide data for " & hdhr_channel & " on device " & hdhr_device)
repeat with i from 1 to length of hdhrGRID_selected
set end of list_position_response to item ((my list_position("hdhrGRID1", item i of hdhrGRID_selected, hdhrGRID_sort, false)) - 1) of Guide of hdhrGRID_temp
--my logger(true, "hdhrGRID()", "INFO", list_position_response)
end repeat
return list_position_response
else
my logger(true, "hdhrGRID(" & caller & ")", "INFO", "User exited")
return {""}
end if
return false
end hdhrGRID
--return {} --means we want to manually add a show, return true means we want to go back, return false means we cancelled out, return anything else, and this is the guide data for the channel they are requesting.
on tuner_overview(caller)
my logger(true, "tuner_overview(" & caller & ")", "INFO", "START Called")
my tuner_mismatch("tuner_overview(" & caller & ")", "")
set main_tuners_list to {}
repeat with i from 1 to length of HDHR_DEVICE_LIST
set tuner_status2_result to my tuner_status2("tuner_overview(" & caller & ")", device_id of item i of HDHR_DEVICE_LIST)
if hdhr_model of item i of HDHR_DEVICE_LIST is not missing value then
set end of main_tuners_list to (hdhr_model of item i of HDHR_DEVICE_LIST & " " & (device_id of item i of HDHR_DEVICE_LIST) & " " & tuneractive of tuner_status2_result & " of " & tunermax of tuner_status2_result & " in use") as text
else
set end of main_tuners_list to (device_id of item i of HDHR_DEVICE_LIST & " " & tuneractive of tuner_status2_result & " of " & tunermax of tuner_status2_result & " in use") as text
end if
end repeat
return main_tuners_list
end tuner_overview
on tuner_end(caller, hdhr_model)
set temp to {}
set lowest_number to 99999999
if length of Show_info is greater than 0 then
repeat with i from 1 to length of Show_info
if show_recording of item i of Show_info is true and hdhr_record of item i of Show_info is hdhr_model then
set end of temp to ((show_end of item i of Show_info) - (current date))
end if
end repeat
if length of temp is greater than 0 then
repeat with i2 from 1 to length of temp
if item i2 of temp is less than lowest_number and item i2 of temp is greater than 0 then
set lowest_number to item i2 of temp
end if
end repeat
end if
my logger(true, "tuner_end(" & caller & ")", "INFO", "Next Tuner Available in " & my ms2time("tuner_end(" & caller & ")", lowest_number, "s", 3))
return lowest_number
end if
return 0
end tuner_end
on tuner_inuse(caller, device_id)
set tuner_offset to my HDHRDeviceSearch("tuner_inuse(" & caller & ")", device_id)
try
with timeout of 8 seconds
set hdhr_discover_temp to my hdhr_api("tuner_inuse(" & caller & ")", statusURL of item tuner_offset of HDHR_DEVICE_LIST)
end timeout
repeat with i from 1 to length of hdhr_discover_temp
repeat 1 times
set local_ip_list to {}
set hdhr_discover_length to length of (item i of hdhr_discover_temp)
if hdhr_discover_length is 1 then
--my logger(true, "tuner_inuse(" & caller & ")", "WARN", "length: " & hdhr_discover_length & ", exited tuner_inuse") --, " & item i of hdhr_discover_temp)
exit repeat
end if
try
try
set TargetIP_check to ""
set TargetIP_check to TargetIP of item i of hdhr_discover_temp
on error errmsg
my logger(true, "tuner_inuse(" & caller & ")", "WARN", "TargetIP is not defined")
end try
if TargetIP_check is not "" then
if TargetIP of item i of hdhr_discover_temp is not equal to {} then
if (TargetIP_check as text) is not (Local_ip as text) then
set end of local_ip_list to TargetIP_check
else
set end of local_ip_list to "Self: (" & TargetIP_check & ")"
end if
try
set temp_line to "VctNumber: " & (VctNumber of item i of hdhr_discover_temp) & ", VctName: " & (VctName of item i of hdhr_discover_temp) & ", Frequency: " & (((Frequency of item i of hdhr_discover_temp as number) / 1000000) & " Mhz") & ", SignalStrengthPercent: " & SignalStrengthPercent of item i of hdhr_discover_temp & ", SignalQualityPercent: " & SignalQualityPercent of item i of hdhr_discover_temp & ", SymbolQualityPercent: " & SymbolQualityPercent of item i of hdhr_discover_temp & ", TargetIP: " & local_ip_list
my logger(true, "tuner_inuse(" & caller & ")", "INFO", temp_line)
on error errmsg
my logger(true, "tuner_inuse(" & caller & ")", "WARN", errmsg)
end try
end if
else
my logger(true, "tuner_inuse(" & caller & ")", "WARN", "TargetIP is empty")
end if
on error errmsg number errnum
my logger(true, "tuner_inuse_temp(" & caller & ")", "WARN", "errmsg: " & errnum & ", " & errmsg)
log errmsg
end try
end repeat
end repeat
on error errmsg
my logger(true, "tuner_inuse(" & caller & ")", "WARN", "Timeout, errmsg: " & errmsg)
return ""
end try
return local_ip_list
end tuner_inuse
on tuner_status2(caller, device_id)
set tuneractive to 0
set tuner_offset to my HDHRDeviceSearch("tuner_status2(" & caller & ")", device_id)
if tuner_offset is 0 then
my logger(true, "tuner_status2(" & caller & ")", "ERROR", "Tuner " & device_id & " is invalid")
return {tunermax:0, tuneractive:0}
end if
try
with timeout of 8 seconds
set hdhr_discover_temp to my hdhr_api("tuner_status2(" & caller & ")", statusURL of item tuner_offset of HDHR_DEVICE_LIST)
end timeout
on error errmsg
my logger(true, "tuner_status2(" & caller & ")", "WARN", "Timeout, errmsg: " & errmsg)
set hdhr_discover_temp to ""
return false
end try
if hdhr_discover_temp is not "" then
set tunermax to length of hdhr_discover_temp
set temp to ""
repeat with i from 1 to tunermax
try
set temp to SymbolQualityPercent of item i of hdhr_discover_temp
set tuneractive to tuneractive + 1
end try
end repeat
my logger(true, "tuner_status2(" & caller & ")", "DEBUG", device_id & " tunermax:" & tunermax & ", tuneractive:" & tuneractive & ", SymbolQualityPercent: " & temp)
return {tunermax:tunermax, tuneractive:tuneractive}
else
my logger(true, "tuner_status2(" & caller & ")", "WARN", "Did not get a result from " & statusURL of item tuner_offset of HDHR_DEVICE_LIST)
return {tunermax:0, tuneractive:0}
end if
end tuner_status2
on tuner_mismatch(caller, device_id)
if device_id is "" and length of HDHR_DEVICE_LIST is greater than 0 then
repeat with i2 from 1 to length of HDHR_DEVICE_LIST
my tuner_mismatch("tuner_mismatch(" & caller & ")", device_id of item i2 of HDHR_DEVICE_LIST)
end repeat
return
else
my logger(true, "tuner_mismatch(" & caller & ")", "INFO", "Called: " & device_id)
set tuner_offset to my HDHRDeviceSearch("tuner_mismatch(" & caller & ")", device_id)
set tuner_status2_result to my tuner_status2("tuner_mismatch(" & caller & ")", device_id)
set temp_shows_recording to 0
repeat with i from 1 to length of Show_info
if hdhr_record of item i of Show_info is device_id and show_recording of item i of Show_info is true then
set temp_shows_recording to temp_shows_recording + 1
end if
end repeat
if temp_shows_recording is greater than tuneractive of tuner_status2_result then
my logger(true, "tuner_mismatch(" & caller & ")", "WARN", "We are marked as having more shows recording then tuners in use")
else if temp_shows_recording is less than tuneractive of tuner_status2_result then
set tuner_inuse_return to my tuner_inuse("tuner_mismatch(" & caller & ")", device_id)
try
my logger(true, "tuner_mismatch(" & caller & ")", "WARN", "There are more tuners in use then we are using, list of other IPs: " & my stringlistflip("tuner_mismatch(" & caller & ")", tuner_inuse_return, ", ", "string"))
on error errmsg
my logger(true, "tuner_mismatch(" & caller & ")", "ERROR", "err, " & errmsg)
end try
else if temp_shows_recording is tuneractive of tuner_status2_result then
my logger(true, "tuner_mismatch(" & caller & ")", "TRACE", "We match")
else
my logger(true, "tuner_mismatch(" & caller & ")", "WARN", "TRACK USE CASE")
end if
my logger(true, "tuner_mismatch(" & caller & ")", "INFO", "Expected: " & temp_shows_recording & ", Actual: " & tuneractive of tuner_status2_result)
end if
end tuner_mismatch
on channel_record(caller, hdhr_tuner, channelcheck)
repeat with i from 1 to length of Show_info
if hdhr_tuner is hdhr_record of item i of Show_info and show_active of item i of Show_info is true then
if channelcheck is show_channel of item i of Show_info then
if show_recording of item i of Show_info is true then
my logger(true, "show_record(" & caller & ")", "TRACE", channelcheck & " marked as recording in channel list")
return true
end if
end if
end if
end repeat
end channel_record
on show_record(caller, hdhr_tuner, channelcheck, start_time, end_time)
--We need to only return the 1 result
my logger(true, "show_record(" & caller & ")", "DEBUG", (hdhr_tuner & " | " & channelcheck))
copy (current date) to cd
--try
repeat with i from 1 to length of Show_info
set show_record_id to show_id of item i of Show_info
-- if hdhr_tuner is hdhr_record of item i of Show_info and show_active of item i of Show_info is true and channelcheck is show_channel of item i of Show_info then
if hdhr_tuner is hdhr_record of item i of Show_info and channelcheck is show_channel of item i of Show_info then
my logger(true, "show_record(" & caller & ")", "TRACE", "show_start: " & class of (show_next of item i of Show_info) & ", start_time: " & class of (start_time))
if show_recording of item i of Show_info is true then
if cd is greater than or equal to start_time and cd is less than or equal to end_time then
my logger(true, "show_record" & i & "(" & caller & ")", "INFO", "Marked as recording: " & show_title of item i of Show_info)
my logger(true, "show_record" & i & "(" & caller & ")", "DEBUG", "REC show_record_id: " & show_record_id & ", offset:" & i)
return {show_stat:"record", the_show_id:show_record_id, status_icon:Record_icon of Icon_record}
end if
else
try
set show_next_low to ((show_next of item i of Show_info) - 2 * minutes)
set show_next_high to ((show_next of item i of Show_info) + 2 * minutes)
if start_time is greater than or equal to show_next_low then
--my logger(true, "show_record(" & caller & ")", "INFO", "1")
if start_time is less than or equal to show_next_high then
--if show_next of item i of Show_info is start_time then
my logger(true, "show_record" & i & "(" & caller & ")", "INFO", "Marked as upnext: " & show_title of item i of Show_info & ", channel " & channelcheck)
my logger(true, "show_record" & i & "(" & caller & ")", "DEBUG", "UPNEXT show_record_id: " & show_record_id & ", offset " & i)
if show_active of item i of Show_info is true then
return {show_stat:"upnext", the_show_id:show_record_id, status_icon:Up_icon of Icon_record}
else
return {show_stat:"deact", the_show_id:show_record_id, status_icon:Uncheck_icon of Icon_record}
end if
end if
else
--my logger(true, "show_record(" & caller & ")", "INFO", "2")
end if
on error errmsg
my logger(true, "show_record(" & caller & ")", "ERROR", "Oops, " & errmsg)
end try
end if
end if
end repeat
return {show_stat:missing value, the_show_id:missing value, status_icon:" "}
--on error errmsg
-- my logger(true, "channel_record(" & caller & ")", "ERROR", "errmsg: " & errmsg)
--end try
end show_record
on show_info_dump(caller, show_id_lookup, userdisplay)
-- (*show_title:Happy_Holidays_America, show_time:16, show_length:60, show_air_date:Sunday, show_transcode:missing value, show_temp_dir:alias Backups:, show_dir:alias Backups:, show_channel:5.1, show_active:true, show_id:221fbe1126389e6af35f405aa681cf19, #show_recording:false, show_last:date Sunday, December 13, 2020 at 4:04:54 PM, show_next:date Sunday, December 13, 2020 at 4:00:00 PM, show_end:date Sunday, December 13, 2020 at 5:00:00 PM, notify_upnext_time:missing value, #notify_recording_time:missing value, hdhr_record:XX105404BE,show_is_series:false*
if show_id_lookup is "" then
repeat with i2 from 1 to length of Show_info
my show_info_dump("show_info_dump(2-" & i2 & ")", show_id of item i2 of Show_info, userdisplay)
end repeat
return
end if
set i to my HDHRShowSearch(show_id_lookup)
--if show_id_lookup
if Local_env is not in Debugger_apps then
my logger(true, "show_info_dump(" & caller & ", " & show_id_lookup & ")", "TRACE", "show " & i & ", show_title: " & show_title of item i of Show_info & ", show_time: " & show_time of item i of Show_info & ", show_length: " & show_length of item i of Show_info & ", show_air_date: " & show_air_date of item i of Show_info & ", show_transcode: " & show_transcode of item i of Show_info & ", show_temp_dir: " & show_temp_dir of item i of Show_info & ", show_dir: " & show_dir of item i of Show_info & ", show_channel: " & show_channel of item i of Show_info & ", show_active: " & show_active of item i of Show_info & ", show_id: " & show_id of item i of Show_info & ", show_recording: " & show_recording of item i of Show_info & ", show_last: " & show_last of item i of Show_info & ", show_next: " & show_next of item i of Show_info & ", show_end: " & notify_upnext_time of item i of Show_info & ", notify_recording_time: " & notify_recording_time of item i of Show_info & ", hdhr_record: " & hdhr_record of item i of Show_info & ", show_is_series: " & show_is_series of item i of Show_info)
end if
end show_info_dump
on check_version(caller)
try
with timeout of 10 seconds
set version_response to (fetch JSON from Version_url with cleaning feed)
set Version_remote to hdhr_version of item 1 of versions of version_response
set Online_detected to true
my logger(true, "check_version(" & caller & ")", "INFO", "Current Version: " & Version_local & ", Remote Version: " & Version_remote)
if Version_remote is greater than Version_local then
my logger(true, "check_version(" & caller & ")", "INFO", "Changelog: " & changelog of item 1 of versions of version_response)
end if
end timeout
on error errmsg
my logger(true, "check_version(" & caller & ")", "ERROR", "Unable to check for new versions: " & errmsg)
set version_response to {versions:{{changelog:"Unable to check for new versions", hdhr_version:"20210101"}}}
set Version_remote to hdhr_version of item 1 of versions of version_response
tell application "JSON Helper" to quit
delay 3
my check_version("check_version(" & caller & ")")
end try
end check_version
on check_version_dialog(caller)
--This handler compares the current version, and the current remote version, and sets a string to show the status
if Version_remote is greater than Version_local then
set temp to Version_local & " " & Update_icon of Icon_record & " " & Version_remote
end if
if Version_remote is less than Version_local then
set temp to "Beta " & Version_local
end if
if Version_remote is Version_local then
set temp to Version_local
end if
return temp
end check_version_dialog
on build_channel_list(caller, hdhr_device)
set channel_list_temp to {}
try
if hdhr_device is "" then
repeat with i from 1 to length of HDHR_DEVICE_LIST
my logger(true, "build_channel_list99(" & caller & ")", "INFO", device_id of item i of HDHR_DEVICE_LIST)
my build_channel_list("build_channel_list-" & i & "(" & caller & ")", device_id of item i of HDHR_DEVICE_LIST)
end repeat
else
set tuner_offset to my HDHRDeviceSearch("build_channel_list(" & caller & ")", hdhr_device)
set temp to hdhr_lineup of item tuner_offset of HDHR_DEVICE_LIST
--set channel_list to {}
repeat with i from 1 to length of temp
--(*GuideNumber:49.2, URL:http://10.0.1.101:5004/auto/v49.2, GuideName:KMQV-LD, VideoCodec:MPEG2, AudioCodec:AC3*)
try
if HD of item i of temp is 1 then
set end of channel_list_temp to GuideNumber of item i of temp & " " & GuideName of item i of temp & " [HD]"
end if
on error
set end of channel_list_temp to GuideNumber of item i of temp & " " & GuideName of item i of temp
end try
try --Show which channels are recording on channel list.
--my logger(true, "build_channel_list0(" & caller & ")", "INFO", "IS_RECORDING1")
if my channel_record("build_channel_list(" & caller & ")", hdhr_device, GuideNumber of item i of temp) is true then
my logger(true, "build_channel_list2(" & caller & ")", "INFO", GuideNumber of item i of temp & " marked on channel list as recording")
set last item of channel_list_temp to last item of channel_list_temp & " " & Record_icon of Icon_record
end if
end try
try
if VideoCodec of item i of temp is not "MPEG2" then
my logger(true, "build_channel_list_VIDEO_CODEC(" & caller & ")", "NEAT", (last item of channel_list_temp as text) & " is using " & VideoCodec of item i of temp)
set last item of channel_list_temp to my encode_strikethrough("build_channel_list_VIDEO_CODEC(" & caller & ")", last item of channel_list_temp, 822)
end if
end try
try
if AudioCodec of item i of temp is not "AC3" then
my logger(true, "build_channel_list_AUDIO_CODEC(" & caller & ")", "NEAT", (last item of channel_list_temp as text) & " is using " & AudioCodec of item i of temp)
set last item of channel_list_temp to my encode_strikethrough("build_channel_list_AUDIO_CODEC(" & caller & ")", last item of channel_list_temp, 822)
end if
end try
end repeat
set channel_mapping of item tuner_offset of HDHR_DEVICE_LIST to channel_list_temp
my logger(true, "build_channel_list(" & caller & ")", "INFO", "Updated channel list for " & hdhr_device & ", " & length of channel_list_temp & " found.")
end if
on error errmsg
my logger(true, "build_channel_list(" & caller & ")", "ERROR", "Unable to build channel list " & errmsg)
end try
end build_channel_list
on channel2name(caller, the_channel, hdhr_device)
my logger(true, "channel2name(" & caller & ")", "DEBUG", the_channel & " on " & hdhr_device)
set tuner_offset to my HDHRDeviceSearch("channel2name0(" & caller & ")", hdhr_device)
if tuner_offset is greater than 0 then
set channel2name_temp to hdhr_lineup of item tuner_offset of HDHR_DEVICE_LIST
repeat with i from 1 to length of channel2name_temp
if GuideNumber of item i of channel2name_temp is the_channel then
my logger(true, "channel2name(" & caller & ")", "DEBUG", "returned \"" & GuideName of item i of channel2name_temp & "\" station for channel " & the_channel & " on " & hdhr_device)
return GuideName of item i of channel2name_temp
end if
end repeat
my logger(true, "channel2name(" & caller & ")", "ERROR", "We were not able to pull lineup data for channel " & the_channel & " for device " & hdhr_device)
--return false
else
my logger(true, "channel2name(" & caller & ")", "WARN", "tuner_offset is 0")
return false
end if
end channel2name
on nextday(caller, the_show_id)
-- my logger(true, "next_day(" & caller & ")", "INFO", "1")
copy (current date) to cd_object
set nextup to {}
set show_offset to my HDHRShowSearch(the_show_id)
repeat with i from -1 to 7
if the_show_id is show_id of item show_offset of Show_info then
if ((weekday of (cd_object + i * days)) as text) is in (show_air_date of item show_offset of Show_info) then
if cd_object is less than (my time_set("nextday(" & caller & ")", (cd_object + i * days), (show_time of item show_offset of Show_info))) + ((show_length of item show_offset of Show_info) * minutes) then
my logger(true, "nextday(" & caller & ")", "DEBUG", "1nextup: " & nextup)
my logger(true, "nextday(" & caller & ")", "DEBUG", "cd_object: " & cd_object)
my logger(true, "nextday(" & caller & ")", "DEBUG", "i: " & i)
set nextup to my time_set("nextday(" & caller & ")", (cd_object + i * days), show_time of item show_offset of Show_info)
exit repeat
end if
end if
end if
end repeat
try
set record_check_pre to ((nextup) - 1 * weeks)
set record_check_post to (record_check_pre) + ((show_length of item show_offset of Show_info) * minutes)
if (cd_object) is greater than record_check_pre and (cd_object) is less than record_check_post then
my logger(true, "nextday(" & caller & ")", "WARN", "We are between record_check_pre and record_check_post")
set show_next of item show_offset of Show_info to record_check_pre
end if
on error errmsg
my logger(true, "nextday(" & caller & ")", "WARN", "0errmsg: " & errmsg)
end try
try
if nextup is missing value then
my logger(true, "nextday(" & caller & ")", "WARN", "nextup0 is missing value")
end if
on error errmsg
my logger(true, "nextday(" & caller & ")", "WARN", "errmsg1: " & errmsg)
end try
if show_end of item show_offset of Show_info is not nextup + ((show_length of item show_offset of Show_info) * minutes) then
set show_end of item show_offset of Show_info to nextup + ((show_length of item show_offset of Show_info) * minutes)
my logger(true, "nextday(" & caller & ")", "INFO", "Show end of \"" & show_title of item show_offset of Show_info & "\" set to: " & nextup + ((show_length of item show_offset of Show_info) * minutes))
my logger(true, "nextday(" & caller & ")", "DEBUG", "WORK Show end class: " & class of (show_end of item show_offset of Show_info))
end if
return nextup
end nextday
on validate_show_info(caller, show_to_check, should_edit)
my logger(true, "validate_show_info(" & caller & ")", "DEBUG", "show_to_check: " & show_to_check)
set show_active_changed to false
if show_to_check is "" then
repeat with i2 from 1 to length of Show_info
my validate_show_info("validate_show_info" & i2 & "(" & caller & ")", show_id of item i2 of Show_info, should_edit)
end repeat
else
set i to my HDHRShowSearch(show_to_check)
my logger(true, "validate_show_info(" & caller & ", " & show_to_check & ", " & should_edit & ")", "TRACE", "Running validate on " & show_title of item i of Show_info & ", should_edit: " & should_edit)
if should_edit is true then
if show_active of item i of Show_info is true then