Thank you for your donation!


Direct link to radiostation
#11
Not wishing to add a new work item to Tim's inexhaustible ToDo list [1], here's another client-side hint.

The MPD command protocol includes a command_list_begin/command_list_end construction. To quote from the protocol specification


Quote:To facilitate faster adding of files etc. you can pass a list of commands all at once using a command list. The command list begins with command_list_begin or command_list_ok_begin and ends with command_list_end.

It does not execute any commands until the list has ended. The response is a concatenation of all individual responses. On success for all commands, OK is returned. If a command fails, no more commands are executed and the appropriate ACK error is returned. If command_list_ok_begin is used, list_OK is returned for each successful command executed in the command list.



Based on that, here's a URL-encoded HTTP GET request for the moOde player hostname "moode" which when entered in my browser clears the player queue, loads the "Favorites" playlist into the queue, and starts playing the first playlist entry [2] in one fell swoop. Please note that this request is entered as a single line despite how it may be displayed when you read this post.

Code:
http://moode/command/?cmd=command_list_begin%0D%0Aclear%0D%0Aload%20Favorites%0D%0Aplay%200%0D%0Acommand_list_end

The string "%0D%0A" is the URL-encoding for CRLF, %20 is the URL-encoding for ASCII space, so this GET request is the equivalent of

Code:
command_list_begin
clear
load Favorites
play 0
command_list_end

There's no fancy error handling here (e.g., the ACK error messages spoken of in the quote are ignored). 

The first command stops whatever is playing and clears the queue. If the named playlist doesn't exist, that's the end of the story. If the playlist exists, it's loaded. Then, if the specified playlist entry doesn't exist the player remains stopped.

Obviously @DRONE7's proposal can be effected using this same command_list construction.

Regards,
Kent

[1] adding a new endpoint to the API entails a fair amount of work which has to be planned, documented, executed, and tested. Defining the requirements is key. Feature creep is like kudzu and must be guarded against.

[2] I forgot in my post yesterday that playlists begin at entry 0 not 1. Classic programmer mistake.
Reply
#12
(01-08-2020, 05:56 AM)smolesen Wrote:
(01-06-2020, 01:31 PM)Tim Curtis Wrote: MPD commands can be sent via

Code:
http://moode/command?cmd=

Example:

http://moode/command?cmd=stop

Volume commands via

Code:
http://moode/command?cmd=vol.sh

pi@rp3:~ $ /var/www/vol.sh --help
Usage: vol.sh [OPTION] [VOLUME]
Change the volume and update the knob.

With no OPTION or VOLUME, print the current volume.
With just VOLUME, set current volume to VOLUME.

 -up            VOLUME  value between 1 and 100
 -dn            VOLUME  value between 1 and 100
 -mute          mute or unmute the volume
 -restore       set volume to current knob level
 --version      print the program version
 --help         print this help text

Examples:

http://moode/command?cmd=vol.sh -up 1
http://moode/command?cmd=vol.sh -dn 1
http://moode/command?cmd=vol.sh 15
http://moode/command?cmd=vol.sh -mute

Yes, it's something like that I'm looking for, something in the line of:

http://mymoode/command?cmd=playradio -station 'somefolder/somestation.pls'

can that be done?

/Søren

Probably, but there would need to be more demand for such a feature. Keep in mind that features that make it to the TODO list compete with one another for developer time and they compete with bug fixes and updates.

-Tim
Reply
#13
Thanks @TheOldPresbyope  for the enlightenment !

Yes, works fine....

Code:
http://<moode-ip-address>/command/?cmd=command_list_begin%0D%0Aclear%0D%0Aadd%20http://relay3.slayradio.org:8000/%0D%0Aplay%200%0D%0Acommand_list_end


@smolesen    could that be an answer for your 'direct link' ?
Reply
#14
(01-08-2020, 10:07 PM)DRONE7 Wrote: Thanks @TheOldPresbyope  for the enlightenment !

Yes, works fine....

Code:
http://<moode-ip-address>/command/?cmd=command_list_begin%0D%0Aclear%0D%0Aadd%20http://relay3.slayradio.org:8000/%0D%0Aplay%200%0D%0Acommand_list_end


@smolesen    could that be an answer for your 'direct link' ?
Should be trivial to add an option 'save shortcut' to generate a Windows style shortcut file along with the add to playlist options.  Or generate the url for copying and pasting.
Pi 3B + Allo MiniBoss DAC / Pro-ject Elemental / Marantz CD6004 / Marantz PM6004 / Monitor Audio Bronze 2
Reply
#15
(01-08-2020, 10:07 PM)DRONE7 Wrote: Thanks @TheOldPresbyope  for the enlightenment !

Yes, works fine....

Code:
http://<moode-ip-address>/command/?cmd=command_list_begin%0D%0Aclear%0D%0Aadd%20http://relay3.slayradio.org:8000/%0D%0Aplay%200%0D%0Acommand_list_end


@smolesen    could that be an answer for your 'direct link' ?

Yes, that would definitely work for me. sorry if I didn't explain properly what I was looking for in the first place...

Thanks for all the help...

