-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathmusicLibrary.php
54 lines (45 loc) · 1.17 KB
/
musicLibrary.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
<?php
///////////////////
// configuration
//
// relative path containing the modules - must be within the documentroot!
$songpath="mods";
//
//
///////////////////
// initialize to empty
$library=array();
// songs grouped by composer
foreach (glob($songpath."/*", GLOB_ONLYDIR) as $composer) {
$d=array();
$d['composer']=preg_replace('/^(.*)\//', '', $composer);
$songs=array();
$dir=opendir($composer);
$mods=array();
while($mod=readdir($dir)) $mods[]=$mod;
sort($mods);
foreach($mods as $mod) {
if (is_file($composer."/".$mod))
$songs[]=array('file'=>$mod, 'size'=>filesize($composer."/".$mod));
}
closedir($dir);
$d['songs']=$songs;
$library[]=$d;
}
// songs by an unknown composer from the root of "mods/"
$d=array('composer'=>'Unknown');
$songs=Array();
$dir=opendir("mods");
$i=0;
$mods=array();
while($mod=readdir($dir)) $mods[]=$mod;
sort($mods);
foreach($mods as $mod) {
if (is_file("mods/".$mod))
$songs[]=array('file'=>$mod, 'size'=>filesize($songpath."/".$mod));
}
closedir($dir);
$d['songs']=$songs;
$library[]=$d;
echo json_encode($library);
?>