aboutsummaryrefslogtreecommitdiff
path: root/cmusShow.sh
blob: b61e90888be6b701a2cc3a6ce7b7e0124c18340b (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh

# Shows a notification with info about the currently playing song.

scriptName="${0##*/}"
[ "$(pgrep "${scriptName}" | wc -l)" -gt "2" ] && exit 0

notificationFreq=0.5
steps=10
iconSize='128'
bluetoothInfo=''

getCmusInfo() {
	cmus-remote -Q | grep "^${1} " | cut -d' ' -f "${2}-"
}

sToTime() {
	min=$(( $1 / 60 ))
	s=$(( $1 % 60 ))
	[ "$s" -lt 10 ] && s="0${s}"
	echo "${min}:${s}"
}

# Album art info

playingFile="$(getCmusInfo 'file' '2')"
albumArt="/tmp/$(echo "$playingFile" | base64 -w0).png"
ffmpeg -y -i "$playingFile" -an -vf scale="${iconSize}:${iconSize}" "$albumArt"

# Bluetooth info

if bluetoothctl info; then
	device="πŸ“» $(bluetoothctl info |
		grep 'Name: ' |
		cut -d' ' -f '2-')"
	battery="$(bluetoothctl info |
		grep 'Battery Percentage:' |
		grep -o '(.*)' |
		grep -o '[0-9]*')% πŸ”‹"
	bluetoothInfo="\n${device} - ${battery}"
fi

i=0
while [ "$i" -lt "$steps" ]; do

	playingIcon=''
	[ "$(getCmusInfo 'status' 2)" = 'playing' ] && playingIcon='▢️'
	[ "$(getCmusInfo 'status' 2)" = 'paused' ] && playingIcon='⏸️'

	title="🎢 $(getCmusInfo 'tag title' '3') 🎢"
	artist="πŸ§‘β€πŸŽ€ $(getCmusInfo 'tag artist' '3')"
	album="$(getCmusInfo 'tag album' '3') πŸ’½"
	position="$(getCmusInfo 'position' '2')"
	duration="$(getCmusInfo 'duration' '2')"

	percentage="$(awk "BEGIN { print int(${position}/${duration}*100) }")"

	dunstify \
		-r "$(dunstifyIDs.sh cmusShow)" \
		-t 1000 \
		-i "$albumArt" \
		-h "int:value:${percentage}" \
		"${title}" \
		"${artist} - ${album}\n${playingIcon} $(sToTime "${position}") - $(sToTime "${duration}")${bluetoothInfo}"

	sleep "$notificationFreq"
	i=$((i+1))
done