Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Idea: API Candidate
#10
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:

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"}
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Messages In This Thread
API Candidate - by ubergoober - 12-31-2023, 07:04 PM
RE: API Candidate - by Tim Curtis - 12-31-2023, 07:13 PM
RE: API Candidate - by Tim Curtis - 12-31-2023, 07:16 PM
RE: API Candidate - by ubergoober - 12-31-2023, 07:26 PM
RE: API Candidate - by Tim Curtis - 12-31-2023, 08:21 PM
RE: API Candidate - by ubergoober - 12-31-2023, 08:54 PM
RE: API Candidate - by ubergoober - 12-31-2023, 10:46 PM
RE: API Candidate - by Nutul - 01-01-2024, 05:38 PM
RE: API Candidate - by ubergoober - 01-01-2024, 09:05 PM
RE: API Candidate - by Tim Curtis - 01-06-2024, 04:55 PM
RE: API Candidate - by ubergoober - 01-06-2024, 06:11 PM
RE: API Candidate - by Tim Curtis - 01-06-2024, 06:26 PM
RE: API Candidate - by ubergoober - 01-06-2024, 07:53 PM

Forum Jump: