-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
1651 lines (1359 loc) · 47.7 KB
/
index.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
# MIT License
#
# Copyright (c) 2020 Jared
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ASCII ART FROM
# http://patorjk.com/software/taag/#p=display&c=bash&f=Big%20Money-ne&t=encoding
#
# /$$ /$$ /$$
# | $$ | $$ |__/
# /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
# /$$_____/ /$$__ $$|_ $$_/|_ $$_/ | $$| $$__ $$ /$$__ $$ /$$_____/
# | $$$$$$ | $$$$$$$$ | $$ | $$ | $$| $$ \ $$| $$ \ $$| $$$$$$
# \____ $$| $$_____/ | $$ /$$| $$ /$$| $$| $$ | $$| $$ | $$ \____ $$
# /$$$$$$$/| $$$$$$$ | $$$$/| $$$$/| $$| $$ | $$| $$$$$$$ /$$$$$$$/
# |_______/ \_______/ \___/ \___/ |__/|__/ |__/ \____ $$|_______/
# /$$ \ $$
# | $$$$$$/
# \______/
# track runtime
$start = microtime(true);
$rustart = getrusage();
# constants
define("CONFIG_JSON_LOCATION", "G:\\config.json");
define("FILESYSTEM_BASE", 'G:\\');
define("PATH_FFMPEG", 'C:\\Users\\jared\\Downloads\\ffmpeg-4.2.1-win64-static\\bin\\ffmpeg.exe');
define("PATH_H264_QUEUE", "G:\\queue_h264.txt");
define("PATH_H265_QUEUE", "G:\\queue_h265.txt");
define("PATH_M4A_QUEUE", "G:\\queue_m4a.txt");
define("PATH_OPUS_QUEUE", "G:\\queue_opus.txt");
# load config file
$config = json_decode(file_get_contents(CONFIG_JSON_LOCATION));
// var_dump($config->db->user);
# setup db connection
$db = NULL;
if($config->use_db == 1) {
$db = new mysqli(
$config->db->host,
$config->db->user,
$config->db->password,
$config->db->database
);
}
# variables
$title = "Highwind's Stash";
$backgrounds = [
"black-pearl.jpg",
"camera.jpg",
"dvd.jpg",
"daftpunk.jpg",
"darwin.jpg",
"motoko.jpg",
"pinkfloyd.jpg",
"radiohead.jpg",
"vcr.jpg",
];
$search_type = '';
$dump_path = '';
$feature = "none";
$jquery_code_to_run = "";
$buttons = array();
$next_file_to_play = "";
$extensions = [
".aac",
".avi",
".flac",
".iso",
".m4a",
".m4b", // uncommon audio format
".m4v",
".mkv",
".mp3",
".mp4",
".ogg",
".opus",
".smc",
".wma",
".webm", // used for VP9
".y4m" // uncompressed video
];
$white_list = [
"Emulation + ROMs\\" ,
// "D&D\\",
"Books\\"
];
$excludes = [
"Backups+Temp",
"Software+Utilities",
"Dropbox"
];
# default to not show next and prev buttons
$show_prev_next = false;
// /$$ /$$ /$$
// | $$ | $$ | $$
// | $$$$$$$ /$$$$$$ /$$$$$$/$$$$ | $$
// | $$__ $$|_ $$_/ | $$_ $$_ $$| $$
// | $$ \ $$ | $$ | $$ \ $$ \ $$| $$
// | $$ | $$ | $$ /$$| $$ | $$ | $$| $$
// | $$ | $$ | $$$$/| $$ | $$ | $$| $$
// |__/ |__/ \___/ |__/ |__/ |__/|__/
//
// /$$
// | $$
// | $$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$
// | $$__ $$ |____ $$ /$$_____/ /$$__ $$
// | $$ \ $$ /$$$$$$$| $$$$$$ | $$$$$$$$
// | $$ | $$ /$$__ $$ \____ $$| $$_____/
// | $$$$$$$/| $$$$$$$ /$$$$$$$/| $$$$$$$
// |_______/ \_______/|_______/ \_______/
define('THEME_TOP' , <<<EOL
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>%%TITLE%%</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/full-width-pics.css" rel="stylesheet">
<!-- https://stackoverflow.com/questions/9789723/css-text-overflow-in-a-table-cell -->
<style>
.text-overflow-dynamic-container {
position: relative;
max-width: 100%;
padding: 0 !important;
display: -webkit-flex;
display: -moz-flex;
display: flex;
vertical-align: text-bottom !important;
}
.text-overflow-dynamic-ellipsis {
position: absolute;
white-space: nowrap;
overflow-y: visible;
overflow-x: hidden;
text-overflow: ellipsis;
-ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis;
max-width: 100%;
min-width: 0;
width:100%;
top: 0;
left: 0;
}
.text-overflow-dynamic-container:after,
.text-overflow-dynamic-ellipsis:after {
content: '-';
display: inline;
visibility: hidden;
width: 0;
}
</style>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="/">Highwind's Stash</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="./?c=n">NEW</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./?c=l">Links</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./?c=a">Audio Books</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./?c=b">Books</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./?c=e">Emulation</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./?c=v">Movies+TV</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./?c=m">Music</a>
</li>
</ul>
</div>
</div>
</nav>
EOL
);
define('THEME_BOTTOM', <<<EOL
</div>
</section>
<!-- Footer -->
<footer class="py-5 bg-dark">
<div class="container">
<a href="https://github.com/jwd83/VCR"><p class="m-0 text-center text-white" style="
-moz-transform: rotate(-180deg);
-ms-transform: rotate(-180deg);
-o-transform: rotate(-180deg);
-webkit-transform: rotate(-180deg);
transform: rotate(-180deg);
">Copyleft ©</p></a>
</div>
<!-- /.container -->
</footer>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>
EOL );
// /$$ /$$
// | $$ | $$
// | $$$$$$$ /$$$$$$ | $$ /$$$$$$ /$$$$$$ /$$$$$$
// | $$__ $$ /$$__ $$| $$ /$$__ $$ /$$__ $$ /$$__ $$
// | $$ \ $$| $$$$$$$$| $$| $$ \ $$| $$$$$$$$| $$ \__/
// | $$ | $$| $$_____/| $$| $$ | $$| $$_____/| $$
// | $$ | $$| $$$$$$$| $$| $$$$$$$/| $$$$$$$| $$
// |__/ |__/ \_______/|__/| $$____/ \_______/|__/
// | $$
// | $$
// |__/
// /$$$$$$ /$$ /$$
// /$$__ $$ | $$ |__/
// | $$ \__//$$ /$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
// | $$$$ | $$ | $$| $$__ $$ /$$_____/|_ $$_/ | $$ /$$__ $$| $$__ $$ /$$_____/
// | $$_/ | $$ | $$| $$ \ $$| $$ | $$ | $$| $$ \ $$| $$ \ $$| $$$$$$
// | $$ | $$ | $$| $$ | $$| $$ | $$ /$$| $$| $$ | $$| $$ | $$ \____ $$
// | $$ | $$$$$$/| $$ | $$| $$$$$$$ | $$$$/| $$| $$$$$$/| $$ | $$ /$$$$$$$/
// |__/ \______/ |__/ |__/ \_______/ \___/ |__/ \______/ |__/ |__/|_______/
function new_extension($src, $new_ext) {
$without_extension = substr($src, 0, strrpos($src, "."));
return $without_extension . $new_ext;
}
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
function writeFileToDBQueue($src, $type, $res = '0') {
global $db;
// echo "WRITING TO DB QUEUE";
# run query
$stmt = $db->prepare('INSERT INTO encoder_queue (path, codec, resolution) VALUES (?,?,?)');
$stmt->bind_param("sss", $src, $type, $res);
$stmt->execute();
}
function writeFileToQueue($src) {
if($GLOBALS['config']->use_db == 1) {
writeFileToDBQueue($src, "h264");
} else {
file_put_contents(PATH_H264_QUEUE, $src . PHP_EOL, FILE_APPEND);
}
}
function writeFileToHEVCQueue($src) {
if($GLOBALS['config']->use_db == 1) {
writeFileToDBQueue($src, "h265");
} else {
file_put_contents(PATH_H265_QUEUE, $src . PHP_EOL, FILE_APPEND);
}
}
function writeFileToAACQueue($src) {
if($GLOBALS['config']->use_db == 1) {
writeFileToDBQueue($src, "aac");
} else {
file_put_contents(PATH_M4A_QUEUE, $src . PHP_EOL, FILE_APPEND);
}
}
function writeFileToOpusQueue($src) {
if($GLOBALS['config']->use_db == 1) {
writeFileToDBQueue($src, "opus");
} else {
file_put_contents(PATH_OPUS_QUEUE, $src . PHP_EOL, FILE_APPEND);
}
}
function reencodeVideo($src) {
$src = FILESYSTEM_BASE . hexToStr($src);
if(file_exists($src)) {
$command = PATH_FFMPEG . " -i \"$src\" -codec copy \"$src.re.mp4\"";
exec($command);
}
}
function reencodeVideoHTML($src) {
$src = FILESYSTEM_BASE . hexToStr($src);
if(file_exists($src)) {
writeFileToQueue($src);
}
}
function reencodeVideoHEVC($src) {
$src = FILESYSTEM_BASE . hexToStr($src);
if(file_exists($src)) {
writeFileToHEVCQueue($src);
}
}
function reencodeAudioAAC($src) {
$src = FILESYSTEM_BASE . hexToStr($src);
if(file_exists($src)) {
writeFileToAACQueue($src);
}
}
function reencodeAudioOpus($src) {
$src = FILESYSTEM_BASE . hexToStr($src);
if(file_exists($src)) {
writeFileToOpusQueue($src);
}
}
function drawHeader($banner = false)
{
global $backgrounds, $title;
// global
if(isset($_REQUEST['file'])) {
$title = pathinfo(hexToStr($_REQUEST['file']))['basename'];
}
echo str_replace("%%TITLE%%", "$title", THEME_TOP) ;
if ($banner !== false)
{
?>
<!-- Header - set the background image for the header in the line below -->
<header class="py-5 bg-image-full" style="background-image: url('/img/<?= $backgrounds[array_rand ($backgrounds)]; ?>');">
<div class="container">
<h1 style="
color:#fff;
margin-bottom: 30px;
margin-top: 30px;
font-size: 5em;
opacity: 0.7;
-webkit-text-stroke: 3px black;
font-style: italic;
font-family: serif;
font-weight: bolder;
">
“<?= $banner ?>”
</h1>
</div>
</header>
<?php
}
echo
'
<!-- Content section -->
<section class="py-5">
<div class="container">
';
}
function strToHex($string){
$hex='';
for ($i=0;
$i < strlen($string); $i++){
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
function hexToStr($hex){
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2){
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
function startsWith ($string, $startString)
{
$len = strlen($startString);
return (substr($string, 0, $len) === $startString);
}
function getDirContents($dir, &$results = array()) {
$files = scandir($dir);
foreach ($files as $key => $value)
{
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (!is_dir($path))
{
$results[] = $path;
}
else if ($value != "." && $value != "..")
{
getDirContents($path, $results);
$results[] = $path;
}
}
return $results;
}
function echoCell($str, $italic = FALSE) {
if ($str == '-') {
echo "\n<td style=\"text-align: center;\">\n";
} else {
echo "\n<td>\n";
}
if($italic) {
echo "<em>$str</em>";
} else {
echo "$str";
}
echo "\n</td>\n";
}
function getDbButtons($base_path, $current_file) {
global $extensions, $db;
$path_to_find = substr(hexToStr($current_file), strlen($base_path) + 1);
// echo $current_file . "<br>\n" . hexToStr($current_file) . "<br>\n$base_path<br>\n$path_to_find";
$hit = 0;
$hit_checks = 0;
$prev_file = "";
$button_array = array();
$button_array['previous'] = "";
$button_array['next'] = "";
$button_array['previous_raw'] = "";
$button_array['next_raw'] = "";
# run query
$stmt = $db->prepare('SELECT * FROM files WHERE parent = ? ORDER BY path');
$stmt->bind_param("s", $base_path);
$stmt->execute();
$stmt->bind_result($r_id, $r_parent, $r_path, $r_size, $r_modified);
# look for our match
while($stmt->fetch()) {
$path = $base_path . "/" . $r_path;
if($hit == 1) {
$button_array['previous'] = strToHex($prev_file);
$button_array['next'] = strToHex($path);
$button_array['previous_raw'] = $prev_file;
$button_array['next_raw'] = str_replace('\\', '/', $path);
return $button_array;
} else {
if($path_to_find == $r_path) {
$hit = 1;
} else {
$prev_file = $path;
}
}
}
return $button_array;
}
function getButtons($base_path, $current_file) {
global $extensions;
if($GLOBALS['config']->use_db == 1) {
return getDbButtons($base_path, $current_file);
}
$hit = 0;
$hit_checks = 0;
$prev_file = "";
$button_array = array();
$button_array['previous'] = "";
$button_array['next'] = "";
$button_array['previous_raw'] = "";
$button_array['next_raw'] = "";
// $files = getDirContents($base_path, $junk , true); // using a named argument
$files = getDirContents($base_path);
// filter valid file extensions
foreach($files as $key => $path) {
$valid_extension = 0;
foreach($extensions as $ext) {
if (endsWith(strtolower($path), strtolower($ext))) {
$valid_extension = 1;
}
}
if($valid_extension == 0) {
unset($files[$key]);
}
}
// generate prev/next button data
foreach($files as $file) {
if(!is_dir($file)) {
$path = substr(trim($file), 3);
if($hit == 1) {
$button_array['previous'] = strToHex($prev_file);
$button_array['next'] = strToHex($path);
$button_array['previous_raw'] = $prev_file;
$button_array['next_raw'] = str_replace('\\', '/', $path);
return $button_array;
}
else
{
if(strToHex($path) == $current_file) {
$hit = 1;
} else {
$prev_file = $path;
}
}
}
}
return $button_array;
}
function drawResultNotes($base_path) {
echo "<h1>$base_path Results</h1>\n";
if($_REQUEST['c'] == 'v') {
echo "
<hr>
<h3>Notes</h3>
[direct] direct link to the video file. download or copy link address.<br>
[watch] place file in an html5 video tag player. your mileage may vary.<br>
[r] replace container with mp4. lossless but may not play in html5 video player.<br>
[h264] reencode using h264 & AAC audio. This is an html5 <video> safe format. new files end in .h264.mp4<br>
[h265] reencode using h265 & original audio in a matroska MKV container. new files end in .h265.mkv<br>
<hr>
";
}
if($_REQUEST['c'] == 'm') {
echo "
<hr>
<h3>Notes</h3>
[direct] direct link to the video file. download or copy link address.<br>
[listen] place file in an html5 audio tag player. your mileage may vary.<br>
[opus] lossy reencode file as .opus<br>
<hr>
";
}
}
function dbShowEverything($stmt) {
$stmt->execute();
$stmt->bind_result($r_id, $r_parent, $r_path, $r_size, $r_modified);
// todo better content type detection based on category flags to be added to config.json
echo '<hr><table>';
while ($stmt->fetch()) {
$path = $r_parent . "\\" . $r_path;
echo '<tr>';
echoCell('<a href="'.$path.'">[direct]</a>');
switch($r_parent) {
case 'Movies+TV':
// if the file was previously transcoded by this tool don't re-encode it again
// to prevent generation loss
if(endsWith($path, ".mp4") || endsWith($path, ".webm")) {
echoCell('<a href="?c=v&file='.strToHex($path).'">[watch]</a>');
} else {
echocell('-');
}
if(
endsWith($path, "h264.mp4") ||
endsWith($path, "h265.mkv") ||
endsWith($path, "vp9.webm") ||
endsWith($path, "av1.webm")
) {
echocell('-');
} else {
echoCell('<a href="?c=t&file='.strToHex($path).'">[transcode]</a>');
}
break;
case 'Music':
echoCell('<a href="?c=m&file='.strToHex($path).'">[listen]</a>');
echoCell('<a href="?c=o&file='.strToHex($path).'">[opus]</a>');
break;
case 'Emulation + ROMs':
echocell('-');
echocell('-');
break;
case 'Books':
echocell('-');
echocell('-');
break;
case 'Audio Books':
echoCell('<a href="?c=a&file='.strToHex($path).'">[listen]</a>');
echocell('-');
break;
default:
echocell('-');
echocell('-');
break;
}
echoCell(human_filesize($r_size), TRUE);
echoCell($path);
echo '<tr>';
}
echo '</table>';
}
function dbResultsEverything($query) {
global $db;
$search_str = "%".$query."%";
$stmt = $db->prepare('SELECT * FROM files WHERE path like ? ORDER BY parent DESC, path');
$stmt->bind_param("s", $search_str);
dbShowEverything($stmt);
}
function dbResults($base_path, $optional_feature = "none", $optional_reference = "none", $query = "none") {
global $extensions, $white_list, $excludes, $db;
drawResultNotes($base_path);
$stmt = NULL;
$search_str = "%".$query."%";
if($query != 'none') {
$stmt = $db->prepare('SELECT * FROM files WHERE parent = ? AND path like ? ORDER BY path');
$stmt->bind_param("ss", $base_path, $search_str);
} else {
$stmt = $db->prepare('SELECT * FROM files WHERE parent = ? ORDER BY path');
$stmt->bind_param("s", $base_path);
}
$stmt->execute();
echo "<table>\n";
$stmt->bind_result($r_id, $r_parent, $r_path, $r_size, $r_modified);
while ($stmt->fetch()) {
$path = $base_path . "/" . $r_path;
echo "<tr>\n";
echoCell('<a href="'.$path.'">[direct]</a>');
if($optional_feature != 'none') {
if($optional_reference == 'v') {
if(endsWith($path, "h265.mkv")) {
echocell('-');
} else {
echoCell('<a href="?c='.$optional_reference.'&file='.strToHex($path).'">['.$optional_feature.']</a>');
}
} else {
echoCell('<a href="?c='.$optional_reference.'&file='.strToHex($path).'">['.$optional_feature.']</a>');
}
}
if($optional_reference == 'v') {
if(
endsWith($path, "h264.mp4") ||
endsWith($path, "h265.mkv") ||
endsWith($path, "vp9.webm") ||
endsWith($path, "av1.webm")
) {
echocell('-');
} else {
echoCell('<a href="?c=t&file='.strToHex($path).'">[transcode]</a>');
}
}
if($optional_reference == 'm') {
if(endsWith($path, ".m4a") || endsWith($path, ".aac") || endsWith($path, ".opus")) {
echocell('-');
// echocell('-');
} else {
echoCell('<a href="?c=o&file='.strToHex($path).'">[opus]</a>');
// echoCell('<a href="?c=4&file='.strToHex($path).'">[aac]</a>');
}
}
echoCell(human_filesize($r_size), TRUE);
// echoCell(substr($path, strlen($base_path)-2));
echoCell($r_path);
echo "</tr>\n";
}
$stmt->close();
echo "</table>\n";
}
function dumpPath($base_path, $optional_feature = "none", $optional_reference = "none", $query = "none") {
global $extensions, $white_list, $excludes;
drawResultNotes($base_path);
$base_path = dirname(__FILE__) . $base_path;
# generate list of files into this array
$files = getDirContents($base_path);
# setup variables to filter our list for our static html cache page
$matched = 0;
$excluded = 0;
$skipped = 0;
$total = 0;
foreach($files as $file)
{
$match = '';
$total++;
$valid = 0;
if(!is_dir($file)) {
$path = substr(trim($file), 3);
// check for a valid file extension
foreach($extensions as $ext)
{
if (endsWith(strtolower($path), strtolower($ext)))
{
$valid = 1;
}
}
// check if the start of a path matches the whitelist
foreach($white_list as $wl)
{
if (startsWith(strtolower($path), strtolower($wl)))
{
$valid = 1;
}
}
// check against query
if($query != 'none' && $valid == 1) {
$valid = 0;
if (strpos(strtolower($path), strtolower($query)) !== false) {
$valid = 1;
}
}
// check that it's not in an excluded path
foreach($excludes as $exclude)
{
if (strpos(strtolower($path), strtolower($exclude)) !== false) {
$excluded++;
if($valid == 1) {
$matched--;
$skipped++;
}
$valid = 0;
}
}
}
if($valid === 1)
{
$matched++;
echo "<tr>\n";
echoCell('<a href="'.$path.'">[direct]</a>');
if($optional_feature != 'none') {
if($optional_reference == 'v') {
if(endsWith($path, "h265.mkv")) {
echocell('-');
} else {
echoCell('<a href="?c='.$optional_reference.'&file='.strToHex($path).'">['.$optional_feature.']</a>');
}
} else {
echoCell('<a href="?c='.$optional_reference.'&file='.strToHex($path).'">['.$optional_feature.']</a>');
}
}
if($optional_reference == 'v') {
if(endsWith($path, "h264.mp4") || endsWith($path, "h265.mkv")) {
echocell('-');
echocell('-');
echocell('-');
} else {
echoCell('<a href="?c=r&file='.strToHex($path).'">[r]</a>');
echoCell('<a href="?c=5&file='.strToHex($path).'">[h264]</a>');
echoCell('<a href="?c=n&file='.strToHex($path).'">[h265]</a>');
}
}
if($optional_reference == 'm') {
if(endsWith($path, ".m4a") || endsWith($path, ".aac") || endsWith($path, ".opus")) {
echocell('-');
// echocell('-');
} else {
echoCell('<a href="?c=o&file='.strToHex($path).'">[opus]</a>');
// echoCell('<a href="?c=4&file='.strToHex($path).'">[aac]</a>');
}
}
echoCell(human_filesize(filesize($path)));
echoCell(substr($path, strlen($base_path)-2));
echo "</tr>\n";
}
}
echo "</table><hr><div>$matched matched of $total files searched, $skipped of $excluded excluded</div>";
}
function rutime($ru, $rus, $index) {
return ($ru["ru_$index.tv_sec"]*1000 + intval($ru["ru_$index.tv_usec"]/1000))
- ($rus["ru_$index.tv_sec"]*1000 + intval($rus["ru_$index.tv_usec"]/1000));
}
function drawFooter() {
global $start, $rustart;
echo "<hr>";
$ru = getrusage();
$time_elapsed_secs = microtime(true) - $start;
echo "This process used " . rutime($ru, $rustart, "utime") . " ms for its computations.<br>\n";
echo "It spent " . rutime($ru, $rustart, "stime") . " ms in system calls.<br>\n";
echo '<b>Total Execution Time:</b> '.number_format($time_elapsed_secs,4).' seconds';
echo THEME_BOTTOM;
}
function buildPlaybackLink($file_in_hex, $type = "") {
# determine type
if(strlen($type) == 0) {
if(isset($_REQUEST['c'])) {
$type = $_REQUEST['c'];
}
}
# filename must already be in hex format
return "/?c=" . $type . "&file=".$file_in_hex;
}
function getSuggestions($category) {
global $config;
$sugs = '';
foreach($config->categories as $cat) {
if($cat->type == $category) {
foreach($cat->searches as $q)
$sugs .= '<a href="/?c='.$category.'&q='.$q.'">'.$q.'</a>, ';
}
}
return $sugs;
}
function pageIndex() {
drawHeader("Stay Awhile and Listen");
echo '
<h2>Please enjoy your stay and DM requests</h2>
<hr>
<h2>See <a href="/?c=n">what\'s new</a></h2>
Search:
<form method="GET">
<input type="text" name="q">
<select name="c">
<option value="z" selected>Everything</option>
<option value="a">Audio Books</option>
<option value="b">Books</option>
<option value="e">Emulation</option>
<option value="v">Movies+TV</option>
<option value="m">Music</option>
</select>
<input type="submit" value="Search">
</form>
<h2 style="margin-top: 1em;">Categories & Popular Searches</h2>
<div class="container">
<div class="row">
<div class="col-sm">
<h4 style="margin-top: 1em;"><a href="?c=m">Music</a></h4>
'.getSuggestions("m").'
</div>
<div class="col-sm">
<h4 style="margin-top: 1em;"><a href="?c=v">Movies+TV</a></h4>
'.getSuggestions("v").'
</div>
</div>
<div class="row">
<div class="col-sm">
<h4 style="margin-top: 1em;"><a href="?c=a">Audio Books</a></h4>
'.getSuggestions("a").'
</div>
<div class="col-sm">
<h4 style="margin-top: 1em;"><a href="?c=b">Books</a></h4>
'.getSuggestions("b").'
</div>
</div>
<div class="row">
<div class="col-sm">
<h4 style="margin-top: 1em;"><a href="?c=e">Emulation</a></h4>
'.getSuggestions("e").'
</div>