c3b072eace1ce19a48e36c2ead5932ae2d2e06d9
- Author
- Harish Narayanan <hnarayanan@gmail.com>
- Committer
- Robby Russell <robby@planetargon.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/osx/README.md b/plugins/osx/README.md
2index b77daecc5dc224a3ab6f18ba34667d83fdf1af47..d3a8f94df972da8134c7cf6756a41da0597a0228 100644
3--- a/plugins/osx/README.md
4+++ b/plugins/osx/README.md
5@@ -12,6 +12,33 @@ plugins=(... osx)
6
7 Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
8
9+## Acknowledgements
10+
11+This application makes use of the following third party scripts:
12+
13+[shpotify](https://github.com/hnarayanan/shpotify)
14+
15+Copyright (c) 2012–2017 [Harish Narayanan](https://harishnarayanan.org/).
16+
17+Permission is hereby granted, free of charge, to any person obtaining
18+a copy of this software and associated documentation files (the
19+"Software"), to deal in the Software without restriction, including
20+without limitation the rights to use, copy, modify, merge, publish,
21+distribute, sublicense, and/or sell copies of the Software, and to
22+permit persons to whom the Software is furnished to do so, subject to
23+the following conditions:
24+
25+The above copyright notice and this permission notice shall be
26+included in all copies or substantial portions of the Software.
27+
28+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35+
36
37 ## Commands
38
39diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
40index e8488ebc94ab5b7cb521b6685dd4f7c5111365ef..b7d6aca724364c7b119de0e4efa26aeb4277933e 100644
41--- a/plugins/osx/osx.plugin.zsh
42+++ b/plugins/osx/osx.plugin.zsh
43@@ -277,272 +277,7 @@ EOF
44 }
45
46 # Spotify control function
47-function spotify() {
48-
49- showHelp () {
50- echo "Usage:";
51- echo;
52- echo " $(basename "$0") <command>";
53- echo;
54- echo "Commands:";
55- echo;
56- echo " play # Resumes playback where Spotify last left off.";
57- echo " play [song name] # Finds a song by name and plays it.";
58- echo " play album [album name] # Finds an album by name and plays it.";
59- echo " play artist [artist name] # Finds an artist by name and plays it.";
60- echo " play list [playlist name] # Finds a playlist by name and plays it.";
61- echo " pause # Pauses Spotify playback.";
62- echo " next # Skips to the next song in a playlist.";
63- echo " prev # Returns to the previous song in a playlist.";
64- echo " pos [time] # Jumps to a time (in secs) in the current song.";
65- echo " quit # Stops playback and quits Spotify.";
66- echo;
67- echo " vol up # Increases the volume by 10%.";
68- echo " vol down # Decreases the volume by 10%.";
69- echo " vol [amount] # Sets the volume to an amount between 0 and 100.";
70- echo " vol show # Shows the current Spotify volume.";
71- echo;
72- echo " status # Shows the current player status.";
73- echo " share # Copies the current song URL to the clipboard."
74- echo " info # Shows Full Information about song that is playing.";
75- echo;
76- echo " toggle shuffle # Toggles shuffle playback mode.";
77- echo " toggle repeat # Toggles repeat playback mode.";
78- }
79-
80- cecho(){
81- bold=$(tput bold);
82- green=$(tput setaf 2);
83- reset=$(tput sgr0);
84- echo "$bold$green$1$reset";
85- }
86-
87- showStatus () {
88- state=$(osascript -e 'tell application "Spotify" to player state as string');
89- cecho "Spotify is currently $state.";
90- if [ "$state" = "playing" ]; then
91- artist=$(osascript -e 'tell application "Spotify" to artist of current track as string');
92- album=$(osascript -e 'tell application "Spotify" to album of current track as string');
93- track=$(osascript -e 'tell application "Spotify" to name of current track as string');
94- duration=$(osascript -e 'tell application "Spotify" to duration of current track as string');
95- duration=$(echo "scale=2; $duration / 60 / 1000" | bc);
96- position=$(osascript -e 'tell application "Spotify" to player position as string' | tr ',' '.');
97- position=$(echo "scale=2; $position / 60" | bc | awk '{printf "%0.2f", $0}');
98-
99- printf "$reset""Artist: %s\nAlbum: %s\nTrack: %s \nPosition: %s / %s\n" "$artist" "$album" "$track" "$position" "$duration";
100- fi
101- }
102-
103-
104-
105- if [ $# = 0 ]; then
106- showHelp;
107- else
108- if [ "$1" != "quit" ] && [ "$(osascript -e 'application "Spotify" is running')" = "false" ]; then
109- osascript -e 'tell application "Spotify" to activate'
110- sleep 2
111- fi
112- fi
113-
114- while [ $# -gt 0 ]; do
115- arg=$1;
116-
117- case $arg in
118- "play" )
119- if [ $# != 1 ]; then
120- # There are additional arguments, so find out how many
121- array=( $@ );
122- len=${#array[@]};
123- SPOTIFY_SEARCH_API="https://api.spotify.com/v1/search"
124- SPOTIFY_PLAY_URI="";
125-
126- searchAndPlay() {
127- type="$1"
128- Q="$2"
129-
130- cecho "Searching ${type}s for: $Q";
131-
132- SPOTIFY_PLAY_URI=$( \
133- curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=$type&limit=1&offset=0" -H "Accept: application/json" \
134- | grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1
135- )
136- }
137-
138- case $2 in
139- "list" )
140- _args=${array[*]:2:$len};
141- Q=$_args;
142-
143diff --git a/plugins/osx/spotify b/plugins/osx/spotify
144new file mode 100644
145index 0000000000000000000000000000000000000000..69f6c541994ed5e8a7ae96f5fea7d203942f09ec
146--- /dev/null
147+++ b/plugins/osx/spotify
148@@ -0,0 +1,438 @@
149+#!/usr/bin/env bash
150+
151+function spotify() {
152+# Copyright (c) 2012--2017 Harish Narayanan <mail@harishnarayanan.org>
153+#
154+# Contains numerous helpful contributions from Jorge Colindres, Thomas
155+# Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin
156+# and Peter Fonseca.
157+
158+# Permission is hereby granted, free of charge, to any person
159+# obtaining a copy of this software and associated documentation files
160+# (the "Software"), to deal in the Software without restriction,
161+# including without limitation the rights to use, copy, modify, merge,
162+# publish, distribute, sublicense, and/or sell copies of the Software,
163+# and to permit persons to whom the Software is furnished to do so,
164+# subject to the following conditions:
165+
166+# The above copyright notice and this permission notice shall be
167+# included in all copies or substantial portions of the Software.
168+
169+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
170+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
171+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
172+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
173+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
174+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
175+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
176+# SOFTWARE.
177+
178+USER_CONFIG_DEFAULTS="CLIENT_ID=\"\"\nCLIENT_SECRET=\"\"";
179+USER_CONFIG_FILE="${HOME}/.shpotify.cfg";
180+if ! [[ -f "${USER_CONFIG_FILE}" ]]; then
181+ touch "${USER_CONFIG_FILE}";
182+ echo -e "${USER_CONFIG_DEFAULTS}" > "${USER_CONFIG_FILE}";
183+fi
184+source "${USER_CONFIG_FILE}";
185+
186+showAPIHelp() {
187+ echo;
188+ echo "Connecting to Spotify's API:";
189+ echo;
190+ echo " This command line application needs to connect to Spotify's API in order to";
191+ echo " find music by name. It is very likely you want this feature!";
192+ echo;
193+ echo " To get this to work, you need to sign up (or in) and create an 'Application' at:";
194+ echo " https://developer.spotify.com/my-applications/#!/applications/create";
195+ echo;
196+ echo " Once you've created an application, find the 'Client ID' and 'Client Secret'";
197+ echo " values, and enter them into your shpotify config file at '${USER_CONFIG_FILE}'";
198+ echo;
199+ echo " Be sure to quote your values and don't add any extra spaces!";
200+ echo " When done, it should look like this (but with your own values):";
201+ echo ' CLIENT_ID="abc01de2fghijk345lmnop"';
202+ echo ' CLIENT_SECRET="qr6stu789vwxyz"';
203+}
204+
205+showHelp () {
206+ echo "Usage:";
207+ echo;
208+ echo " `basename $0` <command>";
209+ echo;
210+ echo "Commands:";
211+ echo;
212+ echo " play # Resumes playback where Spotify last left off.";
213+ echo " play <song name> # Finds a song by name and plays it.";
214+ echo " play album <album name> # Finds an album by name and plays it.";
215+ echo " play artist <artist name> # Finds an artist by name and plays it.";
216+ echo " play list <playlist name> # Finds a playlist by name and plays it.";
217+ echo " play uri <uri> # Play songs from specific uri.";
218+ echo;
219+ echo " next # Skips to the next song in a playlist.";
220+ echo " prev # Returns to the previous song in a playlist.";
221+ echo " replay # Replays the current track from the begining.";
222+ echo " pos <time> # Jumps to a time (in secs) in the current song.";
223+ echo " pause # Pauses (or resumes) Spotify playback.";
224+ echo " stop # Stops playback.";
225+ echo " quit # Stops playback and quits Spotify.";
226+ echo;
227+ echo " vol up # Increases the volume by 10%.";
228+ echo " vol down # Decreases the volume by 10%.";
229+ echo " vol <amount> # Sets the volume to an amount between 0 and 100.";
230+ echo " vol [show] # Shows the current Spotify volume.";
231+ echo;
232+ echo " status # Shows the current player status.";
233+ echo;
234+ echo " share # Displays the current song's Spotify URL and URI."
235+ echo " share url # Displays the current song's Spotify URL and copies it to the clipboard."
236+ echo " share uri # Displays the current song's Spotify URI and copies it to the clipboard."
237+ echo;
238+ echo " toggle shuffle # Toggles shuffle playback mode.";
239+ echo " toggle repeat # Toggles repeat playback mode.";
240+ showAPIHelp
241+}
242+
243+cecho(){
244+ bold=$(tput bold);
245+ green=$(tput setaf 2);
246+ reset=$(tput sgr0);
247+ echo $bold$green"$1"$reset;