mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-22 04:51:12 +02:00
Merge with the upstream shpotify project
- Fix playlist playback - Add a 'stop' command
This commit is contained in:
parent
d89051c0c2
commit
5165bb07ea
1 changed files with 24 additions and 6 deletions
|
|
@ -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 ;;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue