01-06-2024, 04:55 PM
I just got a moment to look at this and there is prolly an easier and more flexible way to get MPD command output.
In file /var/www/command/index.php the code block below can be modified to return output from any MPD command. Some commamds return output that can be parsed by the general purpose parseDelimFile() routine but others require a custom parsing routine for example lsinfo, playlistinfo, etc, and so additional code is needed.
A feature implementation would be something like:
- An option to turn ON/OFF the feature
- Encapsulate the code in inc/<name>.php
- Conditional in command/index.php: if feature is on then parsrMpdOutput()
Example:
Output:
http://moode/command/?cmd=status
In file /var/www/command/index.php the code block below can be modified to return output from any MPD command. Some commamds return output that can be parsed by the general purpose parseDelimFile() routine but others require a custom parsing routine for example lsinfo, playlistinfo, etc, and so additional code is needed.
A feature implementation would be something like:
- An option to turn ON/OFF the feature
- Encapsulate the code in inc/<name>.php
- Conditional in command/index.php: if feature is on then parsrMpdOutput()
Example:
Code:
} else {
// MPD commands
if (false === ($sock = openMpdSock('localhost', 6600))) {
workerLog('command/index.php: Connection to MPD failed');
} else {
sendMpdCmd($sock, $_GET['cmd']);
$resp = readMpdResp($sock);
closeMpdSock($sock);
echo json_encode(parseDelimFile($resp, ': '));
/*if (stripos($resp, 'Error:')) {
echo $resp;
}*/
}
}
Output:
http://moode/command/?cmd=status
Code:
{"volume":"55","repeat":"0","random":"0","single":"0","consume":"0","partition":"default","playlist":"40","playlistlength":"34","mixrampdb":"0","state":"play","song":"5","songid":"6","time":"254:0","elapsed":"253.711","bitrate":"128","audio":"44100:24:2","nextsong":"6","nextsongid":"7"}