Thank you for your donation!


Idea: Extend URL API to clear / load / play a playlist
#1
I don’t think this is implemented currently, but I think it would be really useful to have a “play playlist x” URL. You can do volume and stop via URLs, but not play. 

My use case is unusual, but might extend to others’ uses.

I only listen to AirPlay or one of two radio stations for 99% of the time. I have 4 physical control buttons on a “remote” Pi which is used to control Moode.

Vol Up press: http request
Vol Down press: http request
Radio 4: ssh connection made to issue the clear / load / play command for playlist “radio4”
Radio 2: ssh connection made to issue the clear / load / play command for playlist “radio2”

So I’m thinking a .sh script to take the argument passed via the URL and run the mpc commands. Just like the vol.sh.

What do you reckon?
Reply
#2
(02-06-2019, 04:22 PM)tristanc Wrote: I don’t think this is implemented currently, but I think it would be really useful to have a “play playlist x” URL. You can do volume and stop via URLs, but not play. 

My use case is unusual, but might extend to others’ uses.

I only listen to AirPlay or one of two radio stations for 99% of the time. I have 4 physical control buttons on a “remote” Pi which is used to control Moode.

Vol Up press: http request
Vol Down press: http request
Radio 4: ssh connection made to issue the clear / load / play command for playlist “radio4”
Radio 2: ssh connection made to issue the clear / load / play command for playlist “radio2”

So I’m thinking a .sh script to take the argument passed via the URL and run the mpc commands. Just like the vol.sh.

What do you reckon?

@tristanc

I reckon you should just do it. Smile

As you surmise, the basic machinery is there. 

Like vol.sh, you could create a /var/www/playitagainsam.sh script with appropriate options and invoke it via http://moode/command?cmd=playitagainsam.sh with appropriate parameters. (See Tim's recent reply to another poster http://moodeaudio.org/forum/showthread.p...98#pid7698

You'll likely have to reinstall the script after a moOde update.

Regards,
Kent
Reply
#3
(02-06-2019, 05:17 PM)TheOldPresbyope Wrote: I reckon you should just do it. Smile

As you surmise, the basic machinery is there.

Yep, easy as pi. A quick edit of vol.sh did it. Thanks!

T
Reply
#4
(02-06-2019, 05:17 PM)TheOldPresbyope Wrote: As you surmise, the basic machinery is there. 

Like vol.sh, you could create a /var/www/playitagainsam.sh script with appropriate options and invoke it via http://moode/command?cmd=playitagainsam.sh with appropriate parameters. (See Tim's recent reply to another poster http://moodeaudio.org/forum/showthread.p...98#pid7698

You'll likely have to reinstall the script after a moOde update.

Just in case anyone needs this in the future - in v6 custom scripts can't be called via the URL like the above. You need to modify /var/www/command/index.php to include another elsif section to match the name of your script file.

My version below:
PHP Code:
<?php
/**
 * moOde audio player (C) 2014 Tim Curtis
 * http://moodeaudio.org
 *
 * tsunamp player ui (C) 2013 Andrea Coiutti & Simone De Gregori
 * http://www.tsunamp.com
 *
 * This Program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * This Program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * 2019-08-08 TC moOde 6.0.0
 *
 */

require_once dirname(__FILE__) . '/../inc/playerlib.php';

playerSession('open''' ,'');
session_write_close();

if (isset(
$_GET['cmd']) && empty($_GET['cmd'])) {
    echo 
'Command missing';
}
// SH or PHP commands
elseif (stripos($_GET['cmd'], '.sh') !== false || stripos($_GET['cmd'], '.php') !== false) {
    
// check for valid chrs
 
   if (preg_match('/^[A-Za-z0-9 _.-]+$/'$_GET['cmd'])) {
        
// reject directory traversal ../
        
if (substr_count($_GET['cmd'], '.') > 1) {
            echo 
'Invalid string';
        }
        
// check for valid commands
 
       elseif (stripos($_GET['cmd'], 'vol.sh') !== false) {
 
          $result sysCmd('/var/www/' $_GET['cmd']);
 
          echo $result[0];
 
       }
 
       elseif (stripos($_GET['cmd'], 'playitagainsam.sh') !== false) {
 
          $result sysCmd('/var/www/' $_GET['cmd']);
 
          echo $result[0];
 
       }
 
       else {
 
           echo 'Unknown command';
 
       }
 
   }
 
   else {
 
       echo 'Invalid string';
 
   }
}
// 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
#5
Hi tristanc,
Thanks for the info, I was looking why my home-made scripts were not working when calling them through API with moode v6.x, you saved me!
Reply


Forum Jump: