Mise à jour du gestionnaire de notifications MPD
This commit is contained in:
parent
c19b2ee7d5
commit
a785460823
1 changed files with 30 additions and 7 deletions
|
@ -3,26 +3,46 @@
|
||||||
export MPD_HOST="$HOME/.mpd/socket"
|
export MPD_HOST="$HOME/.mpd/socket"
|
||||||
DUNST_ID=$(sum <<<"mpd" | cut -d' ' -f1)
|
DUNST_ID=$(sum <<<"mpd" | cut -d' ' -f1)
|
||||||
|
|
||||||
|
# Déclaration des variables globales
|
||||||
declare -- cursong prevsong
|
declare -- cursong prevsong
|
||||||
|
|
||||||
while true
|
# Tant que le service MPD fonctionne
|
||||||
|
while systemctl --user is-active mpd.service &>/dev/null
|
||||||
do
|
do
|
||||||
systemctl --user is-active mpd.service &>/dev/null || exit 1
|
# Toutes les 5 secondes, ou dès que le morceau se termine
|
||||||
timeout 5 mpc -w current
|
timeout 5 mpc -w current
|
||||||
|
|
||||||
prevsong="$cursong"
|
prevsong="$cursong"
|
||||||
cursong="$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current)"
|
cursong="$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current)"
|
||||||
|
|
||||||
|
# Si le morceau a changé depuis la dernière vérification
|
||||||
if [[ "$cursong" != "$prevsong" ]]
|
if [[ "$cursong" != "$prevsong" ]]
|
||||||
then
|
then
|
||||||
if [[ -z "$cursong" ]]
|
|
||||||
then
|
# Extractions des informations depuis la chaîne récupérée plus
|
||||||
infos="<i>Arrêt</i>"
|
# tôt, vers un format plus lisible.
|
||||||
fi
|
|
||||||
artist="$(sed -n 1p <<<"$cursong")"
|
artist="$(sed -n 1p <<<"$cursong")"
|
||||||
title="$(sed -n 2p <<<"$cursong")"
|
title="$(sed -n 2p <<<"$cursong")"
|
||||||
album="$(sed -n 3p <<<"$cursong")"
|
album="$(sed -n 3p <<<"$cursong")"
|
||||||
|
|
||||||
|
# Petit trick : si le titre s’est retrouvé sur la première
|
||||||
|
# ligne parce qu’il n’y a pas d’artiste renseigné, on corrige
|
||||||
|
# le contenu des variables (pas forcément fiable, mais
|
||||||
|
# chez moi ça marche™).
|
||||||
[[ -z "$title" ]] && title="$artist" && artist=""
|
[[ -z "$title" ]] && title="$artist" && artist=""
|
||||||
title=$(basename "$title")
|
|
||||||
|
# Si aucune information n’est retournée, c’est que la lecture
|
||||||
|
# s’est arrêtée.
|
||||||
|
if [[ -z "$cursong" ]]
|
||||||
|
then
|
||||||
|
cursong="<i>Arrêt</i>"
|
||||||
|
unset artist title album
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Notification du morceau
|
||||||
dunstify -r "$DUNST_ID" "MPD" "$cursong"
|
dunstify -r "$DUNST_ID" "MPD" "$cursong"
|
||||||
|
|
||||||
|
# Ajout au scrobbler Pleroma
|
||||||
curl -s -X POST -u "breizh:$(pass show Web/pleroma.breizh.pm)" \
|
curl -s -X POST -u "breizh:$(pass show Web/pleroma.breizh.pm)" \
|
||||||
--data-urlencode "title=${title}" \
|
--data-urlencode "title=${title}" \
|
||||||
--data-urlencode "artist=${artist}" \
|
--data-urlencode "artist=${artist}" \
|
||||||
|
@ -31,3 +51,6 @@ do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Si on sort de la boucle c’est que MPD est arrêté, c’est pas normal alors on
|
||||||
|
# sort en erreur.
|
||||||
|
exit 1
|
||||||
|
|
Loading…
Reference in a new issue