Thank you for your donation!


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


Idea: API Candidate
#1
I've taken a stab at the beginnings of a REST API using Python3 and a tool called FAST API and uvicorn.  I've got it running on the pi zero 2w and configured systemd to start it automatically.  

The approach I took was to try to do what MPC and vol.sh do.  The API is making system calls to run  mpc, but does its own work to emulate what Tim has coded in vol.sh.  I didn't implement everything that MPC offers.  Instead, I went after a subset that I find useful.  Testing has been minimal and I've only made it functional, not bullet proof.  I don't code for a living.  I'm a telecomm/voip engineer in my day job.

I'm also thinking of adding a couple of things from moodeutl.  Below is a link to a PDF of the swagger page generated by FAST API.  Will you please give it a look?  Feedback is appreciated. 

https://drive.google.com/drive/folders/1...sp=sharing

Thanks for your consideration,
Tom Lynn
Reply
#2
Thread moved to support
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
There is an existing REST API documented in the Setup Guide
https://github.com/moode-player/moode/bl.../setup.txt

Is the API you are using similar?
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#4
(12-31-2023, 07:16 PM)Tim Curtis Wrote: There is an existing REST API documented in the Setup Guide
https://github.com/moode-player/moode/bl.../setup.txt

Is the API you are using similar?

Understood and in some ways it is similar.  You have some items I would probably add, but other things like loading a playlist, toggling consume, clearing the playlist I was unable to do with the existing API.
Reply
#5
I tried the link in your OP but it looks like its broken.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#6
(12-31-2023, 08:21 PM)Tim Curtis Wrote: I tried the link in your OP but it looks like its broken.

Here's a paste from the PDF.  it looks better in the doc, though.  I'll try to fix it later when we get back from the doc.

FastAPI
/openapi.json

default
GET / Root

GET /mpc/consume Consume

GET /mpc/clear Clear

GET /mpc/current Current

GET /mpc/lsplaylists Lsplaylists

GET /mpc/load/{file} Load

GET /mpc/next Next

GET /mpc/pause Pause

GET /mpc/play/{song_number} Play

GET /mpc/prev Prev

GET /mpc/random Random

GET /mpc/repeat Repeat

GET /mpc/shuffle Shuffle

GET /mpc/stop Stop

GET /mpc/toggle Toggle
0.1.0 OAS 3.1

GET /mpc/volume/ Volume

GET /mpc/volume/{absolute_level} Absolute Volume

GET /mpc/mute Mute

GET /mpc/restore Restore

GET /mpc/volumeup/{increment} Volumeup

GET /mpc/volumedn/{increment} Volumedn
Reply
#7
updated link. Hope it works: https://drive.google.com/file/d/1G85Yped...sp=sharing
Reply
#8
(12-31-2023, 10:46 PM)ubergoober Wrote: updated link.  Hope it works:  https://drive.google.com/file/d/1G85Yped...sp=sharing

Hi,

nice, I also had thought of making one, lots of fun :-)

Just a comment by a pedantic developer: as a rule of thumb, the endpoints that modify statuses (like CONSUME), or perform actions (like PLAY, or CLEAR) should use the POST verb, not GET - which is instead valid for all the endpoints that just return information, without modifying/executing anything (like LSPLAYLISTS => available playlists, or VOLUME => current volume level).
Reply
#9
(01-01-2024, 05:38 PM)Nutul Wrote:
(12-31-2023, 10:46 PM)ubergoober Wrote: updated link.  Hope it works:  https://drive.google.com/file/d/1G85Yped...sp=sharing

Hi,

nice, I also had thought of making one, lots of fun :-)

Just a comment by a pedantic developer: as a rule of thumb, the endpoints that modify statuses (like CONSUME), or perform actions (like PLAY, or CLEAR) should use the POST verb, not GET - which is instead valid for all the endpoints that just return information, without modifying/executing anything (like LSPLAYLISTS => available playlists, or VOLUME => current volume level).

Thank you, Nutul.  Your feedback is helpful.  Changing to POST is easy enough.  I've updated the pdf to reflect the change and everything tested just fine.  Anything that changed the state of Moode was changed to POST.  If you have any more observations, please share, especially anything useful that's missing.

For background, I'm going to use Moode Multiroom playing as a component of my home security strategy.  When I'm away, Home Assistant will be scheduling playlists to change up the music using various genre's, volumes and room selections.  Muting the source when the video doorbell is rung, answering remotely and resuming should also be effective.  I believe it's not just enough to have your home look like you're present.  It should also sound like you're there "enjoying the music."
Reply
#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


Forum Jump: