dotfiles/.local/bin/mpd-notif

34 lines
926 B
Text
Raw Normal View History

2019-06-13 20:12:29 +02:00
#!/bin/bash
export MPD_HOST="$HOME/.mpd/socket"
2020-01-09 21:17:01 +01:00
DUNST_ID=$(sum <<<"mpd" | cut -d' ' -f1)
declare -- cursong prevsong
2019-06-13 20:12:29 +02:00
while true
do
2021-01-15 21:59:21 +01:00
systemctl --user is-active mpd.service &>/dev/null || exit 1
2020-01-09 21:17:01 +01:00
timeout 5 mpc -w current
prevsong="$cursong"
cursong="$(mpc -f '[[%artist%\n|%name%\n]%title%[\n%album%]]|[%file%]' current)"
if [[ "$cursong" != "$prevsong" ]]
2019-06-13 20:12:29 +02:00
then
if [[ -z "$cursong" ]]
2020-01-09 21:17:01 +01:00
then
infos="<i>Arrêt</i>"
fi
artist="$(sed -n 1p <<<"$cursong")"
title="$(sed -n 2p <<<"$cursong")"
album="$(sed -n 3p <<<"$cursong")"
2020-01-09 21:17:01 +01:00
[[ -z "$title" ]] && title="$artist" && artist=""
title=$(basename "$title")
dunstify -r "$DUNST_ID" "MPD" "$cursong"
curl -s -X POST -u "breizh:$(pass show Web/pleroma.breizh.pm)" \
2020-01-09 21:17:01 +01:00
--data-urlencode "title=${title}" \
--data-urlencode "artist=${artist}" \
--data-urlencode "album=${album}" \
https://pleroma.breizh.pm/api/v1/pleroma/scrobble &>/dev/null
2019-06-13 20:12:29 +02:00
fi
done
2020-01-09 21:17:01 +01:00