-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotify.sh
executable file
·22 lines (15 loc) · 910 Bytes
/
spotify.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title play
# @raycast.mode silent
# @raycast.icon https://play-lh.googleusercontent.com/dwyqtk9CgAaoXUcYB8pUHXRErF5A2Shd0UrZdBLkpAFx_e630aZahwN31HRZWNksIQ
# @raycast.argument1 { "type": "text", "placeholder": "track" }
source ./secrets.sh
if ! $(bash ./helpers/is-app-running spotify); then
open -a Spotify -jg
fi
data=$(curl -G -X "GET" "https://api.spotify.com/v1/search" --data-urlencode "q=$*" --data-urlencode "type=track" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $SPOTIFY_TOKEN" | jq -r '.tracks.items | first')
artist=$(jq -r '.artists | first' <<< $data)
track=$(jq -r '{ name: .name, uri: .uri }' <<< $data)
osascript -e 'tell application "Spotify"' -e 'play track "'"$(jq -r '.uri' <<< $track)"'"' -e 'end tell'
echo "Now playing: $(jq -r '.name' <<< $artist) - $(jq -r '.name' <<< $track)"