About: https://redd.it/orzend
Example with dependencies: Spotify_Keys.ahk.zip
About: https://redd.it/orzend
Example with dependencies: Spotify_Keys.ahk.zip
| |
; Version: 2022.11.11.1 | |
; About: https://redd.it/orzend | |
#Include %A_LineFile%\..\Spotify_Api.ahk | |
class Spotify_Keys extends Spotify_Actions { | |
_baseEndpoint := "https://api.spotify.com/v1/me/player/" | |
__New(Arguments*) { | |
this._api := new Spotify_Api(Arguments*) | |
} | |
} | |
class Spotify_Actions { | |
__Call(Action, Adjustment:=0) { | |
static methods := {next:"POST", pause:"PUT", play:"PUT", previous:"POST", repeat:"PUT", shuffle:"PUT", volume:"PUT"} | |
Action := Format("{:L}", Action) | |
if (Action ~= "^(repeat|shuffle|toggleplay|volume)$") | |
player := this._api.Rest("GET", this._baseEndpoint) | |
if (Action = "toggleplay") | |
Action := player.is_playing ? "pause" : "play" | |
if !(method := methods[Action]) | |
throw Exception("Action not available.", -1, Action) | |
endpoint := this._baseEndpoint Action | |
if (Action = "shuffle") { | |
opts := {false:"true", true:"false"} | |
endpoint .= "?state=" opts[player.shuffle_state] | |
} else if (Action = "repeat") { | |
opts := {context:"track", off:"context", track:"off"} | |
endpoint .= "?state=" opts[player.repeat_state] | |
} else if (Action = "volume") { | |
volume := player.device.volume_percent + Adjustment | |
volume := Max(0, Min(100, volume)) | |
endpoint .= "?volume_percent=" volume | |
} | |
this._api.Rest(method, endpoint) | |
} | |
} |