f5f630ff342571097fd92f069ea5fe006599703d

Author
DT <dmofot@gmail.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

osx: update spotify to v2.1 (#7820)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/osx/README.md b/plugins/osx/README.md
  2index 3559dee02b588c816c4515b69c8852f0055c5695..4595ee3195e92ffc47ed044577f2a79f1c7579e8 100644
  3--- a/plugins/osx/README.md
  4+++ b/plugins/osx/README.md
  5@@ -18,7 +18,7 @@ This application makes use of the following third party scripts:
  6 
  7 [shpotify](https://github.com/hnarayanan/shpotify)
  8 
  9-Copyright (c) 2012–2017 [Harish Narayanan](https://harishnarayanan.org/).
 10+Copyright (c) 2012–2019 [Harish Narayanan](https://harishnarayanan.org/).
 11 
 12 Permission is hereby granted, free of charge, to any person obtaining
 13 a copy of this software and associated documentation files (the
 14diff --git a/plugins/osx/spotify b/plugins/osx/spotify
 15index b4215dbe71738a89f1efb77ca2821ef6e5dff342..39f8e043719deabd5c3bdc8c56650a151b8f8b09 100644
 16--- a/plugins/osx/spotify
 17+++ b/plugins/osx/spotify
 18@@ -1,7 +1,7 @@
 19 #!/usr/bin/env bash
 20 
 21 function spotify() {
 22-# Copyright (c) 2012--2018 Harish Narayanan <mail@harishnarayanan.org>
 23+# Copyright (c) 2012--2019 Harish Narayanan <mail@harishnarayanan.org>
 24 #
 25 # Contains numerous helpful contributions from Jorge Colindres, Thomas
 26 # Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin
 27@@ -70,7 +70,7 @@ showHelp () {
 28     echo;
 29     echo "  next                         # Skips to the next song in a playlist.";
 30     echo "  prev                         # Returns to the previous song in a playlist.";
 31-    echo "  replay                       # Replays the current track from the begining.";
 32+    echo "  replay                       # Replays the current track from the beginning.";
 33     echo "  pos <time>                   # Jumps to a time (in secs) in the current song.";
 34     echo "  pause                        # Pauses (or resumes) Spotify playback.";
 35     echo "  stop                         # Stops playback.";
 36@@ -82,6 +82,9 @@ showHelp () {
 37     echo "  vol [show]                   # Shows the current Spotify volume.";
 38     echo;
 39     echo "  status                       # Shows the current player status.";
 40+    echo "  status artist                # Shows the currently playing artist.";
 41+    echo "  status album                 # Shows the currently playing album.";
 42+    echo "  status track                 # Shows the currently playing track.";
 43     echo;
 44     echo "  share                        # Displays the current song's Spotify URL and URI."
 45     echo "  share url                    # Displays the current song's Spotify URL and copies it to the clipboard."
 46@@ -99,12 +102,21 @@ cecho(){
 47     echo $bold$green"$1"$reset;
 48 }
 49 
 50+showArtist() {
 51+    echo `osascript -e 'tell application "Spotify" to artist of current track as string'`;
 52+}
 53+
 54+showAlbum() {
 55+    echo `osascript -e 'tell application "Spotify" to album of current track as string'`;
 56+}
 57+
 58+showTrack() {
 59+    echo `osascript -e 'tell application "Spotify" to name of current track as string'`;
 60+}
 61+
 62 showStatus () {
 63     state=`osascript -e 'tell application "Spotify" to player state as string'`;
 64     cecho "Spotify is currently $state.";
 65-    artist=`osascript -e 'tell application "Spotify" to artist of current track as string'`;
 66-    album=`osascript -e 'tell application "Spotify" to album of current track as string'`;
 67-    track=`osascript -e 'tell application "Spotify" to name of current track as string'`;
 68     duration=`osascript -e 'tell application "Spotify"
 69             set durSec to (duration of current track / 1000) as text
 70             set tM to (round (durSec / 60) rounding down) as text
 71@@ -128,7 +140,7 @@ showStatus () {
 72             end tell
 73             return nowAt'`;
 74 
 75-    echo -e $reset"Artist: $artist\nAlbum: $album\nTrack: $track \nPosition: $position / $duration";
 76+    echo -e $reset"Artist: $(showArtist)\nAlbum: $(showAlbum)\nTrack: $(showTrack) \nPosition: $position / $duration";
 77 }
 78 
 79 if [ $# = 0 ]; then
 80@@ -223,18 +235,18 @@ while [ $# -gt 0 ]; do
 81 
 82                         results=$( \
 83                             curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" -H "Authorization: Bearer ${SPOTIFY_ACCESS_TOKEN}" \
 84-                            | grep -E -o "spotify:user:[a-zA-Z0-9_]+:playlist:[a-zA-Z0-9]+" -m 10 \
 85+                            | grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \
 86                         )
 87 
 88                         count=$( \
 89-                            echo "$results" | grep -c "spotify:user" \
 90+                            echo "$results" | grep -c "spotify:playlist" \
 91                         )
 92 
 93                         if [ "$count" -gt 0 ]; then
 94                             random=$(( $RANDOM % $count));
 95 
 96                             SPOTIFY_PLAY_URI=$( \
 97-                                echo "$results" | awk -v random="$random" '/spotify:user:[a-zA-Z0-9]+:playlist:[a-zA-Z0-9]+/{i++}i==random{print; exit}' \
 98+                                echo "$results" | awk -v random="$random" '/spotify:playlist:[a-zA-Z0-9]+/{i++}i==random{print; exit}' \
 99                             )
100                         fi;;
101 
102@@ -295,7 +307,7 @@ while [ $# -gt 0 ]; do
103 
104         "quit"    ) cecho "Quitting Spotify.";
105             osascript -e 'tell application "Spotify" to quit';
106-            exit 1 ;;
107+            exit 0 ;;
108 
109         "next"    ) cecho "Going to next track." ;
110             osascript -e 'tell application "Spotify" to next track';
111@@ -346,7 +358,7 @@ while [ $# -gt 0 ]; do
112                 echo "  vol down                     # Decreases the volume by 10%.";
113                 echo "  vol [amount]                 # Sets the volume to an amount between 0 and 100.";
114                 echo "  vol                          # Shows the current Spotify volume.";
115-                break
116+                exit 1;
117             fi