-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpostcommand.php
More file actions
77 lines (66 loc) · 2.59 KB
/
postcommand.php
File metadata and controls
77 lines (66 loc) · 2.59 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
<?php
include ("vars.php");
include ("functions.php");
$mpd_status = array();
$mpd_status['albumart'] = "";
@open_mpd_connection();
if($is_connected) {
$cmd_status = true;
fputs($connection, "command_list_begin\n");
$cmds = array();
foreach($_POST['commands'] as $cmd) {
$cmdstart = strpos($cmd, " ");
$part1 = substr($cmd, 0, $cmdstart);
if ($part1 == "additem") {
$part2 = substr($cmd, $cmdstart+1, strlen($cmd));
debug_print("Adding Item ".$part2,"POSTCOMMAND");
$cmds = array_merge($cmds, getItemsToAdd($part2));
} else {
array_push($cmds, $cmd);
}
}
$done = 0;
foreach ($cmds as $cmd) {
$cmdstart = strpos($cmd, " ");
$part1 = substr($cmd, 0, $cmdstart);
if ($part1 == "move") {
// NASTY HACK!
debug_print("Command List: ".$cmd,"POSTCOMMAND");
fputs($connection, $cmd."\n");
} else {
$part2 = substr($cmd, $cmdstart+1, strlen($cmd));
debug_print("Command List: ".$part1.' "'.format_for_mpd(trim($part2, '"')).'"',"POSTCOMMAND");
fputs($connection, $part1.' "'.format_for_mpd(trim($part2, '"')).'"'."\n");
}
$done++;
// Command lists have a maximum length, 50 seems to be the default
if ($done == 50) {
do_mpd_command($connection, "command_list_end", null, true);
fputs($connection, "command_list_begin\n");
$done = 0;
}
}
$cmd_status = do_mpd_command($connection, "command_list_end", null, true);
if (array_key_exists('extra', $_POST)) {
do_mpd_command($connection, $_POST['extra'], null, true);
}
$mpd_status = do_mpd_command ($connection, "status", null, true);
if (is_array($cmd_status) && !array_key_exists('error', $mpd_status)) {
debug_print("Command List Error ".$cmd_status['error'],"POSTCOMMAND");
$mpd_status = array_merge($mpd_status, $cmd_status);
}
if (array_key_exists('song', $mpd_status) && !array_key_exists('error', $mpd_status)) {
$songinfo = array();
$songinfo = do_mpd_command($connection, 'playlistinfo "' . $mpd_status['song'] . '"', null, true);
$mpd_status = array_merge($mpd_status, $songinfo);
}
} else {
if ($prefs['unix_socket'] != "") {
$mpd_status['error'] = "Unable to Connect to MPD server at\n".$prefs["unix_socket"];
} else {
$mpd_status['error'] = "Unable to Connect to MPD server at\n".$prefs["mpd_host"].":".$prefs["mpd_port"];
}
}
close_mpd($connection);
print json_encode($mpd_status);
?>