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 " 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 ;;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue