-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpdnoti
executable file
·37 lines (30 loc) · 1.14 KB
/
mpdnoti
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
#!/bin/bash
# Formats a notification with mpd metadata (which should be the song metadata).
# Also, displays the image cover of the current song album: this image cover
# needs to have the same name as the album in the song, and the extension can
# be .png, .jpg or .jpeg. If no matches, uses $coverDir/sample.png as the image.
# Dep: mpd, mpc
# Where the image file covers are searched
coverDir="${HOME}/.local/share/covers"
# first argument, else this hardcoded value: how much time does the
# notification stays (in ms)
expireTime=${1:-3300}
mpdTitle="$(mpc current --format '[%title%]|[%file%]')"
mpdAlbum="$(mpc current --format '%album%')"
mpdTime="$(mpc status '%currenttime%')/$(mpc current --format '%time%')"
mpdQue="$(mpc status '%songpos%/%length%')"
# bash magik
shopt -s nullglob extglob
covers=("$coverDir"'/'"${mpdAlbum}"@(.png|.jpg|.jpeg))
imgPath=${covers[0]:-"$coverDir"/sample.png}
notify-send \
--replace-id=101 \
--app-name=mpdnoti \
--expire-time="${expireTime}" \
--icon "$imgPath" \
"$mpdTitle" \
"$(mpc current --format \
'By: <b><i>%artist%</i></b>
Album: <u><i>%album%</i></u>')
Span: <i>${mpdTime}</i>
Que: <i>${mpdQue}</i>"