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)
|
|
|
|
|
2022-11-10 00:54:47 +01:00
|
|
|
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
|
2022-11-10 00:54:47 +01:00
|
|
|
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
|
2022-11-10 00:54:47 +01:00
|
|
|
if [[ -z "$cursong" ]]
|
2020-01-09 21:17:01 +01:00
|
|
|
then
|
|
|
|
infos="<i>Arrêt</i>"
|
|
|
|
fi
|
2022-11-10 00:54:47 +01:00
|
|
|
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")
|
2022-11-10 00:54:47 +01:00
|
|
|
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}" \
|
2022-11-10 00:54:47 +01:00
|
|
|
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
|
|
|
|