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.
|
||||
[mpd]
|
||||
#instance=spotify
|
||||
interval=1
|
||||
interval=persist
|
||||
signal=13
|
||||
#markup=none
|
||||
|
||||
|
|
230
.i3blocks/mpd
230
.i3blocks/mpd
|
@ -1,27 +1,24 @@
|
|||
#!/bin/bash
|
||||
|
||||
runtime="${XDG_RUNTIME_DIR}/i3blocks"
|
||||
[[ ! -d "$runtime" ]] && mkdir -p "$runtime"
|
||||
# Fonction de réinitialisation en cas de perte de la connexion
|
||||
self-reset() {
|
||||
echo "<span foreground=\"#515151\">[--:-- --:-- --:--]</span>"
|
||||
sleep 5
|
||||
exec "$0"
|
||||
}
|
||||
|
||||
if ! systemctl --user is-active mpd &>/dev/null
|
||||
then
|
||||
origstatus='off'
|
||||
else
|
||||
origstatus="$(mpc status | sed -n '2p' | grep -Eo '^\[.*\]' | tr -d '[]')"
|
||||
[[ -z "$origstatus" ]] && origstatus='stop'
|
||||
fi
|
||||
trap self-reset PIPE
|
||||
|
||||
LONG=40
|
||||
SHORT=20
|
||||
# Initialisation de la connexion au serveur
|
||||
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
|
||||
1) mpc -q prev ;;
|
||||
2) mpc -q toggle ;;
|
||||
3) mpc -q next ;;
|
||||
#4) mpc -q volume +2 ;;
|
||||
#5) mpc -q volume -2 ;;
|
||||
#?*) notify-send "Test" "$BLOCK_BUTTON" ;;
|
||||
esac
|
||||
# Initialisation des valeurs par défaut et des fonctions
|
||||
declare -i SCROLL=50 I=0
|
||||
declare -- artist song oldfile
|
||||
|
||||
human_time() {
|
||||
local seconds="$1"
|
||||
|
@ -43,100 +40,123 @@ human_time() {
|
|||
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\">"
|
||||
case $origstatus in
|
||||
stop ) status="<span foreground=\"#F2777A\">" ;;
|
||||
paused ) status="<span foreground=\"#FFCC66\">" ;;
|
||||
playing ) status="<span foreground=\"#99CC99\">" ;;
|
||||
off ) status="<span foreground=\"#515151\">" ;;
|
||||
esac
|
||||
# Boucle principale
|
||||
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
|
||||
|
||||
if [[ "$origstatus" != "stop" ]] && [[ "$origstatus" != "off" ]]
|
||||
then
|
||||
if [[ ! -f $runtime/mpd ]]
|
||||
then
|
||||
mpc -f '[[%artist%§|%name%§]%title%|[%file%]' current > ${runtime}/mpd
|
||||
fi
|
||||
|
||||
song=$(<${runtime}/mpd)
|
||||
|
||||
if [[ "${#song}" -gt $LONG ]]
|
||||
then
|
||||
scrolling=long
|
||||
elif [[ "${#song}" -gt $SHORT ]]
|
||||
then
|
||||
scrolling=short
|
||||
else
|
||||
scrolling=none
|
||||
fi
|
||||
|
||||
if [[ "$scrolling" != "none" ]]
|
||||
then
|
||||
scroll="$(<${runtime}/mpd-scroll)"
|
||||
|
||||
if [[ -z "${scroll// /}" ]]
|
||||
then
|
||||
printf "%-${LONG}s" "$(<${runtime}/mpd)" > ${runtime}/mpd-scroll
|
||||
song="$(<${runtime}/mpd-scroll)"
|
||||
else
|
||||
song="$(<${runtime}/mpd-scroll)"
|
||||
printf "%-${LONG}s" "${song:1}" > ${runtime}/mpd-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"
|
||||
;;
|
||||
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
|
||||
|
||||
longsong="${longsong:0:$LONG}"
|
||||
shortsong="${shortsong:0:$SHORT}"
|
||||
longsong="${longsong//&/&}"
|
||||
shortsong="${shortsong//&/&}"
|
||||
# Réinitialisation de l’état
|
||||
unset o
|
||||
declare -A o
|
||||
|
||||
if [[ "$longsong" =~ § ]]
|
||||
# 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\">" ;;
|
||||
esac
|
||||
|
||||
|
||||
# En cas de changement de morceau,
|
||||
# on réinitialise l’affichage défilant
|
||||
if [[ "${o["file"]}" != "$oldfile" ]]
|
||||
then
|
||||
longsong="<b>${longsong/§/</b> }"
|
||||
elif [[ "$song" =~ § ]]
|
||||
unset bloc1 bloc2 bloc3 bloc4
|
||||
artist="${o["Artist"]:-${o["Name"]}}"
|
||||
song="${o["Title"]}"
|
||||
[[ -z "$artist$song" ]] && song="${o["file"]}"
|
||||
|
||||
if [[ "$(( ${#song} + ${#artist} + 1 ))" -gt "$SCROLL" ]]
|
||||
then
|
||||
longsong="<b>${longsong}</b>"
|
||||
fi
|
||||
if [[ "$shortsong" =~ § ]]
|
||||
then
|
||||
shortsong="<b>${shortsong/§/</b> }"
|
||||
elif [[ "$song" =~ § ]]
|
||||
then
|
||||
shortsong="<b>${shortsong}</b>"
|
||||
scroll=true
|
||||
song=" $song "
|
||||
else
|
||||
scroll=false
|
||||
song=" $song"
|
||||
fi
|
||||
|
||||
echo "${longsong} $status$longtime</span>"
|
||||
echo "${shortsong} $status$shorttime</span>"
|
||||
else
|
||||
[[ -f ${runtime}/mpd ]] && rm ${runtime}/mpd
|
||||
[[ -f ${runtime}/mpd-scroll ]] && rm ${runtime}/mpd-scroll
|
||||
printf "$status[--:-- --:-- --:--]</span>\n" " "
|
||||
printf "$status--:-- --:--</span>\n" " "
|
||||
fi
|
||||
bloc1="$artist"
|
||||
bloc2="$song"
|
||||
|
||||
oldfile="${o["file"]}"
|
||||
I=0
|
||||
fi
|
||||
|
||||
# Gestion du défilement
|
||||
if "$scroll"
|
||||
then
|
||||
unset bloc1 bloc2 bloc3 bloc4
|
||||
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
|
||||
bloc2="${song:0:$(( SCROLL - ${#bloc1} ))}"
|
||||
if [[ "$(( ${#bloc1} + ${#bloc2} ))" -lt "$SCROLL" ]]
|
||||
then
|
||||
bloc3="${artist:0:$(( SCROLL - ${#bloc2} - ${#bloc1} ))}"
|
||||
fi
|
||||
fi
|
||||
|
||||
I+=1
|
||||
[[ "$I" -ge "$(( ${#artist} + ${#song} ))" ]] && I=0
|
||||
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
|
||||
|
||||
SINK="alsa_output.pci-0000_2b_00.3.analog-stereo"
|
||||
|
||||
currentport=$(pactl list sinks | grep -Po "Active Port: analog.*")
|
||||
|
||||
|
@ -7,10 +8,10 @@ if [[ -n "$button" ]]
|
|||
then
|
||||
if [[ "$currentport" == "Active Port: analog-output-lineout" ]]
|
||||
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"
|
||||
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 "
|
||||
fi
|
||||
pkill -RTMIN+10 i3blocks
|
||||
|
|
|
@ -59,11 +59,13 @@ do
|
|||
declare -a running
|
||||
|
||||
running=($(jobs -p))
|
||||
if [[ "${#running[@]}" -ge 6 ]]
|
||||
if [[ "${#running[@]}" -ge 10 ]]
|
||||
then
|
||||
wait -n
|
||||
fi
|
||||
|
||||
togain="true"
|
||||
|
||||
(
|
||||
echo " $file"
|
||||
ffmpeg -n -loglevel error -i "file:$file" -c:a libopus -b:a 256K "file:${dstdir}${dstfile}"
|
||||
|
@ -76,6 +78,11 @@ do
|
|||
fi
|
||||
done
|
||||
wait
|
||||
|
||||
# Si le moindre fichier a été converti, on refait les tags replay gain
|
||||
|
||||
if ${togain} && [[ "${dir}" != "Vidéos/" ]]
|
||||
then
|
||||
(
|
||||
cd "${dstdir}"
|
||||
shopt -s nullglob
|
||||
|
@ -85,5 +92,9 @@ do
|
|||
echo "[${red}GAIN${reset}] $dir"
|
||||
shopt -u nullglob
|
||||
) & disown $!
|
||||
|
||||
# Réinitialise le tag togain
|
||||
togain="false"
|
||||
fi
|
||||
done
|
||||
wait
|
||||
|
|
Loading…
Reference in a new issue