-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetmusicfiles.php
More file actions
149 lines (119 loc) · 3.89 KB
/
getmusicfiles.php
File metadata and controls
149 lines (119 loc) · 3.89 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
<?php
include "topline.php";
include "config.php";
if(!empty($_GET['source']))
{
//get argument of the source
$location = $_GET['source'];
//json rpc call procedure
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $xbmcjsonservice);
//array_sort function
function array_sort($a, $b) { return strnatcmp($a['label'], $b['label']); }
//get the results from the directory
$request2 = '{"jsonrpc" : "2.0", "method" : "Files.GetDirectory", "params" : { "directory" : "' . $location . '" }, "id" : 1}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $request2);
$array2 = json_decode(curl_exec($ch),true);
//query below contains both files and directories
$xbmcresults = $array2['result'];
//if the directory has content call AudioPlaylist.Add
if(!empty($_GET['directorycontent'])) {
//get selected songs
$addplaylist = $_GET['directorycontent'];
//only the files
$files = $xbmcresults['files'];
//sort files on name
usort($files, 'array_sort');
//count the number of songs
$songcount = count($files);
//put counter on zero
$i = 0;
//search the array_key of the selected song
foreach ($files as $value)
{
$song = $value['label'];
//there's a match
if ($song == $addplaylist)
{
//count remaining songs
$songqueue = $songcount - $i;
//we still need i
$y = $i;
//clear playlist
$data = '{"jsonrpc": "2.0", "method": "AudioPlaylist.Clear", "id": 1}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$array = json_decode(curl_exec($ch),true);
//get remaining songs from the array
while ($y <= $songcount -1)
{
//get the location of every song
$arraysongs = $files[$y];
$songlocations = $arraysongs['file'];
//filter on .mp3
if (fnmatch("*.mp3",$songlocations,FNM_CASEFOLD))
{
//add song to playlist
$request = '{"jsonrpc" : "2.0", "method": "AudioPlaylist.Add", "params" : { "file" : "' . $songlocations . '"}, "id": 1}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$array = json_decode(curl_exec($ch),true);
}
//loop for remaining songs
$y++;
}
//play item
$playdata = '{"jsonrpc": "2.0", "method": "AudioPlaylist.Play", "id": 1}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $playdata);
$array = json_decode(curl_exec($ch),true);
}
//loop for array_key
$i++;
}
//end for argument empty
}
echo "<div id=\"utility\"><ul>";
//show directories
if (array_key_exists('directories', $xbmcresults)) {
$directories = $xbmcresults['directories'];
//sort directories
usort($directories, 'array_sort');
foreach ($directories as $value)
{
$inhoud = $value['label'];
$display = urlencode($value['file']);
//remove synology shares from result
if (fnmatch("*eaDir*",$display,FNM_CASEFOLD)) { } else {
echo "<li><a href=getmusicfiles.php?source=$display>$inhoud</a></li>";
}
}
}
echo "</ul></div>";
echo "<div id=\"utility\"><ul>";
//show files in directory
if (array_key_exists('files', $xbmcresults)) {
$files = $xbmcresults['files'];
//sort on name
usort($files, 'array_sort');
foreach ($files as $value)
{
$inhoud = $value['label'];
$display = urlencode($value['file']);
//make directory and mp3 name url friendly
$location2 = urlencode($location);
$inhoud2 = urlencode($inhoud);
//show only .mp3 files
if (fnmatch("*.mp3",$display,FNM_CASEFOLD)) {
echo "<li><a href=getmusicfiles.php?source=$location2&directorycontent=$inhoud2>$inhoud</a></li>";
}
}
}
echo "</ul></div>";
//show playlist url when songs are added
if(!empty($_GET['directorycontent'])) {
echo "<br>";
echo "<div id=\"utility\"><ul><li><a href=getplaylist.php>playlist</a></li></ul></div>";
}
} else { echo "No source given!"; }
include "downline.php";
?>