A godot plugin to control spotify
I will implement the features on the way, as I need them or they are requested by the community
Did you use my code and and it worked without problems? You could ...
WIP: https://patreon.com/
- Auth
- Player
- Get Information About The User's Current Playback
- Get Current Track
- Play
- Pause
- Nextsp
- Set Volume
- Get a User's Available Devices
- Transfer a User's Playback
- Copy the folder addons/tsp-gp-spotify to the project path res://addons/
- Open your Project Settings
- Go to Plugins
- Activate the TSP GP Spotify
- From there, you will have an autoload singleton with the variables
- Goto https://developer.spotify.com/ register
- At the Dashboard "CREATE A CLIENT ID"
- Save the ClientId and ClientSecret
- Goto your App and "Edit Settings"
- Add Redirect URI in Spotify --> you have to choose one
- You need to configure the Spotify Plugin with the id, secret, url and an encrption key. The encryption_key is to save the access tokens of Spotify encrypted.
var enrcyption_key = "SOME_STATIC_KEY_IF_CHANGE_THAT_YOUR_TOKENS_WILL_BE_DELETE_AND_YOU_SHALL_NOT_PASS"
{
"client_id" : "",
"client_secret" : "",
"redirect_uri" : ""
}
Spotify.configure(config, enrcyption_key)- During authenticating you need to tell, which scopes you wanna use:
var scopes = ["user-read-playback-state", "user-modify-playback-state"]
Spotify.Auth.authenticate_start(scopes) - authenticate_start(scopes) triggers a _on_open_authentification_url(url) signal
- open the url in your browser
- accept or don't accept and shut down your computer
- the browser redirects to your redirect_uri and there is a code parameter in your url
- use the code to get the first access token
var code = "thecodeyoucopiedfromtheredirectedurlandyoushallpass"
Spotify.Auth.authentication_code(code)- good to go ... I think ... or there is a bug ;)
Check out the playground code
The Request was a success
signal response_success(data)There was an error with the underlying http request
signal response_error(code, message)The Spotify Web API states an error. e.g. NO_ACTIVE_PLAYER --> this causes an 404 Response
signal spotify_error(code, message, reason)Give the Spotify App access to your spotify account
signal open_authentification_url(url)Successfully Authenticated the app
signal authentification_succeeded(auth)There was an error (http request or spotify api)
signal authentification_response_error(code, message)- if you messed up alot, clear the token
Spotify.Auth._delete_token(client_id)- The Plugin is single HTTP based, this means as long as one command is executed, no other can be sent (and will be ignored). You can check the status with:
func _on_GetCurrentTrack_pressed():
if !Spotify.is_busy():
Spotify.Player.get_current_playing_track()- You sometimes you don't need the request data, you just fire the requests
Spotify.Player.play()- ... but if you want to have a toggle play/pause you need some info before. I created callbacks with funcref for that. Still not sure if this is the best solution
func _on_PlayPause_pressed():
Spotify.Player.get_current_playback_information(funcref(self, "_on_playback_response"))
func _on_playback_response(data):
print("Playback Info for Toggle")
if data.is_playing:
Spotify.Player.pause()
else:
Spotify.Player.play()