Alors j'ai réussi à résoudre mon problème, en pompant à droite à gauche ( doc ubuntu surtout ) et en faisant aussi un peu fonctionner
mes méninges,
je poste du coup le resultat, même si je pense que sa peut facilement être amélioré ( le shell n'est pas ma langue maternelle :-D ) :
~/.conky/rhythmbox
#!/bin/bash
case "$1" in
# Now Playing Info
artist) rhythmbox-client --no-start --print-playing-format "%aa";;
title) rhythmbox-client --no-start --print-playing-format "%tt";;
album) rhythmbox-client --no-start --print-playing-format "%at";;
courant)rhythmbox-client --no-start --print-playing-format "%te/%td";;
progress)
curr=`rhythmbox-client --no-start --print-playing-format "%te" | grep -v "Pas de lecture en cours"`
tot=`rhythmbox-client --no-start --print-playing-format "%td" | grep -v "Pas de lecture en cours" | grep -v Inconnu`
a=`date +'%S' | sed 's/^0\+//'`
if [ "$a" = "" ]; then
a=0
fi
b=$(( ($a*100) / 30 ))
c=$(( 200-$b ))
#si pas de durée totale, augmente pendant les 30 premieres secondes puis diminu pendant les 30 suivantes...
if [ "$tot" = "" ]; then
if [ $a -le 30 ]; then
expr $b
else
expr $c
fi
else
#Si durée totale déterminée, il faut traiter le retour de la commande donnant $curr (pour courant et $tot pour total, logique) qui renvoit une donné sous la forme hh:mm:ss
d="1"
nbcurr=`echo $curr | wc -m` #nbr de caractères permet de déterminer si il y a seulement m:ss ou si il y a h:mm:ss (au minimum, m:ss)
posm=$(( $nbcurr-5 )) #pour faire une commande cut générique, il faut définir l'endroit ou on coupe d'ou posx (position des minutes ici)
if [ $posm -lt $d ]; then
posm=`` #Si position inférieur à 1, renvoit variable vide pour ne pas bloque cut
fi
posm2=$(( $nbcurr-4 )) #Forcément 1 indication minute (minimum)= pas besoin de vérifier si >1
posh=$(( $nbcurr-8 )) #Idem pour les heures
if [ $posh -lt $d ]; then
posh=``
fi
posh2=$(( $nbcurr-7 ))
currs=`echo $curr | tail -c3 | sed 's/^0\+//'` # Récupération des secondes forcément à la fin et supression du premier 0 pour ne pas avoir de problème de base (08 en hexa ou base 10)
if [ "$currs" = "" ]; then
currs=0 #si uniquement des zeros, ils sont tous supprimé donc redonner la valeur
fi
currma=`echo $curr | cut -c$posm-$posm2 | sed 's/^0\+//'`
if [ "$currma" = "" ]; then
currma=0 #idem pour minutes
fi
currm=$(( $currma*60 )) #conversion en secondes
if [ $posh2 -lt $d ]; then
currh=0
else
currha=`echo $curr | cut -c$posh-$posh2 | sed 's/^0\+//'`
if [ "$currha" = "" ]; then #idem heures
currha=0
fi
currh=$(( $currha*3600 )) # conversion en secondes
fi
currt=$(( ($currh+$currm) + $currs )) #calcule du nombre de secondes total
nbtot=`echo $tot | wc -m` #Même schema pour la suite mais avec la durée totale
tposm=$(( $nbtot-5 ))
if [ $tposm -lt $d ]; then
tposm=``
fi
tposm2=$(( $nbtot-4 ))
tposh=$(( $nbtot-8 ))
if [ $tposh -lt $d ]; then
tposh=``
fi
tposh2=$(( $nbtot-7 ))
tots=`echo $tot | tail -c3 | sed 's/^0\+//'` ## OK
if [ "$tots" = "" ]; then
tots=0
fi
totma=`echo $tot | cut -c$tposm-$tposm2 | sed 's/^0\+//'` ## OK
if [ "$totma" = "" ]; then
totma=0
fi
totm=$(( $totma*60 )) ## OK
if [ $tposh2 -lt $d ]; then
toth=0
else
totha=`echo $tot | cut -c$tposh-$tposh2 | sed 's/^0\+//'` ## OK
if [ "$totha" = "" ]; then
totha=0
fi
toth=$(( $totha*3600 )) ## OK
fi
tott=$(( ($toth+$totm) + $tots )) ## OK
expr $currt \* 100 / $tott #Et finalement expression du pourcentage accompli
fi
;;
esac
le script amarok fonctionne avec amarok2
~/.conky/amarok
#!/bin/bash
#fetch conky amarok2 information
#by Mjheagle8
#requires: amarok >= 2.0, qdbus
#[ $(pgrep amarok) ] || exit #This just tests whether amarok is running and exits if it's not.
case "$1" in
version)
qdbus org.kde.amarok / Identity # There's no point in using an echo here when the qdbus command will spit out the information itself.
;; # Also, with qdbus, it's not necessary to call the full method interface. Just 'Identity' here suffices.
artist)
qdbus org.kde.amarok /Player GetMetadata | grep artist: | cut -c 9-
;; # When you're using the cut command, it's not necessary to supply an ending position if you just want to cut to the end.
title)
qdbus org.kde.amarok /Player GetMetadata | grep title: | cut -c 8-
;;
album)
qdbus org.kde.amarok /Player GetMetadata | grep album: | cut -c 8-
;;
year)
qdbus org.kde.amarok /Player GetMetadata | grep year: | cut -c 7-
;;
genre)
qdbus org.kde.amarok /Player GetMetadata | grep genre: | cut -c 8-
;;
bitrate)
echo `qdbus org.kde.amarok /Player GetMetadata | grep audio-bitrate: | cut -c 16-`' Kb/s'
;;
rating)
qdbus org.kde.amarok /Player GetMetadata | grep rating: | cut -c 9-
;;
type)
type=`qdbus org.kde.amarok /Player GetMetadata | grep location:`
echo ${type:(-3)} # Here we're using bash string manipulation to pick off the last three characters.
;;
time)
pos=$((`qdbus org.kde.amarok /Player PositionGet`/1000)) # Here we divide by 1000 without using an intermediate variable.
time=$((`qdbus org.kde.amarok /Player GetMetadata | grep mtime: | cut -c 8-`/1000))
currm=$((pos/60))
currs=$((pos%60))
totm=$((time/60))
tots=$((time%60))
if [ $((currm/60)) -lt 10 ]; then
currm=`~/.conky/conversion.sh $currm`
fi
if [ $((currs%60)) -lt 10 ]; then
currs=`~/.conky/conversion.sh $currs`
fi
if [ $((totm/60)) -lt 10 ]; then
totm=`~/.conky/conversion.sh $totm`
fi
if [ $((tots%60)) -lt 10 ]; then
tots=`~/.conky/conversion.sh $tots`
fi
echo $currm:$currs / $totm:$tots
;;
timeperc)
pos=$((`qdbus org.kde.amarok /Player PositionGet`/10))
time=$(`qdbus org.kde.amarok /Player GetMetadata | grep mtime: | cut -c 8-`/1000)
echo $((pos/time))
;;
progress)
pos=$((`qdbus org.kde.amarok /Player PositionGet`/1000)) # Here we divide by 1000 without using an intermediate variable.
time=$((`qdbus org.kde.amarok /Player GetMetadata | grep mtime: | cut -c 8-`/1000))
currm=$((pos/60))
currs=$((pos%60))
totm=$((time/60))
tots=$((time%60))
if [ $((currm/60)) -lt 10 ]; then
currm=`~/.conky/conversion.sh $currm`
fi
if [ $((currs%60)) -lt 10 ]; then
currs=`~/.conky/conversion.sh $currs`
fi
if [ $((totm/60)) -lt 10 ]; then
totm=`~/.conky/conversion.sh $totm`
fi
if [ $((tots%60)) -lt 10 ]; then
tots=`~/.conky/conversion.sh $tots`
fi
curr=$currm:$currs
tot=$totm:$tots
a=`date +'%S' | sed 's/^0\+//'`
if [ "$a" = "" ]; then
a=0
fi
b=$(( ($a*100) / 30 ))
c=$(( 200-$b ))
#si pas de durée totale, augmente pendant les 30 premieres secondes puis diminu pendant les 30 suivantes...
if [ "$tot" = "" ]; then
if [ $a -le 30 ]; then
expr $b
else
expr
fi
else
#Si durée totale déterminée, il faut traiter le retour de la commande donnant $curr (pour courant et $tot pour total, logique) qui renvoit une donné sous la forme hh:mm:ss
d="1"
nbcurr=`echo $curr | wc -m` #nbr de caractères permet de déterminer si il y a seulement m:ss ou si il y a h:mm:ss (au minimum, m:ss)
posm=$(( $nbcurr-5 )) #pour faire une commande cut générique, il faut définir l'endroit ou on coupe d'ou posx (position des minutes ici)
if [ $posm -lt $d ]; then
posm=`` #Si position inférieur à 1, renvoit variable vide pour ne pas bloque cut
fi
posm2=$(( $nbcurr-4 )) #Forcément 1 indication minute (minimum)= pas besoin de vérifier si >1
posh=$(( $nbcurr-8 )) #Idem pour les heures
if [ $posh -lt $d ]; then
posh=``
fi
posh2=$(( $nbcurr-7 ))
currs=`echo $curr | tail -c3 | sed 's/^0\+//'` # Récupération des secondes forcément à la fin et supression du premier 0 pour ne pas avoir de problème de base (08 en hexa ou base 10)
if [ "$currs" = "" ]; then
currs=0 #si uniquement des zeros, ils sont tous supprimé donc redonner la valeur
fi
currma=`echo $curr | cut -c$posm-$posm2 | sed 's/^0\+//'`
if [ "$currma" = "" ]; then
currma=0 #idem pour minutes
fi
currm=$(( $currma*60 )) #conversion en secondes
if [ $posh2 -lt $d ]; then
currh=0
else
currha=`echo $curr | cut -c$posh-$posh2 | sed 's/^0\+//'`
if [ "$currha" = "" ]; then #idem heures
currha=0
fi
currh=$(( $currha*3600 )) # conversion en secondes
fi
currt=$(( ($currh+$currm) + $currs )) #calcule du nombre de secondes total
nbtot=`echo $tot | wc -m` #Même schema pour la suite mais avec la durée totale
tposm=$(( $nbtot-5 ))
if [ $tposm -lt $d ]; then
tposm=``
fi
tposm2=$(( $nbtot-4 ))
tposh=$(( $nbtot-8 ))
if [ $tposh -lt $d ]; then
tposh=``
fi
tposh2=$(( $nbtot-7 ))
tots=`echo $tot | tail -c3 | sed 's/^0\+//'` ## OK
if [ "$tots" = "" ]; then
tots=0
fi
totma=`echo $tot | cut -c$tposm-$tposm2 | sed 's/^0\+//'` ## OK
if [ "$totma" = "" ]; then
totma=0
fi
totm=$(( $totma*60 )) ## OK
if [ $tposh2 -lt $d ]; then
toth=0
else
totha=`echo $tot | cut -c$tposh-$tposh2 | sed 's/^0\+//'` ## OK
if [ "$totha" = "" ]; then
totha=0
fi
toth=$(( $totha*3600 )) ## OK
fi
tott=$(( ($toth+$totm) + $tots )) ## OK
expr $currt \* 100 / $tott #Et finalement expression du pourcentage accompli
fi
;;
esac
conversion.sh est utilisé dans le script amarok pour caster les durées toujours au même format (mm:ss)
~/.conky/conversion.sh
#!/bin/bash
case "$1" in
0) printf "%02.f\n" "0";;
1) printf "%02.f\n" "1";;
2) printf "%02.f\n" "2";;
3) printf "%02.f\n" "3";;
4) printf "%02.f\n" "4";;
5) printf "%02.f\n" "5";;
6) printf "%02.f\n" "6";;
7) printf "%02.f\n" "7";;
8) printf "%02.f\n" "8";;
9) printf "%02.f\n" "9";;
esac
.conkyrc2
${if_running rhythmbox}
${color3}${font DIST Yolks Emoticons:size=25} L ${font SVBasicManual:style=Bold:size=16}Rhythmbox
${font Sans:style=Bold:pixelsize=10}${color2}Artiste : ${color1}${execi 1 ~/.conky/rhythmbox artist}
${color2}Titre : ${color1}${execi 1 ~/.conky/rhythmbox title}
${color2}Album : ${color1}${execi 1 ~/.conky/rhythmbox album}
${color2}Durée : ${color1}${execibar 1 $HOME/.conky/rhythmbox progress}
${alignr}${color1}${execi 1 ~/.conky/rhythmbox courant}$endif
${if_running amarok}${color #F0C300}${font DIST Yolks Emoticons:size=25} L ${font SVBasicManual:style=Bold:size=16}Amarok
${font Sans:style=Bold:pixelsize=10}${color2}Artiste : ${color1}${execi 1 ~/.conky/amarok artist}
${color2}Titre : ${color1}${execi 1 ~/.conky/amarok title}
${color2}Album : ${color1}${execi 1 ~/.conky/amarok album}
${color2}Bitrate : ${color1}${execi 1 ~/.conky/amarok bitrate}
${color2}Durée : ${color1}${execibar 1 $HOME/.conky/amarok progress}
${color2}${alignr}${color1}${execi 1 ~/.conky/amarok time}
$endif
Ainsi suivant que je lance amarok2 ou rhythmbox les scripts respectifs se lancent :pint:
une petite image est toujours plus explicite...
P.S : désolé pour la tartine ( je poste pas souvent mais quand j'y vais je me fais plaisir :-D)