/Søren
Reply
#16
I'm not sure that's what the OP is requesting.

I would think that they want to play a station already in moode without knowing the station URL and without having to use the Moode UI.

Something like

http://moode.ip/play?radiopreset

I think that's what is being requested. I think what is being provided is a "Chromecast" solution where you can send any radio URL to moode.

I think the feature would need to be more user friendly than even a preset name ... even say if the stations in Moode had an index number ... Play preset 142 (like a real radio, or at least you know your station is tuned at 88.2MHZ on FM).

http://moode.ip/play?ch142

Something like that could enable IoT integration much easier and lead to a TV style browser, where each station could have expanded meta data like genres or tagline.

It would have to have the preset stations showing their database index key in the UI so that the user knew that SomaFM Groove Salad was channel 153 for example or a new key in the database for "channel number".

Going that route Moode would have a real old timey dial system where stations were known by "a place on the dial". That would deffo be super cool.

The scripts I'm working on do what we think the OP is asking, or can be changed to do this. I'll have an index file that can handle it as &type=cast. This means you must know the URL of the station. Not having to know the URL of the station would be very cool.

The half way solution ... As "a cast audio to moode" this could be built into a browser extension (like what Volumio is doing with YouTube).

Like moode.ip/radio?type=cast&src=http://radioip/play.mp3

This casting feature could save each casted URL into a playlist so you could go back and find a station you casted last week. The users not requesting this though, just a shortcut to play a station already in moode.

https://github.com/duracell80/MoodeRadio.../index.php
--

GitHub, Spotify and Resonate : @duracell80

My jam: ambient, lush vocals, synths and acoustic guitars
Reply
#17
@duracell80

I think you misunderstand the point of my post.

I was merely showing how a comparable effect could be achieved with no change to moOde.

Your focus on making moOde a radio player sui generis is admirable and I'm following the work closely, but look how much time you've put into it already. That's what happens to Tim every time someone throws a demand for a new capability over the fence. 

We know that almost anything can be done in software if one puts one's mind to it, but "design, implement, test, support" is a demanding work cycle.

I stand by my solution as an easy win.

Regards,
Kent
Reply
#18
(01-20-2020, 01:34 PM)TheOldPresbyope Wrote: @duracell80

I think you misunderstand the point of my post.

I was merely showing how a comparable effect could be achieved with no change to moOde.

Your focus on making moOde a radio player sui generis is admirable and I'm following the work closely, but look how much time you've put into it already. That's what happens to Tim every time someone throws a demand for a new capability over the fence. 

We know that almost anything can be done in software if one puts one's mind to it, but "design, implement, test, support" is a demanding work cycle.

I stand by my solution as an easy win.

Regards,
Kent

Totally agree, the solution does work if you know the URL and if the URL hasn't changed. But we know IPTV doesn't work this way and traditional digital TV doesn't either, they work by channel index. Once a station is in the system you don't usually change channels by having to find a URL. I think this solution does provide a way to produce URL shortcut icons on the users Windows desktop to double click an icon to play the station in Moode. I think the users request is a bit ambiguous, like not requesting a whole operating system, just a shortcut on the desktop on their existing operating system (which launches a browser). I get it.

I have found developing to need full stack knowledge, it has been fun to go back to full stack.

I'm working on these exact issues anyway so can contribute starters. This was done in less than an hour. It's kinda interesting too that as someone thinks of an approach, I'm pretty close already. Turns out not to be too bad and can be added to the API.

   

What the user asked for is genius and totally inline with headless!! Here's how to make a direct link in Windows ...

   

Let me write it up in the How To based on the current API call that's already there in Moode for users right now.

Code:
case "moode":
       // LOOK UP MOODE STATION IN DB BY ID
       if ($ch) {
           $m3u_content    = "#EXTM3U\n";
           $stationfound   = 0;
           $db             = new SQLite3('/var/local/www/db/moode-sqlite3.db');
           $results        = $db->query('SELECT station,name FROM cfg_radio WHERE id =' . $ch);
           
           while ($row = $results->fetchArray()) {
               
               // Build the file
               $m3u_content .= "#EXTINF:-1," . $row['name'] . "\n";
               $m3u_content .= $row['station'];
               $stationfound = 1;
           }
       }
       
       
       
       
       // SEND BROWSER TO PLAYER OR NOT IF IoT THEN ECHO COMMAND
       if($stationfound == 1){
           // PLAY IT AGAIN SAM ...
           shell_exec("sudo touch /var/lib/mpd/playlists/Radio_Play.m3u");
           shell_exec("sudo chmod 777 /var/lib/mpd/playlists/Radio_Play.m3u");
           file_put_contents($radioList, $m3u_content);

           $runcmd = "mpc clear; mpc load Radio_Play"; shell_exec($runcmd);
           $runcmd = "mpc play";
           
           echo(shell_exec($runcmd));
           //header("Location: /");    
       } else {
           echo("Error: Station ID Not Found");
       }
       break;

https://github.com/duracell80/MoodeRadio.../index.php
--

GitHub, Spotify and Resonate : @duracell80

My jam: ambient, lush vocals, synths and acoustic guitars
Reply


Forum Jump: