7077989d28e9cd723afcb4355874683d847278b4

Author
Samuel Beckley <sobeckley@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(macos): update spotify plugin to upstream (#11534)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/macos/spotify b/plugins/macos/spotify
  2index 5fb40517c31852499dbe70bb746a01fdd42df746..ae42db425c98c9295d4c8832d1aee77707f96e23 100644
  3--- a/plugins/macos/spotify
  4+++ b/plugins/macos/spotify
  5@@ -1,7 +1,7 @@
  6 #!/usr/bin/env bash
  7 
  8 function spotify() {
  9-# Copyright (c) 2012--2019 Harish Narayanan <mail@harishnarayanan.org>
 10+# Copyright (c) 2012--2023 Harish Narayanan <mail@harishnarayanan.org>
 11 #
 12 # Contains numerous helpful contributions from Jorge Colindres, Thomas
 13 # Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin
 14@@ -35,6 +35,9 @@ if ! [[ -f "${USER_CONFIG_FILE}" ]]; then
 15 fi
 16 source "${USER_CONFIG_FILE}";
 17 
 18+# Set the percent change in volume for vol up and vol down
 19+VOL_INCREMENT=10
 20+
 21 showAPIHelp() {
 22     echo;
 23     echo "Connecting to Spotify's API:";
 24@@ -170,12 +173,12 @@ while [ $# -gt 0 ]; do
 25                 if [ -z "${CLIENT_ID}" ]; then
 26                     cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}";
 27                     showAPIHelp;
 28-                    return 1
 29+                    return 1;
 30                 fi
 31                 if [ -z "${CLIENT_SECRET}" ]; then
 32                     cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}";
 33                     showAPIHelp;
 34-                    return 1
 35+                    return 1;
 36                 fi
 37                 SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r');
 38                 SPOTIFY_PLAY_URI="";
 39@@ -198,7 +201,7 @@ while [ $# -gt 0 ]; do
 40                     fi
 41                     SPOTIFY_ACCESS_TOKEN=$( \
 42                         printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \
 43-                        | grep -E -o '"access_token":".*",' \
 44+                        | command grep -E -o '"access_token":".*",' \
 45                         | sed 's/"access_token"://g' \
 46                         | sed 's/"//g' \
 47                         | sed 's/,.*//g' \
 48@@ -219,9 +222,8 @@ while [ $# -gt 0 ]; do
 49                             -H "Accept: application/json" \
 50                             --data-urlencode "q=$Q" \
 51                             -d "type=$type&limit=1&offset=0" \
 52-                        | grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1
 53+                        | command grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1
 54                     )
 55-                    echo "play uri: ${SPOTIFY_PLAY_URI}"
 56                 }
 57 
 58                 case $2 in
 59@@ -235,11 +237,11 @@ while [ $# -gt 0 ]; do
 60 
 61                         results=$( \
 62                             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}" \
 63-                            | grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \
 64+                            | command grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \
 65                         )
 66 
 67                         count=$( \
 68-                            echo "$results" | grep -c "spotify:playlist" \
 69+                            echo "$results" | command grep -c "spotify:playlist" \
 70                         )
 71 
 72                         if [ "$count" -gt 0 ]; then
 73@@ -333,16 +335,16 @@ while [ $# -gt 0 ]; do
 74                 cecho "Current Spotify volume level is $vol.";
 75                 break ;
 76             elif [ "$2" = "up" ]; then
 77-                if [ $vol -le 90 ]; then
 78-                    newvol=$(( vol+10 ));
 79+              if [ $vol -le $(( 100-$VOL_INCREMENT )) ]; then
 80+                    newvol=$(( vol+$VOL_INCREMENT ));
 81                     cecho "Increasing Spotify volume to $newvol.";
 82                 else
 83                     newvol=100;
 84                     cecho "Spotify volume level is at max.";
 85                 fi
 86             elif [ "$2" = "down" ]; then
 87-                if [ $vol -ge 10 ]; then
 88-                    newvol=$(( vol-10 ));
 89+                if [ $vol -ge $(( $VOL_INCREMENT )) ]; then
 90+                    newvol=$(( vol-$VOL_INCREMENT ));
 91                     cecho "Reducing Spotify volume to $newvol.";
 92                 else
 93                     newvol=0;
 94@@ -354,11 +356,11 @@ while [ $# -gt 0 ]; do
 95             else
 96                 echo "Improper use of 'vol' command"
 97                 echo "The 'vol' command should be used as follows:"
 98-                echo "  vol up                       # Increases the volume by 10%.";
 99-                echo "  vol down                     # Decreases the volume by 10%.";
100+                echo "  vol up                       # Increases the volume by $VOL_INCREMENT%.";
101+                echo "  vol down                     # Decreases the volume by $VOL_INCREMENT%.";
102                 echo "  vol [amount]                 # Sets the volume to an amount between 0 and 100.";
103                 echo "  vol                          # Shows the current Spotify volume.";
104-                return 1