Created
August 12, 2021 21:44
-
-
Save par6n/8df4ad2bd894cdfc4e07bec8c37e8051 to your computer and use it in GitHub Desktop.
Can be used in Raycast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Required parameters: | |
# @raycast.schemaVersion 1 | |
# @raycast.title Spotify Search | |
# @raycast.mode compact | |
# Optional parameters: | |
# @raycast.icon 🤖 | |
# @raycast.argument1 { "type": "text", "placeholder": "Query" } | |
# @raycast.packageName Spotify | |
# Documentation: | |
# @raycast.description Searches through Spotify | |
# @raycast.author Ehsaan | |
# @raycast.authorURL https://github.com/par6n | |
import requests | |
import sys | |
import os | |
TOKEN = 'TOKEN_HERE' | |
url = 'https://api.spotify.com/v1/search' | |
params = {'q': sys.argv[1], 'type': 'track'} | |
headers = { | |
'Authorization': 'Bearer ' + TOKEN, | |
'Accept': 'application/json' | |
} | |
r = requests.get(url = url, params = params, headers = headers) | |
data = r.json() | |
track = data['tracks']['items'][0] | |
cmd = 'osascript -e \'tell application "Spotify" to play track "{}"\''.format(track['uri']) | |
os.system(cmd) | |
print('Asking Spotify to play {trackName} from {artistName}'.format(trackName = track['name'], artistName = track['artists'][0]['name'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment