Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

iTunes Ratings


  • Please log in to reply
8 replies to this topic
Learned
  • Guests
  • Last active:
  • Joined: --
This is probably not much to you experts out there, but it's something that was annoying me for a bit. I wanted to quickly change ratings as I was listening to music on iTunes. I didn't really care what the music was, just that I wanted to indicate I really liked it or didn't.

I created two vbs scripts as follows:

(iTunesRate+.vbs)
Dim iTunesApp
Set iTunesApp  = CreateObject("iTunes.Application")
Set Current = iTunesApp.CurrentTrack
Current.Rating = Current.Rating + 10

(iTunesRate-.vbs)
Dim iTunesApp
Set iTunesApp  = CreateObject("iTunes.Application")
Set Current = iTunesApp.CurrentTrack
Current.Rating = Current.Rating - 10
I then tied ^Media_Next and ^Media_Prev to those two scripts set to execute in hide mode. Now when I'm listening, no mater what I'm doing, I can give a thumbs up or down to any particular song.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
As no one replies, I tried to write it myself.
Need to copy in the same directory the script CoHelper.ahk.

nInc = 10 ; -10

CoInitialize()
CLSID_iTunesApp := "{DC0C2640-1415-4644-875C-6F4D769839BA}"
 IID_IiTunes    := "{9DD6680B-3EDC-40DB-A771-E6FE4832E34A}"
piT := CreateObject(CLSID_iTunesApp, IID_IiTunes)

DllCall(VTable(piT, 62), "Uint", piT, "UintP", ptr)			; CurrentTrack
DllCall(VTable(ptr, 56), "Uint", ptr, "intP", nRating)			; Rating - Get
DllCall(VTable(ptr, 57), "Uint", ptr, "int" , nRating + nInc)		; Rating - Set
Release(ptr)
Release(piT)
CoUninitialize()

#Include CoHelper.ahk


edkey
  • Members
  • 1 posts
  • Last active: Aug 22 2007 06:39 AM
  • Joined: 22 Aug 2007
Hi I'm new to AHK. This is huge for me. I'm surprised nobody has replied.

How do we use this. Seems like you've provided to com calls from AHK language into Itunes.
Do we just call this code for a particular hotkey?

Thanks

Edit: Nevermind, it seems that each time this code is called, it UP's the rating by 1/2...awesome. Thanks!

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

How do we use this. Seems like you've provided to com calls from AHK language into Itunes.

If you're using the latest CoHelper.ahk, the above will be rewritten as

nInc = 10 ; -10
CoInitialize()

iTunesApp := ActiveXObject("iTunes.Application")
Current := Invoke(iTunesApp, "CurrentTrack")
Invoke(Current, "Rating[color=red]=[/color]", Invoke(Current, "Rating") + nInc)

Release(Current)
Release(iTunesApp)
CoUninitialize()

#Include CoHelper.ahk


Molusc
  • Members
  • 3 posts
  • Last active: Feb 08 2008 12:17 PM
  • Joined: 08 Feb 2008
I've modified this code to allow explicitly setting a rating rather than increasing or decreasing.

I'm new to AHK so I would welcome any comments if I've done something wrong or could improve it in any way.
; Winkey + ` = rate 0 Stars
#`::
	intRating := 0
	GoSub, SetRating
	intRating := ""
return

; Winkey + 1 = rate 1 Stars
#1::
	intRating := 20
	GoSub, SetRating
	intRating := ""
return

; Winkey + 2 = rate 2 Stars
#2::
	intRating := 40
	GoSub, SetRating
	intRating := ""
return

; Winkey + 3 = rate 3 Stars
#3::
	intRating := 60
	GoSub, SetRating
	intRating := ""
return

; Winkey + 4 = rate 4 Stars
#4::
	intRating := 80
	GoSub, SetRating
	intRating := ""
return

; Winkey + 5 = rate 5 Stars
#5::
	intRating := 100
	GoSub, SetRating
	intRating := ""
return

SetRating:
	CoInitialize()

	iTunesApp := ActiveXObject("iTunes.Application")
	Current := Invoke(iTunesApp, "CurrentTrack")
	Invoke(Current, "Rating=", intRating)
	
	Release(Current)
	Release(iTunesApp)
	CoUninitialize()
	
	#Include CoHelper.ahk
return


TheIrishThug
  • Members
  • 419 posts
  • Last active: Jan 18 2012 02:51 PM
  • Joined: 19 Mar 2006
You could make SetRating a function, then just pass it a value and not worry about a global variable.

Molusc
  • Members
  • 3 posts
  • Last active: Feb 08 2008 12:17 PM
  • Joined: 08 Feb 2008

You could make SetRating a function, then just pass it a value and not worry about a global variable.

I tried that first of all, but AHK complained that I was nesting a function inside a function. This was my workaround.

TheIrishThug
  • Members
  • 419 posts
  • Last active: Jan 18 2012 02:51 PM
  • Joined: 19 Mar 2006
You have your Include statement within your Label, did you try to do the same thing with your function? Includes should be at the very top or very bottom of a script so these type of things don't happen and it is easy to know what other things a script is dependent on.

Molusc
  • Members
  • 3 posts
  • Last active: Feb 08 2008 12:17 PM
  • Joined: 08 Feb 2008

You have your Include statement within your Label, did you try to do the same thing with your function?

Well spotted! I did have it there. I've now moved it to the top of the script with the other similar declarations and the script works using a function.

The rating part of the script now looks like this:

; Winkey + ` = rate 0 Stars
#`::
	SetRating(0)
return

; Winkey + 1 = rate 1 Stars
#1::
	SetRating(20)
return

; Winkey + 2 = rate 2 Stars
#2::
	SetRating(40)
return

; Winkey + 3 = rate 3 Stars
#3::
	SetRating(60)
return

; Winkey + 4 = rate 4 Stars
#4::
	SetRating(80)
return

; Winkey + 5 = rate 5 Stars
#5::
	SetRating(100)
return

SetRating(intRating) {
	CoInitialize()

	iTunesApp := ActiveXObject("iTunes.Application")
	Current := Invoke(iTunesApp, "CurrentTrack")
	Invoke(Current, "Rating=", intRating)
	
	Release(Current)
	Release(iTunesApp)
	CoUninitialize()
	
	return
}
Thanks for your help :-)