Re: [Library] Spotify.ahk - Spotify API Wrapper/Global Hotkeys For Spotify
Posted: 17 Nov 2018, 20:14
How has this not had any traction?
Thought you might find this handy. Makes GetCurrentPlaybackInfo() a piece of cake. Add the following to your Example_Hotkeys.ahk
scriptcontrol requires 32bit AHK, but still. Figured I'd mention it.
Thought you might find this handy. Makes GetCurrentPlaybackInfo() a piece of cake. Add the following to your Example_Hotkeys.ahk
Code: Select all
F5::
CPI := jsonAHK(spoofy.Player.GetCurrentPlaybackInfo())
MsgBox, % "Artist:`t`t" . CPI.item.album.artists.0.name . "`n"
. "Album:`t`t" . CPI.item.album.name . "`n"
. "Progress:`t`t" . Round(CPI.progress_ms/CPI.item.duration_ms*100) . "`%`n"
. "Track:`t`t" . CPI.item.name . "`n"
. "Volume:`t`t" . CPI.device.volume_percent . "`%"
;~ Or...
CPI := spoofy.Player.GetCurrentPlaybackInfo()
MsgBox, % "Artist:`t`t" . jsonGet(CPI, "item.album.artists[0].name") . "`n"
. "Album:`t`t" . jsonGet(CPI, "item.album.name")
;~ Etc...
return
jsonAHK(s){
static o:=comobjcreate("scriptcontrol")
o.language:="jscript"
return o.eval("(" s ")")
}
jsonBuild(j) {
for x,y in j
s.=((a:=(j.setcapacity(0)=(j.maxindex()-j.minindex()+1)))?"":x ":")(isobject(y)?jsonBuild(y):y/y||y==0?y:"'" y "'") ","
return (a?"[" rtrim(s,",") "]":"{" rtrim(s,",") "}")
}
jsonGet(s,k){
static o:=comobjcreate("scriptcontrol")
o.language:="jscript"
return o.eval("(" s ")." k)
}