3b2f827d5b37d51bdd0c165dc2b66501704990c4
- Author
- mahi97 <mohammadmahdi76@gmail.com>
- Committer
- mahi97 <mohammadmahdi76@gmail.com>
- Date
Message
add Search Option for album,artist and tracks
Diff
1diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
2index 058576f0be13c0d318bc828e766d3cd35eb88d94..031740633784e001e204a2595d607af7952034a2 100644
3--- a/plugins/osx/osx.plugin.zsh
4+++ b/plugins/osx/osx.plugin.zsh
5@@ -330,9 +330,49 @@ function spotify() {
6
7 case $arg in
8 "play" )
9+ if [ $# != 1 ]; then
10+ # There are additional arguments, so find out how many
11+ array=( $@ );
12+ len=${#array[@]};
13+ SPOTIFY_SEARCH_API="https://api.spotify.com/v1/search"
14+ SPOTIFY_PLAY_URI="";
15+
16+ searchAndPlay() {
17+ type="$1"
18+ Q="$2"
19+
20+ cecho "Searching ${type}s for: $Q";
21+
22+ SPOTIFY_PLAY_URI=$( \
23+ curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=$type&limit=1&offset=0" -H "Accept: application/json" \
24+ | grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1
25+ )
26+ }
27+
28+ case $2 in
29+ "album" | "artist" | "track" )
30+ _args=${array[*]:2:$len};
31+ searchAndPlay "$2" "$_args";;
32+
33+ * )
34+ _args=${array[*]:1:$len};
35+ searchAndPlay track "$_args";;
36+ esac
37+
38+ if [ "$SPOTIFY_PLAY_URI" != "" ]; then
39+ cecho "Playing ($Q Search) -> Spotify URL: $";
40+
41+ osascript -e "tell application \"Spotify\" to play track \"$SPOTIFY_PLAY_URI\"";
42+
43+ else
44+ cecho "No results when searching for $Q";
45+ fi
46+ else
47+ # play is the only param
48 cecho "Playing Spotify.";
49 osascript -e 'tell application "Spotify" to play';
50- break ;;
51+ fi
52+ break ;;
53
54 "pause" )
55 state=$(osascript -e 'tell application "Spotify" to player state as string');