Inutile d'utiliser ffprobe parce que MPV donne directement le titre... suffit de récupérer le résultat
Cette version utilise un slide pour régler le volume, le volume ne peut être changé en direct mais spécifie un volume du lecteur indépendamment du volume générale. Il faut stopper la lecture et relancer le titre pour prendre en compte un changement du volume.
Dans cette version j'utilise un fichier "art_def.jpg" pour une image par défaut si la pochette n'existe pas. A vous de mettre ce fichier image dans le dossier.
############
Hello
Il existe de nombreux programmes avec nos puppy's pour écouter des radios en ligne mais je n'en ai pas trouvé qui affichent le titre en cours de lecture et la pochette de l'album ou du disque. Alors après qq recherches je me suis demandé si je pouvais faire quelque chose par moi même.
Et en effet, les composants nécessaires sont présents, c'est à dire ffprobe pour extraire le titre joué et wget pour prendre la pochette sur le web (après une recherche automatisée) J'utilise MPV pour la lecture audio, vu qu'il est également dispo par défaut.
Alors voilà, si vous êtes curieux je partage mon petit programme, à améliorer mais il est tout à fait fonctionnel !
Une capture du résultat :
Le programme :
Code: Select all
#!/bin/sh
# Nice Radio Player v.03 / 27 AVRIL 2020 / Fabrice_035
#
# just trying to find the cover,
# add your favorites radio with this program or edit radio.txt file
#
# New version, no need ffprob, much simpler pipe with MPV
# Clean before start ##################
echo "" > pid.radio.txt
rm -f api.txt
echo "Select Radio and Play >" > bar.txt
##########################
cp -f art_def.jpg art.jpg
# play radio with mpv player
JOBCREATE(){
killpid=$(cat pid.radio.txt)
if [ "$killpid" != "" ] ; then
kill -9 "$killpid"
echo "" > pid.radio.txt
exit 0
fi
mpv --volume "$volume" "$BOX" > /dev/null 2>&1 >title.txt &
P1=$!
echo $P1 > pid.radio.txt
}
export -f JOBCREATE
# get icy-title with ffbrobe and download picture (wget)
getpicture(){
radio="$BOX"
titre=$(cat title.txt | grep -a "icy-title" | tail -1 | awk -F":" '{print $2}')
kr=$(cat pid.radio.txt)
if [ "$kr" != "" ] ; then
echo "[Play] $titre" > bar.txt
else
echo "[Stop] $titre" > bar.txt
fi
search=$(echo $titre | tr '"' ' ' | tr ' ' '+')
old=$(cat titre.txt)
verif=${#search}
echo "$verif"
min="3"
echo "$search" > titre.txt
if (("$verif" < "$min")) ; then
echo " trop petit "
cp -f art_def.jpg art.jpg
exit 0
fi
echo "$old $search"
if [ "$old" != "$search" ] ; then
echo "$old ? $search"
download
fi
exit 0
}
export -f getpicture
# search and download picture
download() {
search=`cat titre.txt`
rm -f api.txt
wget "https://api.discogs.com/artists/1?callback="$search -O api.txt > /dev/null 2>&1
rm -f out.txt
wget "https://www.discogs.com/fr/search/?q=$search&type=all" -O out.txt > /dev/null 2>&1
img=`grep /discogs-images/ out.txt | tail -n +1 |head -1`
lien=`echo $img | awk -F '"' '{print $2}'`
wget -q -O - $lien > art.jpg
return 0
}
export -f download
GTKDIALOG=gtkdialog
MAIN_DIALOG='
<window title="Nice Radio Player" icon_name="gtk-media-play">
<vbox>
<hbox>
<frame>
<pixmap>
<variable>PIXMAP</variable>
<input file>art.jpg</input>
<action>getpicture</action>
</pixmap>
</frame>
</hbox>
<hbox space-expand="true" space-fill="true">
<button>
<input file stock="gtk-delete" tooltip-text="delete entry"></input>
<action>removeselected:BOX</action>
<action>save:BOX</action>
<action>refresh:BOX</action>
</button>
<comboboxentry has-focus="true" tooltip-text="add favorite radio, press enter" >
<variable>BOX</variable>
<default>Select Radio</default>
<input file>radio.txt</input>
<output file>radio.txt</output>
<action signal="activate">save:BOX</action>
<action signal="activate">refresh:BOX</action>
<action>JOBCREATE</action>
</comboboxentry>
<button tooltip-text="Play/Stop">
<input file stock="gtk-media-next"></input>
<action>JOBCREATE</action>
<action>refresh:LOG</action>
<action>clear:SOURCE</action>
</button>
</hbox>
<hbox>
<hscale xalign="0" width="100" value-pos="1" space-expand="true" space-fill="true" height-request="30" range-value="50">
<variable>volume</variable>
<action>set_volume '"$VLMCH"' "$volume"</action>
</hscale>
</hbox>
<statusbar space-expand="true" space-fill="true" use-markup="true" has-resize-grip="false" auto-refresh="true">
<variable>stb0</variable>
<input file>bar.txt</input>
</statusbar>
</vbox>
<timer visible="true" interval="4">
<action>getpicture&</action>
<action>refresh:PIXMAP</action>
</timer>
</window>
'
export MAIN_DIALOG
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
# kill mpv pid !
kr=$(cat pid.radio.txt)
if [ "$kr" != "" ] ; then
kill -9 "$kr"
fi
# clean and exit , force to wait last process
rm -f art.jpg
rm -f pid.radio.txt
rm -f titre.txt
rm -f bar.txt
rm -f out.txt
rm -f title.txt