-
Notifications
You must be signed in to change notification settings - Fork 1
/
itunes_beatles.10s.sh
executable file
·177 lines (151 loc) · 4.31 KB
/
itunes_beatles.10s.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
#!/bin/bash
# Get current iTunes status with play/pause button,
# shows current track information,
# if track artist is The Beatles, addiational information
# (vocals, year) will be displayed.
#
# based on Spotify script by Jason Tokoph ([email protected]),
# tweaked by Dan Turkel ([email protected]),
# additionally tweaked by Aleš Farčnik (@alesf)
# then additionally tweaked by reorx (@reorx)
#
# 10 second refresh might be a little too quick. Tweak to your liking.
# metadata
# <bitbar.title>iTunes Now Playing (w/ The Beatles)</bitbar.title>
# <bitbar.version>v1.2</bitbar.version>
# <bitbar.author>Dan Turkel, Jason Tokoph, Aleš Farčnik, reorx</bitbar.author>
# <bitbar.author.github>reorx</bitbar.author.github>
# <bitbar.desc>Display currently playing iTunes song, show vocals for The Beatles song. Play/pause, skip forward, skip backward.</bitbar.desc>
# <bitbar.image>http://i.imgur.com/lBfoFdY.png</bitbar.image>
# TODO support spotify
##################
# configurations #
##################
export PATH="/usr/local/bin:/usr/bin:$PATH"
BTS_PATH="bts"
if ! [ -x "$(command -v "$BTS_PATH")" ]; then
echo "please set correct BTS_PATH before running"
exit 1
fi
#----------------#
if [ "$1" = 'launch' ]; then
osascript -e 'tell application "iTunes" to activate'
exit
fi
if [ "$1" = 'open' ]; then
osascript -e 'tell application "iTunes" to reopen'
osascript -e 'tell application "iTunes" to activate'
exit
fi
if [ "$(osascript -e 'application "iTunes" is running')" = "false" ]; then
echo "♫ | size=12"
echo "---"
echo "iTunes is not running"
echo "Launch iTunes | bash='$0' param1=launch terminal=false"
exit
fi
if [ "$1" = 'playpause' ]; then
osascript -e 'tell application "iTunes" to playpause'
exit
fi
if [ "$1" = 'previous' ]; then
osascript -e 'tell application "iTunes" to previous track'
exit
fi
if [ "$1" = 'next' ]; then
osascript -e 'tell application "iTunes" to next track';
exit
fi
BitBarDarkMode=${BitBarDarkMode}
if [ "$BitBarDarkMode" ]; then
COLOR0="#666666"
COLOR1="#ffffff"
COLOR2="#666666"
COLOR3="#333333"
else
COLOR0="#333333"
COLOR1="#000000"
COLOR2="#666666"
COLOR3="#999999"
fi
state=$(osascript -e '
try
tell application "iTunes"
with timeout 3 seconds
player state as string
end timeout
end tell
on error errText
"not available"
end try
');
if [ "$state" = "not available" ]; then
echo "♫ | size=12"
echo "---"
echo "iTunes is not available"
exit
fi
track=$(osascript -e'
try
tell application "iTunes" to name of current track as string
on error errText
"no track selected"
end try
');
artist=$(osascript -e'
try
tell application "iTunes" to artist of current track as string
on error errText
""
end try
');
album=$(osascript -e'
try
tell application "iTunes" to album of current track as string
on error errText
""
end try
');
if [ "$state" = "playing" ]; then
state_icon="▶︎"
else
state_icon="𝝞𝝞"
fi
if [ "$track" != "no track selected" ]; then
song_str="$track - $artist"
# get beatles song here
artist_lower=$(echo "$artist" | tr '[:upper:]' '[:lower:]')
if [[ "$artist_lower" == "the beatles" || "$artist_lower" == "beatles" ]]; then
beatles_info=$(BS_PURGE_QUERY=1 \
BS_FMT='{title} - {vocals}, {year}' \
BS_MODE='rank,fuzzy' \
"$BTS_PATH" "$track" 2>&1)
rc=$?
#echo "got beatles, $beatles_info"
if [ $rc -eq 0 ]; then
song_str="$beatles_info"
#echo "set song str, $song_str"
else
song_str="$song_str (bts failed $rc)"
echo "bts result: $beatles_info"
fi
fi
echo "♫ $state_icon $song_str | color=$COLOR0 size=12"
else
echo "♫ ◼︎ | color=$COLOR0 size=12"
fi
echo "---"
if [ "$state" = "playing" ]; then
echo "𝝞𝝞 Pause | bash='$0 'param1=playpause terminal=false refresh=true color=$COLOR0"
echo "« Previous | bash='$0' param1=previous terminal=false refresh=true color=$COLOR0"
echo "» Next | bash='$0' param1=next terminal=false refresh=true color=$COLOR0"
else
echo "▶︎ Play | bash='$0' param1=playpause terminal=false refresh=true color=$COLOR0"
fi
echo "---"
if [ "$track" != "no track selected" ]; then
echo "$track | color=$COLOR1"
echo "$artist | color=$COLOR2"
echo "$album | size=12 color=$COLOR3 length=30"
fi
echo '---'