-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.php
1244 lines (712 loc) · 34.1 KB
/
func.php
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
<?php
function list_files_into_dir($dir)
{
// 19.07.10
//define the path as relative
$path = $dir;
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
// echo "Directory Listing of $path<br/>";
//running the while loop
while ($file = readdir($dir_handle))
{
if($file == '.' OR $file == '..') continue;
// echo "<a href='$file'>$file</a><br/>";
$file_list_array[] = $file;
}
//closing the directory
closedir($dir_handle);
return $file_list_array;
}
if (!function_exists(robin_file_read)):
function robin_file_read($filename_and_path)
{
$file=@FOpen($filename_and_path, 'rb');
@flock($file,1);
$data = @fread($file, filesize($filename_and_path));
@flock($file,3);
@fclose($file);
return $data;
}
endif;
function extract_dvb_data_from_config($data,$dir,$filename)
{
// 20.07.10
global $config;
$line = explode ("\n", $data);
for($i=0;$i<(count($line));$i++)
{
/*
...tv...
"stype": 1,
...radio...
"stype": 2,
...HD ???...
"stype": 25,
...YES...
"scrambled": 1,
...NO...
"scrambled": 0,
...if "channelname" then 1, if not then empty...
"mapped": 1,
"provider": "Skylink",
"servicename": "TV JOJ",
"channelname": "TV JOJ",
*/
if (preg_match('/"provider": "([a-z0-9@#!\-\. ]+)"/i',$line[$i],$matches)):
$output['provider'] = strtolower($matches[1]);
if($config['debug'] >= 2) echo ' provider: ' . $output['provider'] . '<br/>';
continue;
endif;
if (preg_match('/"servicename": "(.+)"/i',$line[$i],$matches)):
$output['servicename'] = $matches[1];
if($config['debug'] >= 2) echo ' servicename: ' . $output['servicename'] . '<br/>';
$output['all'] .= '---INSERT---' . "\n";
continue;
endif;
if (preg_match('/"scrambled": ([0-9]),/i',$line[$i],$matches)):
$output['scrambled'] = $matches[1];
if($config['debug'] >= 2) echo ' scrambled: ' . $output['scrambled'] . '<br/>';
continue;
endif;
if (preg_match('/"stype": ([0-9]+),/i',$line[$i],$matches)):
$output['stype'] = $matches[1];
if($config['debug'] >= 2) echo ' stype: ' . $output['stype'] . '<br/>';
continue;
endif;
if (preg_match('/"mapped": ([0-9]),/i',$line[$i],$matches)):
$output['mapped'] = $matches[1];
if($config['debug'] >= 2) echo ' mapped: ' . $output['mapped'] . '<br/>';
continue;
endif;
if (preg_match('/"disabled": ([0-9]),/i',$line[$i],$matches)):
$output['disabled'] = $matches[1];
if($config['debug'] >= 2) echo ' disabled: ' . $output['disabled'] . '<br/>';
continue;
endif;
// del old channelname...
if (preg_match('/"channelname": "(.+)"/i',$line[$i],$matches)):
continue;
endif;
$output['all'] .= $line[$i] . "\n";
}
$output['dir'] = $dir;
$output['filename'] = $filename;
return $output;
}
function extract_channels_txt()
{
// 19.07.10
global $config;
$counter = 0;
$data = robin_file_read($config['file_channels_list']);
$line = explode ("\n", $data);
for($i=0;$i<(count($line));$i++)
{
// skipp comments...
if(preg_match('#^//#i',$line[$i])) continue;
$tmp_ex = explode('#',$line[$i]);
// check if exist channel name...
// if(!strlen($tmp_ex[1]) > 0) continue;
if(!isset($tmp_ex[1])) continue;
// ignore comment
if (preg_match('#^//#i',$line[$i])) continue;
// ID...
if($tmp_ex[0] > 0):
$channel_id = $tmp_ex[0];
elseif($tmp_ex[0] == '*'):
$channel_id = 0;
else:
$channel_id = NULL;
endif;
// Name...
$tmp_ex_name = explode('|',$tmp_ex[1]);
$channel_name = $tmp_ex_name[0];
// if exist alias...make alias list...
if(count($tmp_ex_name) > 1):
for($ii=0;$ii<(count($tmp_ex_name));$ii++)
{
$channel_name_alias[$tmp_ex_name[$ii]] = $tmp_ex_name[0];
}
else:
$channel_name_alias[$tmp_ex_name[0]] = $tmp_ex_name[0];
endif;
// scrambled...
if(isset($tmp_ex[2])):
$channel_scrambled = 1;
if(preg_match("#(([0-9]{5})_([A-Z]{1}))#i",$tmp_ex[2],$matches)):
// freq.
// old -> 11797_H -> TS202011797000_H
// 11895_V -> ard11895000_V_
$channel_scrambled_type = 1;
$channel_scrambled_string = $matches[2] . '000' . '_' . strtoupper($matches[3]);
else:
// provider
$channel_scrambled_type = 2;
$channel_scrambled_string = strtolower($tmp_ex[2]);
endif;
else:
$channel_scrambled = 0;
$channel_scrambled_type = NULL;
$channel_scrambled_string = NULL;
endif;
// generate list
if(isset($channel_name)):
$channels_sort_list[$counter]['id'] = $channel_id;
$channels_sort_list[$counter]['name'] = $channel_name;
$channels_sort_list[$counter]['scrambled'] = $channel_scrambled;
$channels_sort_list[$counter]['scrambled_type'] = $channel_scrambled_type;
$channels_sort_list[$counter]['scrambled_string'] = $channel_scrambled_string;
$counter++;
endif;
}
return array($channels_sort_list,$channel_name_alias);
}
function scrambled_yes_or_no($dvbtransports,$channels_sort_list)
{
// 20.07.10
$line_count = count($channels_sort_list);
for($i=0;$i<$line_count;$i++)
{
if($channels_sort_list[$i]['name'] == $dvbtransports['channelname']):
// freq.
if($channels_sort_list[$i]['scrambled'] === 1 AND $channels_sort_list[$i]['scrambled_type'] === 1):
if (preg_match('/' . $channels_sort_list[$i]['scrambled_string'] . '/i',$dvbtransports['filename'],$matches)):
return 1;
endif;
endif;
// provider
if($channels_sort_list[$i]['scrambled'] === 1 AND $channels_sort_list[$i]['scrambled_type'] === 2):
if ($channels_sort_list[$i]['scrambled_string'] == $dvbtransports['provider']):
return 1;
endif;
endif;
endif;
}
return 0;
}
function create_dvb_data($dvbtransports,$channel_enable)
{
// 20.07.10
global $config;
$add_text = NULL;
$add_text = ' "provider": "' . $dvbtransports['provider'] . '",
"servicename": "' . $dvbtransports['servicename'] . '",
"scrambled": ' . $dvbtransports['scrambled'] . ',
"stype": ' . $dvbtransports['stype'] . ',
';
if($channel_enable === 1):
$add_text .= ' "channelname": "' . $dvbtransports['channelname'] . '",
"mapped": 1,
"disabled": 0,';
else:
$add_text .= ' "disabled": 1,';
endif;
$output = preg_replace('#---INSERT---#i',$add_text, $dvbtransports['all']);
robin_file_write($config['path_tvheadend_config_dir_output'] . $config['path_tvheadend_dvbtransports'] . $dvbtransports['dir'] . '/' . $dvbtransports['filename'],$output);
}
function sort_channels($list_all_enabled_channel,$channels_sort_list)
{
// 20.07.10
global $config;
global $config_tv_logo;
/*
>0 = ID
0 = next empty
null = next from xyz
*/
$counter = 0;
$line_count = count($channels_sort_list);
for($i=0;$i<$line_count;$i++)
{
// if is defined channel number...
if($channels_sort_list[$i]['id'] > 0 && $list_all_enabled_channel[$channels_sort_list[$i]['name']] === 1):
$final_channels_sorted_list[$counter]['channel_number'] = $channels_sort_list[$i]['id'];
$final_channels_sorted_list[$counter]['name'] = $channels_sort_list[$i]['name'];
$counter++;
unset($list_all_enabled_channel[$channels_sort_list[$i]['name']]);
endif;
}
$line_count = count($channels_sort_list);
for($i=0;$i<$line_count;$i++)
{
// if is channel number defines as 0...use next empty...
if($channels_sort_list[$i]['id'] === 0 && $list_all_enabled_channel[$channels_sort_list[$i]['name']] === 1):
$next_empty_id = return_next_empty_id($final_channels_sorted_list);
$final_channels_sorted_list[$counter]['channel_number'] = $next_empty_id;
$final_channels_sorted_list[$counter]['name'] = $channels_sort_list[$i]['name'];
$counter++;
unset($list_all_enabled_channel[$channels_sort_list[$i]['name']]);
endif;
}
$actual_max_channel_number = 0;
// Find Max Channel Number...
$line_count = count($final_channels_sorted_list);
for($i=0;$i<$line_count;$i++)
{
if(isset($final_channels_sorted_list[$i]['channel_number'])):
if($final_channels_sorted_list[$i]['channel_number'] > $actual_max_channel_number) $actual_max_channel_number = $final_channels_sorted_list[$i]['channel_number'];
endif;
}
$other_channel_number_begin_from = ceiling(($actual_max_channel_number+$config['add_to_rounding']), 100);
$line_count = count($channels_sort_list);
for($i=0;$i<$line_count;$i++)
{
// if is channel number defines as NULL...use next empty bigger then...
if(!isset($channels_sort_list[$i]['id']) && $list_all_enabled_channel[$channels_sort_list[$i]['name']] === 1):
$next_empty_id = return_next_empty_id($final_channels_sorted_list,$other_channel_number_begin_from);
$final_channels_sorted_list[$counter]['channel_number'] = $next_empty_id;
$final_channels_sorted_list[$counter]['name'] = $channels_sort_list[$i]['name'];
$counter++;
unset($list_all_enabled_channel[$channels_sort_list[$i]['name']]);
endif;
}
if($config['debug'] >= 3):
echo '<pre>';
echo '<b>$list_all_enabled_channel (' . count($list_all_enabled_channel) . ')</b>' . "\n";
print_r($list_all_enabled_channel);
echo '</pre>';
endif;
ksort($list_all_enabled_channel,SORT_STRING);
if($config['debug'] >= 3):
echo '<pre>';
echo '<b>SORT -> $list_all_enabled_channel (' . count($list_all_enabled_channel) . ')</b>' . "\n";
print_r($list_all_enabled_channel);
echo '</pre>';
endif;
// all other channel...
foreach ($list_all_enabled_channel as $k => $v)
{
$next_empty_id = return_next_empty_id($final_channels_sorted_list,$other_channel_number_begin_from);
$final_channels_sorted_list[$counter]['channel_number'] = $next_empty_id;
$final_channels_sorted_list[$counter]['name'] = $k;
$counter++;
unset($list_all_enabled_channel[$k]);
}
if($config['debug'] >= 3):
echo '<pre>';
echo '<b>$final_channels_sorted_list (' . count($final_channels_sorted_list) . ')</b>' . "\n";
print_r($final_channels_sorted_list);
echo '</pre>';
endif;
// remove old ch. list
$temp['tvheadend_channels_dir'] = $config['path_tvheadend_config_dir'] . $config['path_tvheadend_channels'];
$dir_list_array = list_files_into_dir($temp['tvheadend_channels_dir']);
$line_count = count($dir_list_array);
for($i=0;$i<$line_count;$i++)
{
@unlink($config['path_tvheadend_config_dir_output'] . $config['path_tvheadend_channels'] . $dir_list_array[$i]);
}
$line_count = count($final_channels_sorted_list);
for($i=0;$i<$line_count;$i++)
{
// TV Logo
if($config['tv_logo'] === 1):
if(isset($config_tv_logo[$final_channels_sorted_list[$i]['name']])):
$temp_tv_logo = "\n" . ' "icon": "' . $config['path_tv_logo_-_tvheadend'] . $config_tv_logo[$final_channels_sorted_list[$i]['name']] . '",';
else:
$temp_tv_logo = NULL;
endif;
endif;
$output = '{
"name": "' . $final_channels_sorted_list[$i]['name'] . '",' . $temp_tv_logo . '
"tags": [
],
"dvr_extra_time_pre": 0,
"dvr_extra_time_post": 0,
"channel_number": ' . (int) $final_channels_sorted_list[$i]['channel_number'] . '
}
';
// write new channels...
robin_file_write($config['path_tvheadend_config_dir_output'] . $config['path_tvheadend_channels'] . ($i+1),$output);
}
return $final_channels_sorted_list;
}
function xbmc_sqlite($final_channels_sorted_list)
{
// 20.07.10
// DB Version 4
global $config;
global $config_tv_logo;
$file = $config['path_xbmc_sqlite'];
@unlink($file);
$db = new SQLite3($file);
$db->exec('CREATE TABLE ChannelGroup (idGroup integer primary key, groupName text, sortOrder integer)');
$db->exec('CREATE TABLE ChannelLinkageMap (idMapping integer primary key, idPortalChannel integer, idLinkedChannel integer)');
$db->exec('CREATE TABLE ChannelSettings ( idChannel integer primary key, Deinterlace integer,ViewMode integer,ZoomAmount float, PixelRatio float, AudioStream integer, SubtitleStream integer,SubtitleDelay float, SubtitlesOn bool, Brightness float, Contrast float, Gamma float,VolumeAmplification float, AudioDelay float, OutputToAllSpeakers bool, Crop bool, CropLeft integer,CropRight integer, CropTop integer, CropBottom integer, Sharpness float, NoiseReduction float)');
$db->exec('CREATE TABLE Channels (idChannel integer primary key, Name text, Number integer, ClientName text, ClientNumber integer, idClient integer, UniqueId integer, IconPath text, GroupID integer, countWatched integer, timeWatched integer, lastTimeWatched datetime, encryption integer, radio bool, hide bool, grabEpg bool, EpgGrabber text, lastGrabTime datetime, Virtual bool, strInputFormat text, strStreamURL text)');
$db->exec('CREATE TABLE Clients (idClient integer primary key, Name text, GUID text)');
$db->exec('CREATE TABLE GuideData (idDatabaseBroadcast integer primary key, idUniqueBroadcast integer, idChannel integer, StartTime datetime, EndTime datetime, strTitle text, strPlotOutline text, strPlot text, GenreType integer, GenreSubType integer, firstAired datetime, parentalRating integer, starRating integer, notify integer, seriesNum text, episodeNum text, episodePart text, episodeName text)');
$db->exec('CREATE TABLE LastChannel (idChannel integer primary key, Number integer, Name text)');
$db->exec('CREATE TABLE LastEPGScan (idScan integer primary key, ScanTime datetime)');
$db->exec('CREATE TABLE RadioChannelGroup (idGroup integer primary key, groupName text, sortOrder integer)');
$db->exec('CREATE TABLE version (idVersion integer, iCompressCount integer)');
$db->exec('CREATE UNIQUE INDEX ix_ChannelSettings ON ChannelSettings (idChannel)');
$db->exec('CREATE UNIQUE INDEX ix_GuideData on GuideData(idChannel, StartTime desc)');
$db->exec('INSERT INTO version VALUES(4,0)');
$db->exec('INSERT INTO Clients VALUES(1,\'Tvheadend HTSP Client\',\'pvr.hts\')');
$line_count = count($final_channels_sorted_list);
for($i=0;$i<$line_count;$i++)
{
// TV Logo
if($config['tv_logo'] === 1):
if(isset($config_tv_logo[$final_channels_sorted_list[$i]['name']])):
$temp_tv_logo = '\'' . $config['path_tv_logo_-_xbmc'] . $config_tv_logo[$final_channels_sorted_list[$i]['name']] . '\'';
else:
$temp_tv_logo = '\'\'';
endif;
else:
$temp_tv_logo = '\'\'';
endif;
$temp_channel_number = ($config['xbmc_channel_id_one_by_one'] === 1) ? ($i+1) : $final_channels_sorted_list[$i]['channel_number'];
$channel_name_for_sql = preg_replace('/\'/','\'\'',$final_channels_sorted_list[$i]['name']);
$db->exec('INSERT INTO Channels VALUES(' . ($i+1) . ',\'' . $channel_name_for_sql . '\',' . (int) $temp_channel_number . ',\'' . $channel_name_for_sql . '\',' . ($i+1) . ',1,' . ($i+1) . ',' . $temp_tv_logo . ',0,NULL,NULL,NULL,0,0,0,1,\'client\',NULL,0,\'\',\'\')');
if(isset($config['xbmc_lastchannel']) && $final_channels_sorted_list[$i]['name'] == $config['xbmc_lastchannel']):
$db->exec('INSERT INTO LastChannel VALUES(1,' . (int) $temp_channel_number . ',\'' . $channel_name_for_sql . '\')');
endif;
}
}
function xbmc_sqlite_v6($final_channels_sorted_list)
{
// 5.1.11
// DB Version 6
global $config;
global $config_tv_logo;
$file = $config['path_xbmc_sqlite'];
@unlink($file);
$db = new SQLite3($file);
$db->exec('CREATE TABLE ChannelGroup (GroupId integer primary key,IsRadio bool, Name text,SortOrder integer)');
$db->exec('CREATE TABLE ChannelSettings (ChannelId integer primary key, InterlaceMethod integer, ViewMode integer, CustomZoomAmount float, PixelRatio float, AudioStream integer, SubtitleStream integer,SubtitleDelay float, SubtitlesOn bool, Brightness float, Contrast float, Gamma float,VolumeAmplification float, AudioDelay float, OutputToAllSpeakers bool, Crop bool, CropLeft integer, CropRight integer, CropTop integer, CropBottom integer, Sharpness float, NoiseReduction float)');
$db->exec('CREATE TABLE Channels (ChannelId integer primary key, UniqueId integer, ChannelNumber integer, GroupId integer, IsRadio bool, IsHidden bool, IconPath text, ChannelName text, IsVirtual bool, EPGEnabled bool, EPGScraper text, ClientId integer, ClientChannelNumber integer, InputFormat text, StreamURL text, EncryptionSystem integer)');
$db->exec('CREATE TABLE Clients (ClientDbId integer primary key, Name text, ClientId text)');
$db->exec('CREATE TABLE EpgData (BroadcastId integer primary key, BroadcastUid integer, ChannelId integer, Title text, PlotOutline text, Plot text, StartTime datetime, EndTime datetime, GenreType integer, GenreSubType integer, FirstAired datetime, ParentalRating integer, StarRating integer, Notify bool, SeriesId text, EpisodeId text, EpisodePart text, EpisodeName text)');
$db->exec('CREATE TABLE LastChannel (ChannelId integer primary key, Number integer, Name text)');
$db->exec('CREATE TABLE LastEPGScan (idScan integer primary key, ScanTime datetime)');
$db->exec('CREATE TABLE version (idVersion integer, iCompressCount integer)');
$db->exec('CREATE INDEX ix_ChannelClientId on Channels(ClientId)');
$db->exec('CREATE INDEX ix_ChannelGroupIsRadio on ChannelGroup(IsRadio)');
$db->exec('CREATE INDEX ix_ChannelGroupName on ChannelGroup(Name)');
$db->exec('CREATE INDEX ix_ChannelIsHidden on Channels(IsHidden)');
$db->exec('CREATE INDEX ix_ChannelIsRadio on Channels(IsRadio)');
$db->exec('CREATE INDEX ix_ChannelNumber on Channels(ChannelNumber)');
$db->exec('CREATE INDEX ix_ClientId on Clients(ClientId)');
$db->exec('CREATE UNIQUE INDEX ix_EpgBroadcastUid on EpgData(BroadcastUid)');
$db->exec('CREATE INDEX ix_EpgChannelId on EpgData(ChannelId)');
$db->exec('CREATE INDEX ix_EpgEndTime on EpgData(EndTime)');
$db->exec('CREATE INDEX ix_EpgStartTime on EpgData(StartTime)');
$db->exec('CREATE UNIQUE INDEX ix_EpgUniqueStartTime on EpgData(ChannelId, StartTime desc)');
$db->exec('CREATE UNIQUE INDEX ix_UniqueChannelNumber on Channels(ChannelNumber, IsRadio)');
$db->exec('INSERT INTO version VALUES(6,0)');
$db->exec('INSERT INTO Clients VALUES(1,\'Tvheadend HTSP Client\',\'pvr.hts\')');
$lastepgscan = date('Y-m-d H:i:s',mktime()-(60*60*48));
$db->exec('INSERT INTO LastEPGScan VALUES(1,\'' . $lastepgscan . '\')');
$line_count = count($final_channels_sorted_list);
for($i=0;$i<$line_count;$i++)
{
// TV Logo
if($config['tv_logo'] === 1):
if(isset($config_tv_logo[$final_channels_sorted_list[$i]['name']])):
$temp_tv_logo = '\'' . $config['path_tv_logo_-_xbmc'] . $config_tv_logo[$final_channels_sorted_list[$i]['name']] . '\'';
else:
$temp_tv_logo = '\'\'';
endif;
else:
$temp_tv_logo = '\'\'';
endif;
$temp_channel_number = ($config['xbmc_channel_id_one_by_one'] === 1) ? ($i+1) : $final_channels_sorted_list[$i]['channel_number'];
$channel_name_for_sql = preg_replace('/\'/','\'\'',$final_channels_sorted_list[$i]['name']);
$db->exec('INSERT INTO Channels VALUES(
' . ($i+1) . ',
' . ($i+1) . ',
' . (int) $temp_channel_number . ',
0,
0,
0,
' . $temp_tv_logo . ',
\'' . $channel_name_for_sql . '\',
0,
1,
\'client\',
1,
' . ($i+1) . ',
\'\',
\'\',
0)');
if(isset($config['xbmc_lastchannel']) && $final_channels_sorted_list[$i]['name'] == $config['xbmc_lastchannel']):
$db->exec('INSERT INTO LastChannel VALUES(1,' . (int) $temp_channel_number . ',\'' . $channel_name_for_sql . '\')');
endif;
}
}
function xbmc_sqlite_v7($final_channels_sorted_list)
{
// 9.1.11
// DB Version 7
global $config;
global $config_tv_logo;
$file = $config['path_xbmc_sqlite'];
@unlink($file);
$db = new SQLite3($file);
$db->exec('CREATE TABLE channelgroups (idGroup integer primary key,bIsRadio bool, sName text,iSortOrder integer)');
$db->exec('CREATE TABLE channels (idChannel integer primary key, iUniqueId integer, iChannelNumber integer, idGroup integer, bIsRadio bool, bIsHidden bool, sIconPath text, sChannelName text, bIsVirtual bool, bEPGEnabled bool, sEPGScraper text, iLastWatched integer,iClientId integer, iClientChannelNumber integer, sInputFormat text, sStreamURL text, iEncryptionSystem integer)');
$db->exec('CREATE TABLE channelsettings (idChannel integer primary key, iInterlaceMethod integer, iViewMode integer, fCustomZoomAmount float, fPixelRatio float, iAudioStream integer, iSubtitleStream integer,fSubtitleDelay float, bSubtitles bool, fBrightness float, fContrast float, fGamma float,fVolumeAmplification float, fAudioDelay float, bOutputToAllSpeakers bool, bCrop bool, iCropLeft integer, iCropRight integer, iCropTop integer, iCropBottom integer, fSharpness float, fNoiseReduction float)');
$db->exec('CREATE TABLE clients (idClient integer primary key, sName text, sUid text)');
$db->exec('CREATE TABLE epg (idBroadcast integer primary key, iBroadcastUid integer, idChannel integer, sTitle text, sPlotOutline text, sPlot text, iStartTime integer, iEndTime integer, iGenreType integer, iGenreSubType integer, iFirstAired integer, iParentalRating integer, iStarRating integer, bNotify bool, sSeriesId text, sEpisodeId text, sEpisodePart text, sEpisodeName text)');
$db->exec('CREATE TABLE lastepgscan (idEpg integer primary key, iLastScan integer)');
$db->exec('CREATE TABLE version (idVersion integer, iCompressCount integer)');
$db->exec('CREATE VIEW vw_last_watched AS SELECT idChannel, iChannelNumber, sChannelName FROM Channels ORDER BY iLastWatched DESC');
$db->exec('CREATE INDEX idx_channelgroups_bIsRadio on channelgroups(bIsRadio)');
$db->exec('CREATE INDEX idx_channelgroups_sName on channelgroups(sName)');
$db->exec('CREATE INDEX idx_channels_bIsHidden on channels(bIsHidden)');
$db->exec('CREATE INDEX idx_channels_bIsRadio on channels(bIsRadio)');
$db->exec('CREATE INDEX idx_channels_iChannelNumber on channels(iChannelNumber)');
$db->exec('CREATE UNIQUE INDEX idx_channels_iChannelNumber_bIsRadio on channels(iChannelNumber, bIsRadio)');
$db->exec('CREATE INDEX idx_channels_iClientId on channels(iClientId)');
$db->exec('CREATE INDEX idx_channels_iLastWatched on channels(iLastWatched)');
$db->exec('CREATE INDEX idx_clients_sUid on clients(sUid)');
$db->exec('CREATE UNIQUE INDEX idx_epg_iBroadcastUid on epg(iBroadcastUid)');
$db->exec('CREATE INDEX idx_epg_iEndTime on epg(iEndTime)');
$db->exec('CREATE INDEX idx_epg_iStartTime on epg(iStartTime)');
$db->exec('CREATE INDEX idx_epg_idChannel on epg(idChannel)');
$db->exec('CREATE UNIQUE INDEX idx_epg_idChannel_iStartTime on epg(idChannel, iStartTime desc)');
$db->exec('INSERT INTO version VALUES(7,0)');
$db->exec('INSERT INTO clients VALUES(1,\'Tvheadend HTSP Client\',\'pvr.hts\')');
$lastepgscan = mktime()-(60*60*48);
$db->exec('INSERT INTO lastepgscan VALUES(0,\'' . $lastepgscan . '\')');
$lastwatched = mktime()-(60*60*48);
$line_count = count($final_channels_sorted_list);
for($i=0;$i<$line_count;$i++)
{
// TV Logo
if($config['tv_logo'] === 1):
if(isset($config_tv_logo[$final_channels_sorted_list[$i]['name']])):
$temp_tv_logo = '\'' . $config['path_tv_logo_-_xbmc'] . $config_tv_logo[$final_channels_sorted_list[$i]['name']] . '\'';
else:
$temp_tv_logo = '\'\'';
endif;
else:
$temp_tv_logo = '\'\'';
endif;
$temp_channel_number = ($config['xbmc_channel_id_one_by_one'] === 1) ? ($i+1) : $final_channels_sorted_list[$i]['channel_number'];
$channel_name_for_sql = preg_replace('/\'/','\'\'',$final_channels_sorted_list[$i]['name']);
$db->exec('INSERT INTO channels VALUES(
' . ($i+1) . ',
' . ($i+1) . ',
' . (int) $temp_channel_number . ',
0,
0,
0,
' . $temp_tv_logo . ',
\'' . $channel_name_for_sql . '\',
0,
1,
\'client\',
NULL,
1,
' . ($i+1) . ',
\'\',
\'\',
0)');
if(isset($config['xbmc_lastchannel']) && $final_channels_sorted_list[$i]['name'] == $config['xbmc_lastchannel']):
$db->exec('UPDATE channels SET iLastWatched=\'' . (int) $lastwatched . '\' WHERE sChannelName=\'' . $channel_name_for_sql . '\'');
endif;
}
}
function xbmc_sqlite_v7_1($final_channels_sorted_list)
{
// 21.1.11
// DB Version 7.1
global $config;
global $config_tv_logo;
$file = $config['path_xbmc_sqlite'];
@unlink($file);
$db = new SQLite3($file);
$db->exec('CREATE TABLE channelgroups (idGroup integer primary key,bIsRadio bool, sName text,iSortOrder integer)');
$db->exec('CREATE TABLE channels (idChannel integer primary key, iUniqueId integer, iChannelNumber integer, idGroup integer, bIsRadio bool, bIsHidden bool, sIconPath text, sChannelName text, bIsVirtual bool, bEPGEnabled bool, sEPGScraper text, iLastWatched integer,iClientId integer, iClientChannelNumber integer, sInputFormat text, sStreamURL text, iEncryptionSystem integer)');
$db->exec('CREATE TABLE channelsettings (idChannel integer primary key, iInterlaceMethod integer, iViewMode integer, fCustomZoomAmount float, fPixelRatio float, iAudioStream integer, iSubtitleStream integer,fSubtitleDelay float, bSubtitles bool, fBrightness float, fContrast float, fGamma float,fVolumeAmplification float, fAudioDelay float, bOutputToAllSpeakers bool, bCrop bool, iCropLeft integer, iCropRight integer, iCropTop integer, iCropBottom integer, fSharpness float, fNoiseReduction float)');
$db->exec('CREATE TABLE clients (idClient integer primary key, sName text, sUid text)');
$db->exec('CREATE TABLE epg (idBroadcast integer primary key, iBroadcastUid integer, idChannel integer, sTitle text, sPlotOutline text, sPlot text, iStartTime integer, iEndTime integer, iGenreType integer, iGenreSubType integer, iFirstAired integer, iParentalRating integer, iStarRating integer, bNotify bool, sSeriesId text, sEpisodeId text, sEpisodePart text, sEpisodeName text)');
$db->exec('CREATE TABLE lastepgscan (idEpg integer primary key, iLastScan integer)');
$db->exec('CREATE TABLE version (idVersion integer, iCompressCount integer)');
$db->exec('CREATE VIEW vw_last_watched AS SELECT idChannel, iChannelNumber, sChannelName FROM Channels ORDER BY iLastWatched DESC');
$db->exec('CREATE INDEX idx_channelgroups_bIsRadio on channelgroups(bIsRadio)');
$db->exec('CREATE INDEX idx_channels_bIsHidden on channels(bIsHidden)');
$db->exec('CREATE INDEX idx_channels_bIsRadio on channels(bIsRadio)');
$db->exec('CREATE INDEX idx_channels_iChannelNumber on channels(iChannelNumber)');
$db->exec('CREATE UNIQUE INDEX idx_channels_iChannelNumber_bIsRadio on channels(iChannelNumber, bIsRadio)');
$db->exec('CREATE INDEX idx_channels_iClientId on channels(iClientId)');
$db->exec('CREATE INDEX idx_channels_iLastWatched on channels(iLastWatched)');
$db->exec('CREATE UNIQUE INDEX idx_epg_iBroadcastUid on epg(iBroadcastUid)');
$db->exec('CREATE INDEX idx_epg_iEndTime on epg(iEndTime)');
$db->exec('CREATE INDEX idx_epg_iStartTime on epg(iStartTime)');
$db->exec('CREATE INDEX idx_epg_idChannel on epg(idChannel)');
$db->exec('CREATE UNIQUE INDEX idx_epg_idChannel_iStartTime on epg(idChannel, iStartTime desc)');
$db->exec('INSERT INTO version VALUES(7,0)');
$db->exec('INSERT INTO clients VALUES(1,\'Tvheadend HTSP Client\',\'pvr.hts\')');
$lastepgscan = mktime()-(60*60*48);
$db->exec('INSERT INTO lastepgscan VALUES(0,\'' . $lastepgscan . '\')');
$lastwatched = mktime()-(60*60*48);
$line_count = count($final_channels_sorted_list);
for($i=0;$i<$line_count;$i++)
{
// TV Logo
if($config['tv_logo'] === 1):
if(isset($config_tv_logo[$final_channels_sorted_list[$i]['name']])):
$temp_tv_logo = '\'' . $config['path_tv_logo_-_xbmc'] . $config_tv_logo[$final_channels_sorted_list[$i]['name']] . '\'';
else:
$temp_tv_logo = '\'\'';
endif;
else:
$temp_tv_logo = '\'\'';
endif;
$temp_channel_number = ($config['xbmc_channel_id_one_by_one'] === 1) ? ($i+1) : $final_channels_sorted_list[$i]['channel_number'];
$channel_name_for_sql = preg_replace('/\'/','\'\'',$final_channels_sorted_list[$i]['name']);
$db->exec('INSERT INTO channels VALUES(
' . ($i+1) . ',
' . ($i+1) . ',
' . (int) $temp_channel_number . ',
0,
0,
0,
' . $temp_tv_logo . ',
\'' . $channel_name_for_sql . '\',
0,
1,
\'client\',
NULL,
1,
' . ($i+1) . ',
\'\',
\'\',
0)');
if(isset($config['xbmc_lastchannel']) && $final_channels_sorted_list[$i]['name'] == $config['xbmc_lastchannel']):
$db->exec('UPDATE channels SET iLastWatched=\'' . (int) $lastwatched . '\' WHERE sChannelName=\'' . $channel_name_for_sql . '\'');
endif;
}
}
function analog_tv($list_all_enabled_channel)
{
// 20.07.10
global $config;
list($analog_tv_services,$list_all_enabled_channel) = analog_tv_create_services($list_all_enabled_channel);
@mkdir($config['path_tvheadend_config_dir_output'] . $config['path_analog_tv_services']);
$dir_list_array = list_files_into_dir($config['path_tvheadend_config_dir'] . $config['path_analog_tv_adapters']);