92586e38c72a4a3a112a5c2b13cca6fc250e7447

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

Message

add info, share and status option

Diff

  1diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
  2index 386507dbc90228630c9954ddd7524c183a7487ce..dc68916bf69c2a84b81b37715cab12ef6261286e 100644
  3--- a/plugins/osx/osx.plugin.zsh
  4+++ b/plugins/osx/osx.plugin.zsh
  5@@ -263,6 +263,7 @@ EOF
  6 
  7 # Spotify control function
  8 function spotify() {
  9+  
 10   showHelp () {
 11     echo "Usage:";
 12     echo;
 13@@ -277,13 +278,35 @@ function spotify() {
 14     echo "  pos [time]                   # Jumps to a time (in secs) in the current song.";
 15     echo "  quit                         # Stops playback and quits Spotify.";
 16     echo;
 17+    echo "  vol up                       # Increases the volume by 10%.";
 18+    echo "  vol down                     # Decreases the volume by 10%.";
 19     echo "  vol [amount]                 # Sets the volume to an amount between 0 and 100.";
 20     echo "  vol show                     # Shows the current Spotify volume.";
 21     echo;
 22+    echo "  status                       # Shows the current player status.";
 23+    echo "  share                        # Copies the current song URL to the clipboard."
 24+    echo "  info                         # Shows Full Information about song that is playing.";
 25+    echo;
 26     echo "  toggle shuffle               # Toggles shuffle playback mode.";
 27     echo "  toggle repeat                # Toggles repeat playback mode.";
 28   }
 29 
 30+  showStatus () {
 31+      state=$(osascript -e 'tell application "Spotify" to player state as string');
 32+      echo "Spotify is currently $state.";
 33+      if [ "$state" = "playing" ]; then
 34+        artist=$(osascript -e 'tell application "Spotify" to artist of current track as string');
 35+        album=$(osascript -e 'tell application "Spotify" to album of current track as string');
 36+        track=$(osascript -e 'tell application "Spotify" to name of current track as string');
 37+        duration=$(osascript -e 'tell application "Spotify" to duration of current track as string');
 38+        duration=$(echo "scale=2; $duration / 60 / 1000" | bc);
 39+        position=$(osascript -e 'tell application "Spotify" to player position as string' | tr ',' '.');
 40+        position=$(echo "scale=2; $position / 60" | bc | awk '{printf "%0.2f", $0}');
 41+
 42+        echo "$reset""Artist: $artist\nAlbum: $album\nTrack: $track \nPosition: $position / $duration";
 43+      fi
 44+  }
 45+
 46   if [ $# = 0 ]; then
 47     showHelp;
 48   else
 49@@ -367,6 +390,51 @@ function spotify() {
 50         osascript -e "tell application \"Spotify\" to set player position to $2";
 51         break;;
 52 
 53+      "status" )
 54+        showStatus;
 55+        break ;;
 56+
 57+      "info" )
 58+        info=$(osascript -e 'tell application "Spotify"
 59+          set tM to round (duration of current track / 60) rounding down
 60+          set tS to duration of current track mod 60
 61+          set pos to player position as text
 62+          set myTime to tM as text & "min " & tS as text & "s"
 63+          set nM to round (player position / 60) rounding down
 64+          set nS to round (player position mod 60) rounding down
 65+          set nowAt to nM as text & "min " & nS as text & "s"
 66+          set info to "" & "\nArtist:         " & artist of current track
 67+          set info to info & "\nTrack:          " & name of current track
 68+          set info to info & "\nAlbum Artist:   " & album artist of current track
 69+          set info to info & "\nAlbum:          " & album of current track
 70+          set info to info & "\nSeconds:        " & duration of current track
 71+          set info to info & "\nSeconds played: " & pos
 72+          set info to info & "\nDuration:       " & mytime
 73+          set info to info & "\nNow at:         " & nowAt
 74+          set info to info & "\nPlayed Count:   " & played count of current track
 75+          set info to info & "\nTrack Number:   " & track number of current track
 76+          set info to info & "\nPopularity:     " & popularity of current track
 77+          set info to info & "\nId:             " & id of current track
 78+          set info to info & "\nSpotify URL:    " & spotify url of current track
 79+          set info to info & "\nArtwork:        " & artwork of current track
 80+          set info to info & "\nPlayer:         " & player state
 81+          set info to info & "\nVolume:         " & sound volume
 82+          set info to info & "\nShuffle:        " & shuffling
 83+          set info to info & "\nRepeating:      " & repeating
 84+          end tell
 85+          return info')
 86+        echo "$info";
 87+        break ;;
 88+
 89+    "share"     )
 90+      url=$(osascript -e 'tell application "Spotify" to spotify url of current track');
 91+      remove='spotify:track:'
 92+      url=${url#$remove}
 93+      url="http://open.spotify.com/track/$url"
 94+      echo "Share URL: $url";
 95+      echo -n "$url" | pbcopy
 96+      break;;
 97+
 98       -h|--help| *)
 99         showHelp;
100         break ;;