b808555678ea6a960d3ab31f1bdce4bd18ab0a10

Author
mahi97 <mohammadmahdi76@gmail.com>
Committer
mahi97 <mohammadmahdi76@gmail.com>
Date

Message

add search option for playlist

Diff

 1diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
 2index 031740633784e001e204a2595d607af7952034a2..4ba2026c0ad814f62dbcb8a949fc25e81710424b 100644
 3--- a/plugins/osx/osx.plugin.zsh
 4+++ b/plugins/osx/osx.plugin.zsh
 5@@ -350,6 +350,29 @@ function spotify() {
 6           }
 7 
 8           case $2 in
 9+            "list"  )
10+              _args=${array[*]:2:$len};
11+              Q=$_args;
12+
13+              cecho "Searching playlists for: $Q";
14+
15+              results=$( \
16+                curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" \
17+                | grep -E -o "spotify:user:[a-zA-Z0-9_]+:playlist:[a-zA-Z0-9]+" -m 10 \
18+                )
19+
20+              count=$( \
21+                echo "$results" | grep -c "spotify:user" \
22+                )
23+
24+              if [ "$count" -gt 0 ]; then
25+                random=$(( RANDOM % count));
26+
27+                SPOTIFY_PLAY_URI=$( \
28+                  echo "$results" | awk -v random="$random" '/spotify:user:[a-zA-Z0-9]+:playlist:[a-zA-Z0-9]+/{i++}i==random{print; exit}' \
29+                  )
30+              fi;;
31+
32             "album" | "artist" | "track"    )
33               _args=${array[*]:2:$len};
34               searchAndPlay "$2" "$_args";;
35@@ -367,12 +390,12 @@ function spotify() {
36           else
37             cecho "No results when searching for $Q";
38           fi
39-      else
40-        # play is the only param
41-        cecho "Playing Spotify.";
42-        osascript -e 'tell application "Spotify" to play';
43-      fi
44-      break ;;
45+        else
46+          # play is the only param
47+          cecho "Playing Spotify.";
48+          osascript -e 'tell application "Spotify" to play';
49+        fi
50+        break ;;
51 
52       "pause"    )
53         state=$(osascript -e 'tell application "Spotify" to player state as string');