Thank you for your donation!


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


[Moode 6.4.2] Report result of mpc commands to local UI
#4
Smile 
I create another script for adding current song to a playlist with a remote.
I have a Samsung BN59 like remote with numeric touch from 0 to 9 and I use it to launch playlist (named playlist0 to playlist9).
So when touch the 5 button for example, it clear, add and play the playlist 5. I wanted to be able to add a listen song to a specific playlist. It's the purpose of that script which do :
- verify that a number is passed as parameter (playlist to update)
- verify if the playlist file exist and create if necessary
- search the file name of the current song in the currentsong.txt file
- verify if thjat file isn't already store in that playlist
- add the current file playing at the end of the playlist
Code:
#!/bin/bash
CurrentFile=/var/local/www/currentsong.txt
PlayList=/var/lib/mpd/playlists/playlist
#  verif argument number playlist passed
if [ -n "$1" ]  
then
 fileout=$PlayList$1".m3u"
 # verif if playlist file exists
 if [ ! -f $fileout ];then
    # file doesn't exist => created empty
     touch $fileout
 fi
 #  read currentsong.txt to retrieve the current file playing
 while read -r ligne
 do       
   if  [ ${ligne:0:5}=='file=' ]
   then
     file=${ligne:5}
     # read the playlist file to see if the song file is already stored in the playlist
     while read -r ligne_pl
     do      
       if [ "$ligne_pl" = "$file" ]
         then
           # already stored => nothing to do        
           exit 0;
       fi
     done < $fileout
     # current file not found in the playlist
     # add current file at the end of the playlist and exit
     echo $file  >> $fileout    
     exit 0
   fi      
 done < $CurrentFile
else
 echo "Usage: `basename $0` [num_playlist]"  
fi
exit 0

The script is affected  to a combination of 2 buttons on my remote control (for me PRE-CH + Numeric button corresponding to the playlist choosen).

my irexec file for updating the playlist 5 as example :
Code:
begin
prog = irexec
button = KEY_P
button = KEY_5
config = sudo /home/pi/scripts/CurrenttoPlaylist.sh 5
repeat = 0
flags = quit
end



and to load the playlist (that part must be after the previous one as the KEY_5 is in case in the 2 parts) :

Code:
begin
prog = irexec
button = KEY_5
config = mpc clear; mpc load playlist5; mpc play
repeat = 0
flags = quit
end


 
May be it can help someone Smile
Enjoy Cool
Reply


Messages In This Thread
RE: [Moode 6.4.2] Report result of mpc commands to local UI - by zebons - 03-02-2020, 04:53 PM

Forum Jump: