AutoHotkey Community

It is currently May 27th, 2012, 10:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: iTunes Ratings
PostPosted: May 23rd, 2007, 2:44 am 
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:

Code:
(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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2007, 1:46 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
As no one replies, I tried to write it myself.
Need to copy in the same directory the script CoHelper.ahk.

Code:
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2007, 7:39 am 
Offline

Joined: August 22nd, 2007, 7:37 am
Posts: 1
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2007, 6:08 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
edkey wrote:
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

Code:
nInc = 10 ; -10
CoInitialize()

iTunesApp := ActiveXObject("iTunes.Application")
Current := Invoke(iTunesApp, "CurrentTrack")
Invoke(Current, "Rating=", Invoke(Current, "Rating") + nInc)

Release(Current)
Release(iTunesApp)
CoUninitialize()

#Include CoHelper.ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2008, 1:25 pm 
Offline

Joined: February 8th, 2008, 1:17 pm
Posts: 3
Location: London, UK
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.
Code:
; 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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2008, 3:05 pm 
Offline

Joined: March 19th, 2006, 5:52 am
Posts: 419
You could make SetRating a function, then just pass it a value and not worry about a global variable.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2008, 3:15 pm 
Offline

Joined: February 8th, 2008, 1:17 pm
Posts: 3
Location: London, UK
TheIrishThug wrote:
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2008, 5:03 pm 
Offline

Joined: March 19th, 2006, 5:52 am
Posts: 419
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2008, 5:40 pm 
Offline

Joined: February 8th, 2008, 1:17 pm
Posts: 3
Location: London, UK
TheIrishThug wrote:
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:

Code:
; 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 :-)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: specter333, XX0 and 25 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group