Page 1 of 1

Re: [Library] Spotify.ahk - Spotify API Wrapper/Global Hotkeys For Spotify

Posted: 17 Nov 2018, 20:14
by Wicked
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

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)
}
scriptcontrol requires 32bit AHK, but still. Figured I'd mention it.

Re: [Library] Spotify.ahk - Spotify API Wrapper/Global Hotkeys For Spotify

Posted: 19 Dec 2018, 19:10
by reverberation
Hi guys, is there any function for Saving current playing song to favorites please? Greatly appreciate it!

Re: [Library] Spotify.ahk - Spotify API Wrapper/Global Hotkeys For Spotify

Posted: 20 Dec 2018, 04:44
by reverberation
Hello,

So sorry but I don't understand how to implement the idea that u just mentioned (full newbie here). is there any sample script or could u guide me please?

Re: [Library] Spotify.ahk - Spotify API Wrapper/Global Hotkeys For Spotify

Posted: 27 Jan 2019, 01:30
by reverberation
Thanks a million for this! Can this be tweaked so that it becomes a Toggle between save/unsaved, together with a toast notification that indicates accordingly?

Thanks!

Re: [Library] Spotify.ahk - Spotify API Wrapper/Global Hotkeys For Spotify

Posted: 15 Jul 2020, 01:08
by chrich
Hi Wicked (and all).

Thanks for leading me to the Spotify.ahk wrapper.

All is working well except for:
Artist:`t`t" . CPI.item.album.artists.0.name . "`n"

which returns null (I see a value "The Beatles" when I view the JSON as a tree).

Is there something I am missing? Syntax error? Any help would be appreciated!
Thanks,
Charlie

-------------

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 . "`%"

Re: [Library] Spotify.ahk - Spotify API Wrapper/Global Hotkeys For Spotify

Posted: 15 Jul 2020, 20:13
by chrich
Got it!
JSON counts 1st nested item as "0",
Spotify.ahk counts 1st nested item as "1",

should be:

MsgBox, % "Artist:`t`t" . CPI.item.album.artists.1.name . "`n"

Re: [Library] Spotify.ahk - Spotify API Wrapper/Global Hotkeys For Spotify

Posted: 18 Aug 2022, 10:42
by JnLlnd
Hi,

I'm trying to run this script but the following line returns this error: "Error: 0x80040154 - Classe non enregistrée" ("class not registered")

static o:=comobjcreate("scriptcontrol")

EDIT: Just realized I was running it with 64-bit. Now with 32-bit AHK, I get this other error:

Error: 0x800A03EA -
Source: Compilation error Microsoft JScript
Description: Syntax error

---> 022: Return,o.eval("(" s ")")