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 " replay # Replays the current track from the begining.";
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;
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");
SPOTIFY_PLAY_URI="";
searchAndPlay() {
type="$1"
Q="$2"
getAccessToken() {
cecho "Connecting to Spotify's API";
SPOTIFY_TOKEN_RESPONSE_DATA=$( \
@ -188,6 +186,13 @@ while [ $# -gt 0 ]; do
| sed 's/"//g' \
| sed 's/,.*//g' \
)
}
searchAndPlay() {
type="$1"
Q="$2"
getAccessToken;
cecho "Searching ${type}s for: $Q";
@ -207,10 +212,12 @@ while [ $# -gt 0 ]; do
_args=${array[@]:2:$len};
Q=$_args;
getAccessToken;
cecho "Searching playlists for: $Q";
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 \
)
@ -270,6 +277,17 @@ while [ $# -gt 0 ]; do
osascript -e 'tell application "Spotify" to playpause';
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.";
osascript -e 'tell application "Spotify" to quit';
exit 1 ;;