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

Post your working scripts, libraries and tools for AHK v1.1 and older
Wicked
Posts: 40
Joined: 05 Jun 2016, 20:34

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

Post by Wicked » 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

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.

reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

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

Post by reverberation » 19 Dec 2018, 19:10

Hi guys, is there any function for Saving current playing song to favorites please? Greatly appreciate it!

reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

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

Post by reverberation » 20 Dec 2018, 04:44

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?

reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

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

Post by reverberation » 27 Jan 2019, 01:30

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!

chrich
Posts: 2
Joined: 22 Apr 2017, 13:05

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

Post by chrich » 15 Jul 2020, 01:08

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

chrich
Posts: 2
Joined: 22 Apr 2017, 13:05

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

Post by chrich » 15 Jul 2020, 20:13

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"

User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

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

Post by JnLlnd » 18 Aug 2022, 10:42

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 ")")
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey

Post Reply

Return to “Scripts and Functions (v1)”