Merge with the upstream shpotify project

- Fix playlist playback
- Add a 'stop' command
This commit is contained in:
Harish Narayanan 2017-12-11 14:15:05 +00:00
commit 5165bb07ea

View file

@ -72,7 +72,8 @@ showHelp () {
echo " prev # Returns to the previous song in a playlist."; echo " prev # Returns to the previous song in a playlist.";
echo " replay # Replays the current track from the begining."; echo " replay # Replays the current track from the begining.";
echo " pos <time> # Jumps to a time (in secs) in the current song."; echo " pos <time> # Jumps to a time (in secs) in the current song.";
echo " pause # Pauses Spotify playback."; echo " pause # Pauses (or resumes) Spotify playback.";
echo " stop # Stops playback.";
echo " quit # Stops playback and quits Spotify."; echo " quit # Stops playback and quits Spotify.";
echo; echo;
echo " vol up # Increases the volume by 10%."; echo " vol up # Increases the volume by 10%.";
@ -162,10 +163,7 @@ while [ $# -gt 0 ]; do
SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"); SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n");
SPOTIFY_PLAY_URI=""; SPOTIFY_PLAY_URI="";
searchAndPlay() { getAccessToken() {
type="$1"
Q="$2"
cecho "Connecting to Spotify's API"; cecho "Connecting to Spotify's API";
SPOTIFY_TOKEN_RESPONSE_DATA=$( \ SPOTIFY_TOKEN_RESPONSE_DATA=$( \
@ -188,6 +186,13 @@ while [ $# -gt 0 ]; do
| sed 's/"//g' \ | sed 's/"//g' \
| sed 's/,.*//g' \ | sed 's/,.*//g' \
) )
}
searchAndPlay() {
type="$1"
Q="$2"
getAccessToken;
cecho "Searching ${type}s for: $Q"; cecho "Searching ${type}s for: $Q";
@ -207,10 +212,12 @@ while [ $# -gt 0 ]; do
_args=${array[@]:2:$len}; _args=${array[@]:2:$len};
Q=$_args; Q=$_args;
getAccessToken;
cecho "Searching playlists for: $Q"; cecho "Searching playlists for: $Q";
results=$( \ results=$( \
curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" \ 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}" \
| grep -E -o "spotify:user:[a-zA-Z0-9_]+:playlist:[a-zA-Z0-9]+" -m 10 \ | grep -E -o "spotify:user:[a-zA-Z0-9_]+:playlist:[a-zA-Z0-9]+" -m 10 \
) )
@ -270,6 +277,17 @@ while [ $# -gt 0 ]; do
osascript -e 'tell application "Spotify" to playpause'; osascript -e 'tell application "Spotify" to playpause';
break ;; break ;;
"stop" )
state=`osascript -e 'tell application "Spotify" to player state as string'`;
if [ $state = "playing" ]; then
cecho "Pausing Spotify.";
osascript -e 'tell application "Spotify" to playpause';
else
cecho "Spotify is already stopped."
fi
break ;;
"quit" ) cecho "Quitting Spotify."; "quit" ) cecho "Quitting Spotify.";
osascript -e 'tell application "Spotify" to quit'; osascript -e 'tell application "Spotify" to quit';
exit 1 ;; exit 1 ;;