dotfiles/.i3blocks/mpd.new

63 lines
1.2 KiB
Text
Raw Normal View History

2020-09-15 02:50:48 +02:00
#!/bin/bash
2021-06-05 22:49:18 +02:00
LENGHT=40
2020-09-15 02:50:48 +02:00
human_time() {
2021-06-05 22:49:18 +02:00
# Prends des secondes
2020-09-15 02:50:48 +02:00
local seconds="$1"
2021-06-05 22:49:18 +02:00
2020-09-15 02:50:48 +02:00
if [[ "$seconds" -lt 0 ]]
then
2021-06-05 22:49:18 +02:00
# Négatif = pas de temps à afficher
2020-09-15 02:50:48 +02:00
echo "--:--"
return
fi
2021-06-05 22:49:18 +02:00
# Calcule les minutes
2020-09-15 02:50:48 +02:00
local minutes=$(( $seconds / 60 ))
seconds=$(( $seconds % 60 ))
2021-06-05 22:49:18 +02:00
# Calcule les heures
local hours=$(( $minutes / 60 ))
minutes=$(( $minutes % 60 ))
if [[ "$hours" -ge 1 ]]
2020-09-15 02:50:48 +02:00
then
2021-06-05 22:49:18 +02:00
# Si on dépasse lheure affiche le temps en heures-minutes
printf "%02dh%02d\n" "$hours" "$minutes"
2020-09-15 02:50:48 +02:00
else
2021-06-05 22:49:18 +02:00
# Sinon en minutes-secondes
2020-09-15 02:50:48 +02:00
printf "%02d:%02d\n" "$minutes" "$seconds"
fi
return
}
2021-06-05 22:49:18 +02:00
# Boucle principale
while true
do
# Déclaration des variables
declare status
2020-09-15 02:50:48 +02:00
2021-06-05 22:49:18 +02:00
# État du serveur
if ! systemctl --user is-active mpd.service &>/dev/null
2020-09-15 02:50:48 +02:00
then
2021-06-05 22:49:18 +02:00
# Traitement particulier pour le cas où le service est coupé
status="off"
2020-09-15 02:50:48 +02:00
else
2021-06-05 22:49:18 +02:00
status="$(mpc status | sed -n '2p' | grep -Eo '^\[.*\]' | tr -d '[]')"
[[ -z status ]] && status="stopped"
2020-09-15 02:50:48 +02:00
fi
2021-06-05 22:49:18 +02:00
artist="$(mpc -f '%artist%' current)"
title="$(mpc -f '%title%' current)"
name="$(mpc -f '%name%' current)"
file="$(basename "$(mpc -f '%file%' current)")"
album="$(mpc -f '%album%' current)"
2020-09-15 02:50:48 +02:00
2021-06-05 22:49:18 +02:00
( zscroll -b "<b>$artist</b> " "${title:-${file}}" ) &
pid="$!"
2020-09-15 02:50:48 +02:00
2021-06-05 22:49:18 +02:00
mpc idle &>/dev/null
kill "$pid"
done