forked from Malabarba/control-pianobar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pianobar-notify.sh
executable file
·197 lines (166 loc) · 5.94 KB
/
pianobar-notify.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# Copyright (c) 2011
# Artur de S. L. Malabarba
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
###### USAGE: ######
#
# This is an event script. Place it somewhere convenient for you and
# add the line 'event_command = /PATH/TO/pianobar-notify.sh' to your
# pianobar config file.
#
# Also check if this matches you config folder
fold="$XDG_CONFIG_HOME/pianobar"
# Some of the following was copied from eventcmd.sh
if [[ "$fold" == "/pianobar" ]]; then
fold="$HOME/.config/pianobar"
# blankicon="$fold""$blankicon"
fi
# You should also place the control-pianobar.sh script in the
# config folder (or modify the following variable accordingly).
controlpianobar="$fold/control-pianobar.sh"
# Also place the pandora.jpg file in the same folder, or modify de
# following variable.
blankicon="$fold/pandora.jpg"
notify="notify-send --hint=int:transient:1"
zenity="zenity"
logf="$fold/log"
ctlf="$fold/ctl"
an="$fold/artname"
np="$fold/nowplaying"
ds="$fold/durationstation"
dse="$fold/durationstationexplain"
su="$fold/showupcoming"
stl="$fold/stationlist"
ip="$fold/isplaying"
ine="$fold/ignextevent"
while read L; do
k="`echo "$L" | cut -d '=' -f 1`"
v="`echo "$L" | cut -d '=' -f 2`"
export "$k=$v"
done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|coverArt\|stationCount\|station[0-9]\+\)=' /dev/stdin) # don't overwrite $1...
[[ "$rating" == 1 ]] && like="(like)"
playpause="||"
[[ "$(cat "$ip")" == 1 ]] && playpause="|>"
icon=`echo "$artist-$album.jpg" | sed 's/\//_/g'`
songPlayed="$(($songDuration-$songPlayed))"
dursec="$(($(($songDuration-$(($songDuration/60000*60000))))/1000))"
plasec="$(($(($songPlayed-$(($songPlayed/60000*60000))))/1000))"
if [[ $dursec -lt 10 ]]; then
duration="$(($songDuration/60000)):"0$dursec
else
duration="$(($songDuration/60000)):"$dursec
fi
if [[ $plasec -lt 10 ]]; then
played="$(($songPlayed/60000)):"0$plasec
else
played="$(($songPlayed/60000)):"$plasec
fi
if [[ $songDuration -gt 10 ]]; then
echo -e "\-$played/$duration \t $playpause
Album: $album
Station: $stationName" > "$ds"
else
echo "
Album: $album
Station: $stationName" > "$ds"
fi
echo "$title - $artist $like" > "$np"
case "$1" in
songstart)
echo "1" > "$ip"
cd "$fold/albumart"
if [[ ! -e "$icon" ]]; then
if [[ -n "$coverArt" ]]; then
wget -q -O "$icon" "$coverArt"
echo "$fold/albumart/$icon" > $an
else
echo "$blankicon" > $an
fi
else
echo "$fold/albumart/$icon" > $an
fi
$notify -t 7000 -i "`cat $an`" "Now Playing" "`cat $np` `cat $ds`"
echo "" > "$logf"
if [[ -e "$su" ]]; then
$controlpianobar u 7 &
rm -f "$su"
fi;;
songexplain)
cp "$ds" "$dse"
tail -1 "$logf" | grep --text "(i) We're" | sed 's/.*(i).*features/*/' | sed 's/,/\n*/g' | sed 's/and \([^,]*\)\./\n* \1/' | sed 's/\* many other similarities.*/* and more./' >> "$dse"
$notify -t 15000 -i "`cat $an`" "`cat $np`" "`cat $dse`";;
songlove)
if [[ -e "$ine" ]]; then
$notify -t 2500 -i "$blankicon" "Song Liked" ""
rm -f "$ine"
else
$notify -t 2500 -i "`cat $an`" "Song Liked" "$artist - $title"
fi;;
songban)
if [[ -e "$ine" ]]; then
$notify -t 2500 -i "$blankicon" "Song Banned" ""
rm -f "$ine"
else
$notify -t 2500 -i "`cat $an`" "Song Banned" "$artist - $title"
fi;;
songshelf)
if [[ -e "$ine" ]]; then
$notify -t 2500 -i "$blankicon" "Song Put Away" ""
rm -f "$ine"
else
$notify -t 2500 -i "`cat $an`" "Song Put Away" "$artist - $title"
fi;;
stationfetchplaylist)
echo "1" > "$su";;
usergetstations)
if [[ $stationCount -gt 0 ]]; then
rm -f "$stl"
for stnum in $(seq 0 $(($stationCount-1))); do
echo "$stnum) "$(eval "echo \$station$stnum") >> "$stl"
done
fi
echo "$($zenity --entry --title="Switch Station" --text="$(cat "$stl")")" > "$ctlf"
;;
userlogin)
if [ "$pRet" -ne 1 ]; then
$notify -t 1500 "Login ERROR 1" "$pRetStr"
$notify -t 6000 "Restart Tor" "This is probably a proxy problem. If tor and polipo are running and configured, restart tor and try again."
# $notify -t 6000 "Restarting Tor" "Input root password, wait a few seconds, and try running pianobar again."
# sleep 1.5
# xterm -e sudo rc.d restart tor && $notify -t 1000 "Success!"
# if [[ $? -eq 0 ]]; then
# $notify "Failure" "Sorry, that's all I can do."
# else
# $notify "Success" "I think it worked. Try running pianobar again."
# fi
elif [ "$wRet" -ne 1 ]; then
$notify "Login ERROR 2" "$wRetStr"
else
$notify -t 2000 -i "$blankicon" "Login Successful" "Fetching Stations..."
fi
;;
songfinish)
exit;;
*)
if [ "$pRet" -ne 1 ]; then
$notify -i "$blankicon" "Pianobar - ERROR" "$1 failed: $pRetStr"
elif [ "$wRet" -ne 1 ]; then
$notify -i "$blankicon" "Pianobar - ERROR" "$1 failed: $wRetStr"
else
$notify -i "$blankicon" "$1" "fill $2"
fi;;
esac