-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblueplayer.sh
88 lines (74 loc) · 2 KB
/
blueplayer.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
#Blueplayer, by Giorgio Acquati
#IMPORTANT!!!
#Change the value of the following variable to the bluetooth address of the device you wish to remotely control
BADDR="68_F8_82_6C_65_6B"
title="Unknown Title"
artist="Unknown Artist"
album="Unknown Album"
icon="$(pwd)/icon.ico"
bold=$(tput bold)
normal=$(tput sgr0)
updateTrackInfo() {
#set all parameters to unknown
title="Unknown Title"
artist="Unknown Artist"
album="Unknown Album"
#parse track information
output=$(dbus-send --print-reply --type=method_call --system --dest=org.bluez /org/bluez/hci0/dev_$BADDR/player0 org.freedesktop.DBus.Properties.Get string:org.bluez.MediaPlayer1 string:Track)
while read -r line; do
if [[ $line == *'string "Album"'* ]]; then
read -r album
elif [[ $line == *'string "Title"'* ]]; then
read -r title
elif [[ $line == *'string "Artist"'* ]]; then
read -r artist
fi
done <<< "$output"
#trim strings
album=$(echo $album | cut -d '"' -f 2 )
title=$(echo $title | cut -d '"' -f 2 )
artist=$(echo $artist | cut -d '"' -f 2 )
}
notifyTrackInfo() {
pkill notify-osd
notify-send --icon="$icon" "$title" "$artist - $album"
}
echoTrackInfo() {
clear
echo ${normal} Currently playing:
echo ${bold}
echo " $title"
#echo ----------------------------------------------------
echo " ${normal}by ${bold}$artist"
echo " ${normal}from ${bold}$album"
}
startNotifying() {
updateTrackInfo
echoTrackInfo
gdbus monitor --system --dest org.bluez --object-path /org/bluez/hci0/dev_$BADDR/player0 |
while read -r line; do
if [[ $line == *"{'Status':"* ]]; then
if [[ $line == *"playing"* ]]; then
updateTrackInfo
notifyTrackInfo
#elif [[ $line == *"paused"* ]]; then
#**code**
fi
elif [[ $line == *" {'Track':"* ]]; then
updateTrackInfo
echoTrackInfo
notifyTrackInfo
fi
done
}
echoDevices() {
python3 $(pwd)/getObj.py |
while read -r line; do
if [[ $(grep -o "/" <<< "$line" | wc -l) == 4 ]]; then
echo $line
fi
done
}
#echoDevices
startNotifying