64 lines
1.3 KiB
Bash
Executable file
64 lines
1.3 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
LENGHT=40
|
||
|
||
human_time() {
|
||
# Prends des secondes
|
||
local seconds="$1"
|
||
|
||
if [[ "$seconds" -lt 0 ]]
|
||
then
|
||
# Négatif = pas de temps à afficher
|
||
echo "--:--"
|
||
return
|
||
fi
|
||
|
||
# Calcule les minutes
|
||
local minutes=$(( $seconds / 60 ))
|
||
seconds=$(( $seconds % 60 ))
|
||
|
||
# Calcule les heures
|
||
local hours=$(( $minutes / 60 ))
|
||
minutes=$(( $minutes % 60 ))
|
||
|
||
if [[ "$hours" -ge 1 ]]
|
||
then
|
||
# Si on dépasse l’heure affiche le temps en heures-minutes
|
||
printf "%02dh%02d\n" "$hours" "$minutes"
|
||
else
|
||
# Sinon en minutes-secondes
|
||
printf "%02d:%02d\n" "$minutes" "$seconds"
|
||
fi
|
||
return
|
||
}
|
||
|
||
# Boucle principale
|
||
while true
|
||
do
|
||
# Déclaration des variables
|
||
declare status
|
||
|
||
# État du serveur
|
||
if ! systemctl --user is-active mpd.service &>/dev/null
|
||
then
|
||
# Traitement particulier pour le cas où le service est coupé
|
||
status="off"
|
||
else
|
||
status="$(mpc status | sed -n '2p' | grep -Eo '^\[.*\]' | tr -d '[]')"
|
||
[[ -z status ]] && status="stopped"
|
||
fi
|
||
|
||
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)"
|
||
|
||
[[ -n "$artist" ]] && artist+=" "
|
||
|
||
( zscroll -n false -b "$(tput bold)$artist$(tput sgr0)" "${title:-${file}}" ) &
|
||
pid="$!"
|
||
|
||
mpc idle &>/dev/null
|
||
kill "$pid"
|
||
done
|