Moode Forum
Receive is Webradio playing - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (https://moodeaudio.org/forum/forumdisplay.php?fid=7)
+--- Thread: Receive is Webradio playing (/showthread.php?tid=339)



Receive is Webradio playing - mezcal - 07-22-2018

Hi all,

I have succesfully set up Apple remote to control moode. This remote has one button for play/stop. I use commad mpc toggle.
It works fine but for webradios is better stop then pause as GUI does. My approach is:
Code:
http=$(echo -e "currentsong\nclose" | nc localhost 6600 | grep file: | sed 's/file: //' | cut -c -4)
status=$(echo -e "status\nclose" | nc localhost 6600 | grep state: | sed 's/state: //')
if [ "$http" == 'http' ] && [ "$status" == 'play' ]; then # radio
    mpc stop
else
    mpc toggle
fi
If the filename of a playing track starts with 'http' it is webradio. I am affraid it can catch tidal. For tidal is pause better then stop.

Is any way how to execute GUI commands. Something like:
Code:
curl "http://127.0.0.1/commands.php/?cmd=play"



RE: Receive is Webradio playing - TheOldPresbyope - 07-22-2018

(07-22-2018, 06:12 AM)mezcal Wrote: Hi all,

I have succesfully set up Apple remote to control moode. This remote has one button for play/stop. I use commad mpc toggle.
It works fine but for webradios is better stop then pause as GUI does. My approach is:
Code:
http=$(echo -e "currentsong\nclose" | nc localhost 6600 | grep file: | sed 's/file: //' | cut -c -4)
status=$(echo -e "status\nclose" | nc localhost 6600 | grep state: | sed 's/state: //')
if [ "$http" == 'http' ] && [ "$status" == 'play' ]; then # radio
    mpc stop
else
    mpc toggle
fi
If the filename of a playing track starts with 'http' it is webradio. I am affraid it can catch tidal. For tidal is pause better then stop.

Is any way how to execute GUI commands. Something like:
Code:
curl "http://127.0.0.1/commands.php/?cmd=play"

@mezcal 

Interesting approach.

First, props for using netcat Smile 

Second, perhaps I'm misunderstanding your request, but it looks like the logic you seek isn't handled in php but in javascript. Have a look at js/scripts-panels.js where moOde decides what to do with Play/Pause clicks. Once it's decided, it uses the function sendMpdCmd() to invoke the commands you already know.

Tim's the Guru on this. I just bird-walk through his code from time to time.

Regards,
Kent


RE: Receive is Webradio playing - Tim Curtis - 07-22-2018

Bird Walk ;-)
https://www.youtube.com/watch?v=L81maEBjvgc

There are two WebAPI's for moOde

1. MPD command API
http://moode/command?cmd=play
http://moode/command?cmd=pause

2. Volume API
http://moode/command?cmd=vol.sh 10

Here is the help for vol.sh
pi@rp3:~ $ /var/www/vol.sh -help
vol.sh with no arguments will print the current volume level
vol.sh restore will set alsa/mpd volume based on current knob setting
vol.sh <level between 0-100>, mute (toggle), up <step> or dn <step>, -help

-Tim


RE: Receive is Webradio playing - TheOldPresbyope - 07-22-2018

(07-22-2018, 05:46 PM)Tim Curtis Wrote: Bird Walk ;-)
https://www.youtube.com/watch?v=L81maEBjvgc

Now THAT's what I'm talkin' about!

Quote:There are two WebAPI's for moOde

I got the impression @mezcal needed context-sensitive control. It wouldn't be the first time I was wrong.

Regards,
Kent


RE: Receive is Webradio playing - Tim Curtis - 07-22-2018

I think u might be right. You can get output from any MPD command via the Web command API. You can use curl and localhost on the Pi or you can run from a client Web Browser via http://hostname/command?cmd=

For example:

Code:
pi@rp3:~ $ curl http://localhost/command/?cmd=currentsong
file: http://aac-64.streamthejazzgroove.com:80/stream
Title: Danilo Pérez - If I Forget You
Name: TheJazzGroove.com - East Channel
Pos: 4
Id: 5

pi@rp3:~ $ curl http://localhost/command/?cmd=status
volume: 20
repeat: 0
random: 0
single: 0
consume: 0
playlist: 113
playlistlength: 97
mixrampdb: 0.000000
state: play
song: 4
songid: 5
time: 4109:0
elapsed: 4108.840
bitrate: 56
audio: 44100:16:2
nextsong: 5
nextsongid: 6
pi@rp3:~ $
-Tim


RE: Receive is Webradio playing - mezcal - 07-22-2018

I am newbie to moodeaudio and mpd.
I have been going through source code.

play/pause button is defined in js/scripts-panels.js:
Code:
if (MPD.json['file'].substr(0, 4).toLowerCase() == 'http') {
    var cmd = MPD.json['artist'] == 'Radio station' ? 'stop' : 'pause'; // pause if for upnp url
}
else {
   var cmd = 'pause'; // song file
}
Only radio needs stop.
I have found in inc/playerlib.php division of formats:
Code:
// radio station
if (isset($song['Name']) || (substr($song['file'], 0, 4) == 'http' && !isset($song['Artist']))) {
        
}
// UPnP file
elseif (substr($song['file'], 0, 4) == 'http' && isset($song['Artist'])) {

}
// DSD file
elseif (getFileExt($song['file']) == 'dsf' || getFileExt($song['file']) == 'dff') {

}
// file
else {

Artist 'Radio station' is adding in command/worker.php
Code:
if (isset($song['Name']) || (substr($song['file'], 0, 4) == 'http' && !isset($song['Artist']))) {
    $artist = 'Radio station';

The condition above should be used for webradio. I will try write it in bash.
I think js test for http is case insensitive and php tests are case sensitive.