-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmusic-monitor
executable file
·38 lines (32 loc) · 1.31 KB
/
music-monitor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
handle_property_change() {
music_album_dir="$HOME/.cache/music-albumart"
metadata=$(echo "$1" | grep -oP "(?<='Metadata': )<\{.*\}>")
artist=$(echo "$metadata" | grep -oP "(?<='xesam:artist': )<\[\K[^\]]+" | tr -d "'")
title=$(echo "$metadata" | grep -oP "(?<='xesam:title': )<'\K[^']+" )
album=$(echo "$metadata" | grep -oP "(?<='xesam:album': )<'\K[^']+" )
artUrl=$(echo "$metadata" | grep -oP "(?<='mpris:artUrl': )<'\K[^']+")
status=$(echo "$1" | grep -oP "(?<='PlaybackStatus': )<'\K[^']+" )
if [[ $status == "Playing" ]]; then
if [[ -n $artUrl ]]; then
baseurl=$(basename "$artUrl")
if [[ ! -f "$music_album_dir/$baseurl" ]]; then
curl "$artUrl" > "$music_album_dir/$baseurl"
fi
fi
notify-send -t 5000 "$title" "$artist" -a "$album" -i "$music_album_dir/$baseurl"
convert "$music_album_dir/$baseurl" -resize 100x100 "$music_album_dir/$baseurl"
fi
}
while true; do
player=$(cat "${HOME}/.config/mc.conf")
if [[ -z $player ]]; then
player=$(playerctl -l | head -n 1)
fi
command="timeout 5s gdbus monitor --session --dest org.mpris.MediaPlayer2.$player --object-path /org/mpris/MediaPlayer2"
while read -r line; do
if [[ $line == *"PropertiesChanged"* ]]; then
handle_property_change "$line"
fi
done < <($command)
done