Thank you for your donation!


Problem: how do I know what moode is doing?
#1
Lightbulb 
Dear all

I am enjoying moode a lot - now I want to go a step further and get the system more integrated into my home automation.

I am looking to a neat way to know at any point in time what moode audio is doing, i.e.
  • idle: MPD/airplay/spotify/etc mode with status "stop"
  • play: as above, but with the status "play"
Now, in case of MPD is active, I just need to send a GET request to http://moode/engine-mpd.php and parse the JSON output, e.g.

Quote:State: play
Volume: 0
File: http://psn1.prostreaming.net:8095/stream

However, I cannot figure out how to obtain a similar output when I stream through Airplay or Spotify. While I am aware of the limited information when using the other streaming options. I would love to have at least

Quote:State: play (possible?)
Volume: 0
File: http://psn1.prostreaming.net:8095/stream

I think there is http://moode/audioinfo.php providing some of the information but it is not JSON compatible, so I will need different parsing strategies depending from the service (doable but not preferred Dodgy )

Any other suggestion or could you point me to some docs?

DISCLAIMER: I am not a web programmer, I am sure that interactions done through http://moode/ could be done with GET/POST requests, but how?

Thanks
Max
Reply
#2
You could try the command API.
https://github.com/moode-player/moode/bl.../setup.txt

To get output from commands you will need to uncomment the statement //echo $result; in file /var/www/command/index.php. See below.

Code:
// MPD commands
else {
    if (false === ($sock = openMpdSock('localhost', 6600))) {
        $msg = 'command/index: Connection to MPD failed';
        workerLog($msg);
        exit($msg . "\n");
    }
    else {
        sendMpdCmd($sock, $_GET['cmd']);
        $result = readMpdResp($sock);
        closeMpdSock($sock);
        //echo $result;
    }
Reply
#3
(03-27-2021, 10:18 PM)Tim Curtis Wrote: You could try the command API.
https://github.com/moode-player/moode/bl.../setup.txt

To get output from commands you will need to uncomment the statement //echo $result; in file /var/www/command/index.php. See below.

Code:
// MPD commands
else {
    if (false === ($sock = openMpdSock('localhost', 6600))) {
        $msg = 'command/index: Connection to MPD failed';
        workerLog($msg);
        exit($msg . "\n");
    }
    else {
        sendMpdCmd($sock, $_GET['cmd']);
        $result = readMpdResp($sock);
        closeMpdSock($sock);
        //echo $result;
    }

Thanks @Tim Curtis , I will try it.

Max
Reply
#4
Hi didomax

I have a program that needs to determine play/pause/stop state. I use the /var/local/www/currentsong.txt file (enable the Moode metadata file in the UI) with the following logic

   https://github.com/antiprism/mpd_oled/bl...s.cpp#L353

If the file doesn't contain "title=something" then a non-MPD player is being used and the state is 'play',
otherwise, if the file includes "state=stop" then the state is 'stop',
otherwise the state is 'play'.

[Seems like there is no longer any detection of 'pause', whatever 'pause' means...]

Adrian.
Reply
#5
Hi didomax

Correction: the state will have been previous read from MPD first, and may be 'pause', and so will only be finally be set to 'play' if MPD does not report a status.

Clarification: for the non-MPD players the actual play state is unknown and is simply set to play.

Adrian.
Reply
#6
(03-28-2021, 10:19 AM)adrii Wrote: Hi didomax

Correction: the state will have been previous read from MPD first, and may be 'pause', and so will only be finally be set to 'play' if MPD does not report a status.

Clarification: for the non-MPD players the actual play state is unknown and is simply set to play.

Adrian.

Hi @adrii

Thanks a lot, this goes exactly in the right direction!

The only missing step is the availability of such file through a GET call: does anybody know if there is a way to make these data available through the command API?

Thanks
Max
Reply
#7
(03-28-2021, 07:07 PM)didomax Wrote:
(03-28-2021, 10:19 AM)adrii Wrote: Hi didomax

Correction: the state will have been previous read from MPD first, and may be 'pause', and so will only be finally be set to 'play' if MPD does not report a status.

Clarification: for the non-MPD players the actual play state is unknown and is simply set to play.

Adrian.

Hi @adrii

Thanks a lot, this goes exactly in the right direction!

The only missing step is the availability of such file through a GET call: does anybody know if there is a way to make these data available through the command API?

Thanks
Max

Well, if you want to try a "heat it and beat it" approach (a phrase I learned from a master welder), just create a symlink to make /var/local/www/currentsong.txt visible to the nginx server. Let's abuse the fact that it can serve up imagery for coverart

Code:
sudo ln -s /var/local/www/currentsong.txt /var/local/www/imagesw/currentsong.txt

Now point your code to

Code:
http://moode.local/imagesw/currentsong.txt

Assuming you've enabled moOde's Metadata file setting under m>Sys config>Local services, you'll see the last written content.

Here, for example, is what is displayed in my web browser while a track is streaming from another moOde player's DLNA server (in this case with BubbleUPnP on my phone as the UPnP control point).

Code:
file=http://192.168.4.26:8200/MediaItems/8321.flac
artist=Miles Davis & Quincy Jones
album=Miles & Quincy Live at Montreux
title=Boblicity
coverurl=
track=2
date=1993
composer=
encoded=VBR
bitrate=758 kbps
outrate=16 bit, 44.1 kHz, Stereo, 1.411 Mbps
volume=57
mute=0
state=play

Regards,
Kent
Reply
#8
(03-28-2021, 07:51 PM)TheOldPresbyope Wrote:
(03-28-2021, 07:07 PM)didomax Wrote:
(03-28-2021, 10:19 AM)adrii Wrote: Hi didomax

Correction: the state will have been previous read from MPD first, and may be 'pause', and so will only be finally be set to 'play' if MPD does not report a status.

Clarification: for the non-MPD players the actual play state is unknown and is simply set to play.

Adrian.

Hi @adrii

Thanks a lot, this goes exactly in the right direction!

The only missing step is the availability of such file through a GET call: does anybody know if there is a way to make these data available through the command API?

Thanks
Max

Well, if you want to try a "heat it and beat it" approach (a phrase I learned from a master welder), just create a symlink to make /var/local/www/currentsong.txt visible to the nginx server. Let's abuse the fact that it can serve up imagery for coverart

Code:
sudo ln -s /var/local/www/currentsong.txt /var/local/www/imagesw/currentsong.txt

Now point your code to

Code:
http://moode.local/imagesw/currentsong.txt

Assuming you've enabled moOde's Metadata file setting under m>Sys config>Local services, you'll see the last written content.

Here, for example, is what is displayed in my web browser while a track is streaming from another moOde player's DLNA server (in this case with BubbleUPnP on my phone as the UPnP control point).

Code:
file=http://192.168.4.26:8200/MediaItems/8321.flac
artist=Miles Davis & Quincy Jones
album=Miles & Quincy Live at Montreux
title=Boblicity
coverurl=
track=2
date=1993
composer=
encoded=VBR
bitrate=758 kbps
outrate=16 bit, 44.1 kHz, Stereo, 1.411 Mbps
volume=57
mute=0
state=play

Regards,
Kent

Kent, 

This is great! I am going to try this asap. 

The output format is not my preferred (JSON would rock  Tongue ), but it looks the whole process is doable, with no big mods of the base Moode system (important whenever I will need to restore the system from a HW failure  Smile ).

I will post the results once available.

Max
Reply


Forum Jump: