Changement du script i3blocks/mpd
This commit is contained in:
parent
cc6f15e243
commit
8ce08fa228
4 changed files with 149 additions and 117 deletions
|
@ -41,7 +41,7 @@ interval=once
|
||||||
# Supported players are: spotify, vlc, audacious, xmms2, mplayer, and others.
|
# Supported players are: spotify, vlc, audacious, xmms2, mplayer, and others.
|
||||||
[mpd]
|
[mpd]
|
||||||
#instance=spotify
|
#instance=spotify
|
||||||
interval=1
|
interval=persist
|
||||||
signal=13
|
signal=13
|
||||||
#markup=none
|
#markup=none
|
||||||
|
|
||||||
|
|
212
.i3blocks/mpd
212
.i3blocks/mpd
|
@ -1,27 +1,24 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
runtime="${XDG_RUNTIME_DIR}/i3blocks"
|
# Fonction de réinitialisation en cas de perte de la connexion
|
||||||
[[ ! -d "$runtime" ]] && mkdir -p "$runtime"
|
self-reset() {
|
||||||
|
echo "<span foreground=\"#515151\">[--:-- --:-- --:--]</span>"
|
||||||
|
sleep 5
|
||||||
|
exec "$0"
|
||||||
|
}
|
||||||
|
|
||||||
if ! systemctl --user is-active mpd &>/dev/null
|
trap self-reset PIPE
|
||||||
then
|
|
||||||
origstatus='off'
|
|
||||||
else
|
|
||||||
origstatus="$(mpc status | sed -n '2p' | grep -Eo '^\[.*\]' | tr -d '[]')"
|
|
||||||
[[ -z "$origstatus" ]] && origstatus='stop'
|
|
||||||
fi
|
|
||||||
|
|
||||||
LONG=40
|
# Initialisation de la connexion au serveur
|
||||||
SHORT=20
|
coproc nc -U /home/breizh/.mpd/socket
|
||||||
|
IN=${COPROC[1]}
|
||||||
|
OUT=${COPROC[0]}
|
||||||
|
#echo "password xxx" >&${IN}
|
||||||
|
#sed '/^OK$/q' <&$OUT &>/dev/null
|
||||||
|
|
||||||
case $BLOCK_BUTTON in
|
# Initialisation des valeurs par défaut et des fonctions
|
||||||
1) mpc -q prev ;;
|
declare -i SCROLL=50 I=0
|
||||||
2) mpc -q toggle ;;
|
declare -- artist song oldfile
|
||||||
3) mpc -q next ;;
|
|
||||||
#4) mpc -q volume +2 ;;
|
|
||||||
#5) mpc -q volume -2 ;;
|
|
||||||
#?*) notify-send "Test" "$BLOCK_BUTTON" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
human_time() {
|
human_time() {
|
||||||
local seconds="$1"
|
local seconds="$1"
|
||||||
|
@ -43,100 +40,123 @@ human_time() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Initialisation de l’état
|
||||||
|
echo "status" >&$IN
|
||||||
|
while read -t 1 -u $OUT output
|
||||||
|
do
|
||||||
|
[[ "$output" == "OK" ]] && break
|
||||||
|
o[${output%%:*}]="${output##*: }"
|
||||||
|
done
|
||||||
|
|
||||||
status="<span foreground=\"#6699CC\">"
|
# Boucle principale
|
||||||
case $origstatus in
|
while [[ -n "$COPROC_PID" ]]
|
||||||
|
do
|
||||||
|
# Gestion du clic, fait office de délai si aucune action (une seconde).
|
||||||
|
# En cas de clic, l’actualisation de l’affichage sera instantanné.
|
||||||
|
read -t 1 BLOCK_BUTTON
|
||||||
|
|
||||||
|
case $BLOCK_BUTTON in
|
||||||
|
1|3) [[ "${o["state"]}" == stop ]] \
|
||||||
|
&& echo "play" >&${IN} \
|
||||||
|
&& sed '/^OK$/q' <&$OUT &>/dev/null ;;&
|
||||||
|
2) [[ "${o["state"]}" == stop ]] \
|
||||||
|
&& echo "play" >&${IN} \
|
||||||
|
|| echo "pause" >&${IN} ;;&
|
||||||
|
1) echo "previous" >&${IN} ;;&
|
||||||
|
3) echo "next" >&${IN} ;;&
|
||||||
|
1|2|3) sed '/^OK$/q' <&$OUT &>/dev/null ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Réinitialisation de l’état
|
||||||
|
unset o
|
||||||
|
declare -A o
|
||||||
|
|
||||||
|
# Récupération de l’état
|
||||||
|
echo "status" >&$IN
|
||||||
|
while read -t 1 -u $OUT output
|
||||||
|
do
|
||||||
|
[[ "$output" == "OK" ]] && break
|
||||||
|
o[${output%%:*}]="${output##*: }"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Récupération des informations du morceau en cours
|
||||||
|
echo "currentsong" >&$IN
|
||||||
|
while read -t 1 -u $OUT output
|
||||||
|
do
|
||||||
|
[[ "$output" == "OK" ]] && break
|
||||||
|
o[${output%%:*}]="${output##*: }"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Choix des couleurs selon l’état
|
||||||
|
case "${o["state"]}" in
|
||||||
|
play ) status="<span foreground=\"#99CC99\">" ;;
|
||||||
|
pause ) status="<span foreground=\"#FFCC66\">" ;;
|
||||||
stop ) status="<span foreground=\"#F2777A\">" ;;
|
stop ) status="<span foreground=\"#F2777A\">" ;;
|
||||||
paused ) status="<span foreground=\"#FFCC66\">" ;;
|
|
||||||
playing ) status="<span foreground=\"#99CC99\">" ;;
|
|
||||||
off ) status="<span foreground=\"#515151\">" ;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ "$origstatus" != "stop" ]] && [[ "$origstatus" != "off" ]]
|
|
||||||
then
|
|
||||||
if [[ ! -f $runtime/mpd ]]
|
|
||||||
then
|
|
||||||
mpc -f '[[%artist%§|%name%§]%title%|[%file%]' current > ${runtime}/mpd
|
|
||||||
fi
|
|
||||||
|
|
||||||
song=$(<${runtime}/mpd)
|
# En cas de changement de morceau,
|
||||||
|
# on réinitialise l’affichage défilant
|
||||||
|
if [[ "${o["file"]}" != "$oldfile" ]]
|
||||||
|
then
|
||||||
|
unset bloc1 bloc2 bloc3 bloc4
|
||||||
|
artist="${o["Artist"]:-${o["Name"]}}"
|
||||||
|
song="${o["Title"]}"
|
||||||
|
[[ -z "$artist$song" ]] && song="${o["file"]}"
|
||||||
|
|
||||||
if [[ "${#song}" -gt $LONG ]]
|
if [[ "$(( ${#song} + ${#artist} + 1 ))" -gt "$SCROLL" ]]
|
||||||
then
|
then
|
||||||
scrolling=long
|
scroll=true
|
||||||
elif [[ "${#song}" -gt $SHORT ]]
|
song=" $song "
|
||||||
then
|
|
||||||
scrolling=short
|
|
||||||
else
|
else
|
||||||
scrolling=none
|
scroll=false
|
||||||
|
song=" $song"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$scrolling" != "none" ]]
|
bloc1="$artist"
|
||||||
then
|
bloc2="$song"
|
||||||
scroll="$(<${runtime}/mpd-scroll)"
|
|
||||||
|
|
||||||
if [[ -z "${scroll// /}" ]]
|
oldfile="${o["file"]}"
|
||||||
|
I=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Gestion du défilement
|
||||||
|
if "$scroll"
|
||||||
then
|
then
|
||||||
printf "%-${LONG}s" "$(<${runtime}/mpd)" > ${runtime}/mpd-scroll
|
unset bloc1 bloc2 bloc3 bloc4
|
||||||
song="$(<${runtime}/mpd-scroll)"
|
declare -- bloc1 bloc2 bloc3 bloc4
|
||||||
|
bloc1="${artist:$I:$SCROLL}"
|
||||||
|
if [[ "${#bloc1}" -eq 0 ]]
|
||||||
|
then
|
||||||
|
bloc2="${song:$(( I - ${#artist} )):$SCROLL}"
|
||||||
|
if [[ "$(( ${#bloc1} + ${#bloc2} ))" -lt "$SCROLL" ]]
|
||||||
|
then
|
||||||
|
bloc3="${artist:0:$(( SCROLL - ${#bloc2} ))}"
|
||||||
|
if [[ "$(( ${#bloc1} + ${#bloc2} + ${#bloc3} ))" -lt "$SCROLL" ]]
|
||||||
|
then
|
||||||
|
bloc4="${song:0:$(( SCROLL - ${#bloc1} - ${#bloc2} - ${#bloc3} ))}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
song="$(<${runtime}/mpd-scroll)"
|
bloc2="${song:0:$(( SCROLL - ${#bloc1} ))}"
|
||||||
printf "%-${LONG}s" "${song:1}" > ${runtime}/mpd-scroll
|
if [[ "$(( ${#bloc1} + ${#bloc2} ))" -lt "$SCROLL" ]]
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
time="$(echo -e 'status\nclose' | nc -U $MPD_HOST | grep time \
|
|
||||||
| cut -d' ' -f2)"
|
|
||||||
|
|
||||||
time_elapsed=$(human_time "${time%:*}")
|
|
||||||
time_total=$(human_time "${time#*:}")
|
|
||||||
time_left=$(human_time "$(( ${time#*:} - ${time%:*} ))")
|
|
||||||
|
|
||||||
longtime="[$time_elapsed $time_left ${time_total/00:00/--:--}]"
|
|
||||||
shorttime="$time_elapsed $time_left"
|
|
||||||
|
|
||||||
case $scrolling in
|
|
||||||
long)
|
|
||||||
longsong="${song}"
|
|
||||||
shortsong="${song}"
|
|
||||||
;;
|
|
||||||
short)
|
|
||||||
longsong="$(<${runtime}/mpd)"
|
|
||||||
shortsong="${song}"
|
|
||||||
;;
|
|
||||||
none)
|
|
||||||
longsong="$(<${runtime}/mpd)"
|
|
||||||
shortsong="$longsong"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
longsong="${longsong:0:$LONG}"
|
|
||||||
shortsong="${shortsong:0:$SHORT}"
|
|
||||||
longsong="${longsong//&/&}"
|
|
||||||
shortsong="${shortsong//&/&}"
|
|
||||||
|
|
||||||
if [[ "$longsong" =~ § ]]
|
|
||||||
then
|
then
|
||||||
longsong="<b>${longsong/§/</b> }"
|
bloc3="${artist:0:$(( SCROLL - ${#bloc2} - ${#bloc1} ))}"
|
||||||
elif [[ "$song" =~ § ]]
|
|
||||||
then
|
|
||||||
longsong="<b>${longsong}</b>"
|
|
||||||
fi
|
fi
|
||||||
if [[ "$shortsong" =~ § ]]
|
|
||||||
then
|
|
||||||
shortsong="<b>${shortsong/§/</b> }"
|
|
||||||
elif [[ "$song" =~ § ]]
|
|
||||||
then
|
|
||||||
shortsong="<b>${shortsong}</b>"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${longsong} $status$longtime</span>"
|
I+=1
|
||||||
echo "${shortsong} $status$shorttime</span>"
|
[[ "$I" -ge "$(( ${#artist} + ${#song} ))" ]] && I=0
|
||||||
else
|
|
||||||
[[ -f ${runtime}/mpd ]] && rm ${runtime}/mpd
|
|
||||||
[[ -f ${runtime}/mpd-scroll ]] && rm ${runtime}/mpd-scroll
|
|
||||||
printf "$status[--:-- --:-- --:--]</span>\n" " "
|
|
||||||
printf "$status--:-- --:--</span>\n" " "
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Gestion du temps
|
||||||
|
time_elapsed=$(human_time "${o["time"]%:*}")
|
||||||
|
time_total=$(human_time "${o["time"]#*:}")
|
||||||
|
time_left=$(human_time "$(( ${o["time"]#*:} - ${o["time"]%:*} ))")
|
||||||
|
|
||||||
|
time="[${time_elapsed:---:--} ${time_left:---:--} ${time_total:---:--}]"
|
||||||
|
|
||||||
|
# DEBUG
|
||||||
|
printf '<b>%s</b>%s<b>%s</b>%s%s\n' "$bloc1" "$bloc2" "$bloc3" "$bloc4" " $status$time</span>"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
SINK="alsa_output.pci-0000_2b_00.3.analog-stereo"
|
||||||
|
|
||||||
currentport=$(pactl list sinks | grep -Po "Active Port: analog.*")
|
currentport=$(pactl list sinks | grep -Po "Active Port: analog.*")
|
||||||
|
|
||||||
|
@ -7,10 +8,10 @@ if [[ -n "$button" ]]
|
||||||
then
|
then
|
||||||
if [[ "$currentport" == "Active Port: analog-output-lineout" ]]
|
if [[ "$currentport" == "Active Port: analog-output-lineout" ]]
|
||||||
then
|
then
|
||||||
pactl set-sink-port "alsa_output.pci-0000_2b_00.3.analog-stereo.5" "analog-output-headphones"
|
pactl set-sink-port "$SINK" "analog-output-headphones"
|
||||||
echo "casque"
|
echo "casque"
|
||||||
else
|
else
|
||||||
pactl set-sink-port "alsa_output.pci-0000_2b_00.3.analog-stereo.5" "analog-output-lineout"
|
pactl set-sink-port "$SINK" "analog-output-lineout"
|
||||||
echo "front "
|
echo "front "
|
||||||
fi
|
fi
|
||||||
pkill -RTMIN+10 i3blocks
|
pkill -RTMIN+10 i3blocks
|
||||||
|
|
|
@ -59,11 +59,13 @@ do
|
||||||
declare -a running
|
declare -a running
|
||||||
|
|
||||||
running=($(jobs -p))
|
running=($(jobs -p))
|
||||||
if [[ "${#running[@]}" -ge 6 ]]
|
if [[ "${#running[@]}" -ge 10 ]]
|
||||||
then
|
then
|
||||||
wait -n
|
wait -n
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
togain="true"
|
||||||
|
|
||||||
(
|
(
|
||||||
echo " $file"
|
echo " $file"
|
||||||
ffmpeg -n -loglevel error -i "file:$file" -c:a libopus -b:a 256K "file:${dstdir}${dstfile}"
|
ffmpeg -n -loglevel error -i "file:$file" -c:a libopus -b:a 256K "file:${dstdir}${dstfile}"
|
||||||
|
@ -76,6 +78,11 @@ do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
wait
|
wait
|
||||||
|
|
||||||
|
# Si le moindre fichier a été converti, on refait les tags replay gain
|
||||||
|
|
||||||
|
if ${togain} && [[ "${dir}" != "Vidéos/" ]]
|
||||||
|
then
|
||||||
(
|
(
|
||||||
cd "${dstdir}"
|
cd "${dstdir}"
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
@ -85,5 +92,9 @@ do
|
||||||
echo "[${red}GAIN${reset}] $dir"
|
echo "[${red}GAIN${reset}] $dir"
|
||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
) & disown $!
|
) & disown $!
|
||||||
|
|
||||||
|
# Réinitialise le tag togain
|
||||||
|
togain="false"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
wait
|
wait
|
||||||
|
|
Loading…
Reference in a new issue