-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
3352 lines (2886 loc) · 224 KB
/
index.php
File metadata and controls
3352 lines (2886 loc) · 224 KB
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
#####
# # #### # # ###### # #### # # ##### ## ##### # #### # #
# # # ## # # # # # # # # # # # # # # # ## #
# # # # # # ##### # # # # # # # # # # # # # # #
# # # # # # # # # ### # # ##### ###### # # # # # # #
# # # # # ## # # # # # # # # # # # # # # # ##
##### #### # # # # #### #### # # # # # # #### # #
define('OPT_SQL_FILENAME', 'oryx.db');
// currently there can only be one music folder. OPT_MUSICDIR should be the unix path (from root)
// to this folder. It is VERY important that this path has a trailing slash.
define('OPT_MUSICDIR', '/home2/buckly/nonpublic/submusic2/');
// the letter groups for indexes. space-separated characters (or groups of characters)
define('OPT_LETTERGROUPS', 'A B C D E F G H I J K L M N O P Q R S T U V W XYZ #');
define('OPT_NONALPHALETTERGROUP', '#');
// articles ignored when sorting indexes. Space-separated words.
define('OPT_ARTICLES', 'The');
// disable this if you want oryx to require no authentication. Not recommended if your server is public-facing.
define('REQUIRE_AUTH', true);
// Allowing oryx to serve a partial file is required for being able to skip through a track (past the buffer).
// Also Safari won't even show playing progress or time without partial file service. Turn this off, however, if
// you want to decrease the load on your server, because partial file service uses more resources than otherwise.
define('STREAM_ALLOW_PARTIAL', true);
// this defines whether the JavaScript playback engine will preload tracks, so the next song will play without delay.
define('PLAYBACK_PRELOAD', false);
// this defines whether the backdrop of a folder view (on the web frontend) will enclude a (very faded) album
// art backdrop
define('ALBUMART_BACKDROP', true);
// whether you want the index headers to be scroll-persistent.
define('PERSISTENT_INDEXHEADERS', true);
// this sets the webpage title for all responses.
define('FRONT_TITLE', 'Oryx');
// this defines which images will be accepted as cover art (currently only jpeg is supported)
define('ALBUMART_REGEXP', '/^(id3)?(folder|cover|album)(art)?\.(jpg|jpeg)$/i');
/**** The following settings should only be modified if you know what you're doing. ****/
define('TIME_2033', 2000000000);
define('OPT_SCAN_COUNTPERREFRESH', 75);
define('OPT_ACCEPTED_FILE_TYPES', '.mp3'); //lower case only
define('OPT_IGNOREDFOLDERS', '.. .');
define('IMG_ICON', 'image/gif;base64,R0lGODlhDAAMAJECAAAAAJaWlv///wAAACH5BAEAAAIALAAAAAAMAAwAAAIZlI+pGe2NgpKHxssOAGobn4AgInKhuaRpAQA7');
// for now the 'last modified' for an index request is a constant
define('OPT_TEMP_LASTMODIFIED', '237462836472342');
# # ####### # # #
# # # ## ## #
# # # # # # # #
####### # # # # #
# # # # # #
# # # # # #
# # # # # #######
// the main page for oryx's web interface. below you see only what is common to all pages.
// the three functions provided $style, $script, and $body will be called at the appropriate times
// to insert these sections. If you specify no arguments, the default (authorised) page is rendered.
function htmlHome($style='htmlStyle', $script='htmlScript', $body='htmlBody') { ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- EXTERNAL JS -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js" ></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-color/2.1.2/jquery.color.min.js" ></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/js/bootstrap.min.js" ></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js" ></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5sortable/0.1.1/html.sortable.min.js" ></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator.min.js" ></script>
<!-- <script src="//cdnjs.cloudflare.com/ajax/libs/sortable/0.6.0/js/sortable.min.js" ></script> -->
<!-- EXTERNAL CSS -->
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Raleway:100,200,300,400,500,600,700,800,900" >
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css" >
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css" >
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/css/bootstrapvalidator.min.css" >
<link rel="icon" type="img/ico" href="data:<?php echo IMG_ICON; ?>">
<?php $style(); ?>
<?php $script(); ?>
<title><?php echo FRONT_TITLE; ?></title>
</head>
<body>
<?php $body(); ?>
</body>
</html>
<?php }
function htmlBody() { ?>
<div class="leftPanelWrapper">
<div class="leftPanel"></div>
</div>
<div class="centrePanelWrapper">
<div class="centrePanel"> </div>
</div>
<div class="rightPanelWrapper">
<div class="rightPanel">
<audio id="htmlAudio" controls autoplay></audio>
<table id="playlistTable"><tbody></tbody></table>
<div id="playerControls">
<button type="button" data-toggle="tooltip" data-placement="bottom" title="Previous Track" onclick="javascript:prevTrack();" class="btn btn-default btn-s"><i class="fa fa-step-backward"></i></button>
<button type="button" data-toggle="tooltip" data-placement="bottom" title="Restart Track" onclick="javascript:startTrack();" class="btn btn-default btn-s"><i class="fa fa-rotate-right" ></i></button>
<button type="button" data-toggle="tooltip" data-placement="bottom" title="Next Track" onclick="javascript:nextTrack();" class="btn btn-default btn-s"><i class="fa fa-step-forward" ></i></button>
<button type="button" data-toggle="tooltip" data-placement="bottom" title="Shuffle Playlist" onclick="javascript:shufflePlaylist();" class="btn btn-default btn-s"><i class="fa fa-random" ></i></button>
<button type="button" data-toggle="tooltip" data-placement="bottom" title="Clear Playlist" onclick="javascript:clearPlaylist();" class="btn btn-default btn-s"><i class="fa fa-trash-o" ></i></button>
</div>
</div>
</div>
<div class="footerWrapper">
<div class="footer">
<a href="?/signout">Sign Out</a>
<a href="javascript:void(0);" onclick="scanDB();">Scan DB</a>
<a href="#/settings">Settings</a>
<div class="progress progress-striped" style="width:300px;">
<div class="progress-bar" style="width: 100%;">
<span></span>
</div>
</div>
</div>
</div>
<?php }
// the raw HTML for a login form. This uses bootstrap heavily.
function htmlLoginForm() { ?>
<div class="loginContainer">
<form class="form-signin" method="post">
<h2 class="form-signin-heading">Sign in to <b>Oryx</b></h2>
<input type="text" class="form-control" placeholder="Username" name="frmUsr" required autofocus>
<input type="password" class="form-control" placeholder="Password" name="frmPwd" required>
<?php postLoginFailAlert(); ?>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
<?php }
// create the raw HTML for a 'bad auth' page - this is just a login screen.
function htmlBadAuth() {
htmlHome(
'htmlStyle',
'·',
'htmlLoginForm'
);
}
function postLoginFailAlert() {
if (¿($GLOBALS['loginPostTried'])) { ?>
<div class="alert alert-danger fade in">
<strong>Bad work bro.</strong> Your username and password didn't work. Try again I guess.
</div>
<script type="text/javascript"> $(".alert").delay(4000).slideUp(2000); </script>
<?php }
}
function htmlSettings() { ?>
<div class="settingsContainer">
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="active"><a href="#generalSettings" data-toggle="tab">General</a></li>
<li> <a href="#musicSettings" data-toggle="tab">Music </a></li>
<li> <a href="#userSettings" data-toggle="tab">Users </a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane fade in active" id="generalSettings"></div>
<div class="tab-pane fade" id="musicSettings" ></div>
<div class="tab-pane fade" id="userSettings" ></div>
</div>
</div>
<?php }
##### ##### #####
# # # # # #
# # #
# ##### #####
# # #
# # # # # #
##### ##### #####
function htmlStyle() { ?>
<style type="text/css">
/* General */
html {
height: 100%;
}
body {
font-family: 'Raleway', sans-serif;
font-weight: 300;
color: #222;
height: 100%
}
audio {
width: 100%;
display: block;
}
table {
font-family: inherit;
font-size: inherit;
font-style: inherit;
font-variant: inherit;
font-weight: inherit;
}
div.loader {
font-size: 300px;
color: #FAFAFA;
text-align: center;
margin: 100px;
}
/* Layout */
.leftPanelWrapper {
position: absolute;
left: 0px;
top: 0px;
bottom: 40px;
width: 200px;
overflow-y: scroll;
background-color: #EEE;
border-bottom-right-radius: 5px;
padding: 5px;
border-right: 1px solid #DDD;
border-bottom: 1px solid #DDD;
}
.leftPanel {}
.centrePanelWrapper {
position: absolute;
top: 0px;
left: 200px;
right: 300px;
bottom: 40px;
background-size: cover;
background-position: center center;
padding: 0px 0px 0px;
}
.centrePanel {
height: 100%;
background-color:#FFF;
overflow-y: scroll;
}
.rightPanelWrapper {
position: absolute;
top: 0px;
bottom: 40px;
width: 300px;
right: 0px;
overflow-y: scroll;
background-color: #EEE;
border-bottom-left-radius: 5px;
padding: 5px;
border-left: 1px solid #DDD;
border-bottom: 1px solid #DDD;
}
.rightPanel {}
.footerWrapper {
position: absolute;
left: 0px;
right: 0px;
bottom: 0px;
height: 35px;
border-top: 1px solid #DDD;
}
.footer {
background: #EEE;
width: 100%;
height: 100%;
padding: 5px;
}
.footer div.progress {
float: right;
}
/* Indexes */
div.indexGroupHeader {
font-weight: 900;
background-color: #BBB;
padding-left: 8px;
border-radius: 5px;
z-index: ;
}
div.indexGroupHeaderFloater {
display:none;
position: fixed;
top: 0px;
width: 190px;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
}
div.indexItem {
font-size: 10pt;
padding-left: 18px;
text-indent: -6px;
}
div.indexItem:hover {
background-color: #eaeaea;
padding-left: 9px;
border-left: 3px solid #ccc;
border-right: 3px solid #ccc;
}
a.indexItemAnchor {
color: #000;
text-decoration: none;
width: 100%;
display: block;
}
/* Header */
h1.musicheader {
background-color: rgba(0, 0, 0, 0.01);
margin: 0px 0px;
color: rgba(138, 138, 138, 0.8);
text-shadow: 1px 4px 6px #eee, 0 0 0 #000, 1px 4px 6px #eee;
border-bottom: 1px solid #DDD;
padding: 5px;
}
#titleParent {
font-size: 20pt;
padding: 0px;
font-weight: 700;
}
#titleParent a {
color: inherit;
}
#titleWrapper {
font-weight: 900;
padding: 0px 0px 5px;
display:table;
width: 100%;
}
#directoryTitle {
display:table-cell;
width: 100%;
padding-left: 8px;
}
#titleButton {
display: table-cell;
vertical-align: middle;
text-align: right;
}
/* Login Screen */
.loginContainer {
width: 100%;
height: 100%;
background-color: #EEE;
padding-top: 40px;
padding-bottom: 40px;
border-radius: 5px;
}
.form-signin {
max-width: 400px;
padding: 25px;
margin: 0 auto;
}
.form-signin-heading {
text-align: center;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
height: auto;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="text"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
/* Directory List */
.tracktable {
width: 100%;
}
tr.track {
cursor: pointer;
}
tr.track.curPlaying {
font-weight:bold;
}
tr.track:hover td:last-child::after {
font-family: 'FontAwesome';
content: '\f0a9';
display: block;
float: right;
}
.table-striped > tbody > tr:nth-child(odd) > td,
.table-striped > tbody > tr:nth-child(odd) > th {
background-color: rgba(0, 0, 0, 0.025);
}
th.trackTrack {
width: 1%;
}
th.trackDuration {
width: 1%;
}
.dirtableWrapper {
padding: 10px;
}
.dirtable {
width: 100%;
empty-cells: show;
}
.dirtable td:first-child {
width: 0px;
}
.dirtable td:last-child {
}
.dirtable tr:hover {
background-color: rgba(0,0,0,0.05);
}
.dirtable td {
padding: 5px;
}
.dirtable td a {
color: inherit;
font-size: 20px;
}
.dirtable td:first-child {
width: 110px;
height: 110px;
}
img.dirListCover {
width: 100px;
height: 100px;
display: none;
}
.imgerror {
display: none;
font-family: 'FontAwesome';
text-align: center;
line-height: 100px;
width: 100px;
height: 100px;
font-size: 80px;
border: 1px solid #DDD;
color: white;
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000
}
/* Playlist */
#playlistTable {
font-size: 8pt;
width: 100%;
}
#playlistTable .playingTrack {
font-weight: 500;
}
#playlistTable .trackTR {
cursor: move;
box-sizing: border-box;
}
#playlistTable .sortable-placeholder {
border: 1px dashed #CCC;
}
#playlistTable .sortable-dragging {
opacity: 0.75;
}
#playlistTable .pliDuration {
text-align: right;
width: 20px;
}
#playlistTable.multipleDirs .trackTR {
border-right: 5px solid;
}
#playlistTable .trackTR .pliPlay ,
#playlistTable .trackTR .pliDelete {
font-family: 'FontAwesome';
color: transparent;
cursor: pointer;
}
#playlistTable .trackTR:hover .pliPlay ,
#playlistTable .trackTR:hover .pliDelete {
color: #CCC;
}
#playlistTable .trackTR .pliPlay:hover ,
#playlistTable .trackTR .pliDelete:hover {
color: #000;
}
#playlistTable .trackTR .pliDelete {
text-align: right;
}
#playerControls {
margin-top: 5px;
text-align: center;
}
#playerControls button {
padding: 5px 10px;
font-size: 15px;
}
/* Footer stuff */
div.progress {
margin: 0px;
}
/* Settings */
.settingsContainer {
width: 100%;
height: 100%;
padding-top: 10px;
}
.settingsContainer ul.nav-tabs li:first-child {
margin-left: 10px;
}
.settingsContainer ul.nav-tabs li:last-child {
margin-right: 10px;
}
.tab-content {
padding: 10px;
}
#userstable thead th {
white-space: nowrap;
}
#userstable thead th {
width: 20%;
}
#userstable thead th:first-child {
width: 50%;
}
#userstable thead th.tinyth {
width: 1%;
}
.adduserbtn {
float: right;
}
</style>
<?php }
# #####
# ## # # ## # # #### ##### # ##### #####
# # # # # # # # # # # # # # # #
# # # # # # # ##### # # # # # # #
# # ###### # # ###### # # ##### # ##### #
# # # # # # # # # # # # # # # # #
##### # # ## # # ##### #### # # # # #
function htmlScript() { ?>
<script type="text/javascript">
//settings via PHP
var PLAYBACK_PRELOAD = <?php echo tf(PLAYBACK_PRELOAD); ?>;
var ALBUMART_BACKDROP = <?php echo tf(ALBUMART_BACKDROP); ?>;
var PERSISTENT_INDEXHEADERS = <?php echo tf(PERSISTENT_INDEXHEADERS); ?>;
//semi-globals
var currentTrackIndex = 0;
var isPlaying = false;
var altAudio = null;
//code snippets
var snippetLoader = '<div class="loader"><i class="fa fa-cog fa-spin"></i></div>';
var snippetErrorLoading = '<div class="loader"><i class="fa fa-wheelchair"></i></div>';
var snippetTrackLoading = '<i class="fa fa-spinner fa-spin"></i>';
//extra jQuery features
$.fn.exists = function () { return this.length !== 0; }
$.fn.orreturn = function(def) { return this.exists() ? this : def; }
$.fn.orrun = function(foo) { return foo(); };
$.fn.random = function() {return $(this[Math.floor(Math.random() * this.length)]);};
$.fn.poprandom = function() {return this.splice(Math.floor(Math.random() * this.length),1);};
$.fn.reverse = [].reverse;
// this executes when the document is 'ready'. Here we do a bunch of preparation for later behaviour.
$(function() {
//bind hash listener, and process URL's hash
$(window).bind('hashchange', hashResponse);
hashResponseMaybe();
// load the indexes (on the left)
loadIndexes();
// disable preloading for IE9
if(navigator.appVersion.indexOf("MSIE 9.")!=-1) PLAYBACK_PRELOAD=false;
// make the playlist sortable
$('#playlistTable tbody').sortable({
items : 'tr'
, placeholder : '<tr><td colspan="4"> </td></tr>'
, forcePlaceholderSize : true
});
// bind listeners to the audio element
prepAudioElement();
// setup tooltips on buttons
$('#playerControls button').tooltip();
prepButtons();
// setup persistent headers
if (PERSISTENT_INDEXHEADERS) {
scrollHeaders();
}
});
function scanDB() {
var progress = $('.footer .progress');
var progressbar = $('.footer .progress-bar');
var progressspan = $('.footer .progress-bar span');
progress.addClass('active');
progressspan.text("Looking for new files...");
$.getJSON('?/db/newfiles', function(data) {
var totalcount = data.oryx_newfiles.newfiles;
progress
.removeClass('active')
.removeClass('progress-striped');
progressspan
.text("Processing new files...");
var callBack = function(newdata) {
var newcount = newdata.oryx_scantracks.newfiles;
showProgress(totalcount-newcount, totalcount);
if (newcount > 0)
$.getJSON('?/db/scantracks', callBack)
.fail(badProgress);
}
loadIndexes();
$.getJSON('?/db/scantracks', callBack)
.fail(badProgress);
}).fail(badProgress);
}
function showProgress(progress, outof) {
var progressbar = $('.footer .progress .progress-bar');
if (progress == outof || outof == 0) {
progressbar
.css('width', '100%')
.addClass('progress-bar-success');
progressbar
.find('span')
.text("Finished scanning.");
} else {
var percent = parseInt(100*parseFloat(progress)/parseFloat(outof)) + '%';
progressbar.css('width', percent);
progressbar.find('span').text(percent);
}
}
function badProgress() {
var progressbar = $('.footer .progress .progress-bar');
progressbar
.css('width', '100%')
.removeClass('progress-bar-success')
.addClass('progress-bar-danger');
progressbar
.find('span')
.text("There was an error while scanning :(");
}
// applies 'persistent header' style to headers in the index (left panel).
function scrollHeaders() {
var lastIndex = -1;
var floatingHeaderActive = false;
$('.leftPanelWrapper').scroll(function() {
var floatingHeader = $('.indexGroupHeaderFloater');
var needFloat = false;
var currentlyShiftingHeader = false;
$('.indexGroup').reverse().each(function(index) {
var offsetTop = $(this).offset().top;
if (!currentlyShiftingHeader)
floatingHeader.css('top', 0);
if (offsetTop <= 0) {
if (lastIndex != index || !floatingHeaderActive) {
if (!floatingHeaderActive) {
floatingHeader.css('display', 'block');
floatingHeaderActive = true;
}
floatingHeader.text($(this).find('.indexGroupHeader').text());
lastIndex = index;
}
needFloat = true;
return false;
}
currentlyShiftingHeader = false;
if (offsetTop <= floatingHeader.outerHeight() && offsetTop > 0) {
floatingHeader.css('top', offsetTop-floatingHeader.outerHeight());
currentlyShiftingHeader = true;
}
});
if (!needFloat) {
floatingHeader.css('display', 'none');
floatingHeaderActive = false;
}
});
}
// add some wrapper behaviour for the media buttons
function prepButtons(selector) {
if(typeof(selector)==='undefined') selector = 'button';
$(selector).click(function(){
var that = this;
setTimeout(function() { $(that).blur(); }, 1000);
});
}
function prepAudioElement() {
$('#htmlAudio')
.on('ended', audEnded)
.on('canplay', audCanPlay)
.on('play', audPlay)
.on('pause', audPause)
.on('timeupdate', audTimeUpdate);
}
function doPlayPause() {
ddAudio = $('#htmlAudio').get(0);
if (ddAudio.paused)
ddAudio.play();
else
ddAudio.pause();
}
function audEnded() {
isPlaying = false;
nextTrack();
}
function audPlay() {
isPlaying = true;
}
function audCanPlay() {}
function audPause() {}
function clearPlaylist() {
$('#playlistTable tbody').empty();
checkMultipleDirsPlaying();
clearPidHues();
}
function shufflePlaylist() {
var body = $('#playlistTable tbody');
var tracks = body.find('.trackTR').not('.playingTrack').detach();
while(tracks.length>0) {
body.append(tracks.poprandom());
}
}
function nextTrack() {
moveTrack(1);
}
function prevTrack() {
moveTrack(-1);
}
function startTrack() {
moveTrack(0);
}
function getCurTrack() {
var cur = $('.trackTR.playingTrack').first();
if (!cur.exists()) {
cur = $('.trackTR').first();
cur.addClass('playingTrack');
}
return cur;
}
function showPlaying(newTrack) {
$("table.tracktable tr.track")
.removeClass('curPlaying')
.filter("[oryxid="+newTrack+"]")
.addClass('curPlaying');
}
// +1 means 'next track'. -1 means 'previous track'. 0 means 'restart (and reload) track'
function moveTrack(change) {
// the currently playing track
var oldTR = getCurTrack();
oldTR.removeClass('playingTrack');
// choose and select the next track
var newTR = oldTR;
while (change > 0) {
newTR = newTR.next('.trackTR');
change--;
}
while (change < 0) {
newTR = newTR.prev('.trackTR');
change++;
}
newTR.addClass('playingTrack');
// play the track.
var newTrack = newTR.attr('oryxid');
// update other UI elements that this new track is playing
showPlaying(newTrack);
// check if there is an (appropriate) preloaded track
if (altAudio!=null && altAudio.attr('oryxid') == newTrack) {
consoleLog('Playing. Preloaded.');
// set the (background loaded) audio element's id to htmlAudio, for later access
altAudio.attr('id', 'htmlAudio');
altAudio.get(0).volume = $('#htmlAudio').get(0).volume;
// replace the current audio element with the background-loaded one.
$('#htmlAudio').replaceWith(altAudio);
// wipe 'altAudio' from memory
altAudio = null;
// bind appropriate functions to the new audio element
prepAudioElement();
// make the new audio element start playing
$('#htmlAudio').get(0).play();
} else {
// set the source of the current audio element to be the new source, and tell it to load and play
$('#htmlAudio')
.attr('src', '?/rest/stream.view?id='+newTrack)
.load();
$('#htmlAudio').get(0).play();
consoleLog('Playing. Not preloaded.')
}
}
function audTimeUpdate() {
if (!this.hasOwnProperty('preloadFlagged') && PLAYBACK_PRELOAD) {
var threshold = this.duration*0.75;
if (this.currentTime > threshold) {
startPreload();
this.preloadFlagged = true;
}
}
}
function getNextTrackId() {
var cur = $('.trackTR.playingTrack').first().next('.trackTR');
if (cur)
return cur.attr('oryxid');
return 0;
}
function startPreload() {
// get the id for the track that should play next
var nextid = getNextTrackId();
// make a new audio element, which will preload the next mp3.
altAudio = $('<audio>', {
src : '?/rest/stream.view?id='+nextid
, preload : 'auto'
, autoplay : 'false'
, controls : 'controls'
, oryxid : nextid
});
// make sure that the new audio element doens't play in the background.
altAudio.get(0).pause();
altAudio.get(0).volume = 0;
consoleLog('preloading...');
}
// what happens when you click on a track in the library pane.
var firstTimeSelected = true;
function selectTrack(tid, pid, title, duration) {
var dTrackTable = $('#playlistTable tbody');
// set up a new TR for this new track
var dNewTrackTR = $('<tr>', {
class : 'trackTR'
, id : 'track'+tid
, oryxid : tid
, oryxpid : pid
})
.append($('<td>', {
class : 'pliPlay'
, html : ''
, click : function() {
// enable the 'play' button for this track
dNewTrackTR.siblings().removeClass('playingTrack');
dNewTrackTR.addClass('playingTrack');
startTrack();
}
}))
.append($('<td>', {
class : 'pliName'
, text : title
}))
.append($('<td>', {
class : 'pliDuration'
, text : duration
}))
.append($('<td>', {
class : 'pliDelete'
, html : ''
, click : function() {
// enable the 'delete' button for this track
dNewTrackTR.remove();
checkMultipleDirsPlaying();
}
}))
// add the color border thing for this track
dNewTrackTR.css('border-color', hslToRgb(pidToHue(pid),0.4,0.8));
dTrackTable.append(dNewTrackTR);
// make sure the new item is sortable
dTrackTable.sortable('reload');
// start playing, if necessary
if (firstTimeSelected || $('#htmlAudio').get(0).ended || $('#htmlAudio').get(0).currentTime==0) {
startTrack();
firstTimeSelected = false;
}
// check to see if there are multiple directories of music in the playlist
checkMultipleDirsPlaying();
}
// check to see if there are multiple directories of music in the playlist, and set the 'multipleDirs'
// class accordingly.
function checkMultipleDirsPlaying() {
var pids = _.uniq($("#playlistTable .trackTR").map(function(){return $(this).attr("oryxpid")}).get());
if (pids.length > 1)
$("#playlistTable").addClass('multipleDirs');
else
$("#playlistTable").removeClass('multipleDirs');
}
var pidHues = {};
var prevHue = -1;
function pidToHue(pid) {
if (prevHue == -1) {
pidHues[pid] = (pid*0.6180339887498948)%1;