Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

iTunes Info & Control - v2.3


  • Please log in to reply
14 replies to this topic
infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
iTunes Info & Control v2.3

This script lets you create reliable hotkeys for iTunes that work anywhere, including when iTunes is minimized to the tray. It uses sean's COM lib to connect to iTunes to control it and get info from it.

Just Download the .7z or peek at the iTunes.ahk file, though you'll need the other files in the 7z.
This requires sean's COM lib. I recommend it be put in your standard lib, but you could also #include it


These are the hotkeys I use. Also a good demostration of possibilities.
Disclaimer: Neither AHK nor I am in no way liable for any damages resulting from this script giving you a feeling of complete power or sense of limitless, god-like control.
#.::iTunes("NextTrack")
#,::iTunes("PreviousTrack")
#'::iTunes("SoundVolume", "+", 2)
#;::iTunes("SoundVolume", "+", -2)
#=::iTunes("FastForward"), WaitThisHotkey(), iTunes("Resume")
#-::iTunes("Rewind"), WaitThisHotkey(), iTunes("Resume")
#/::iTunes( "Mute", "!" )
#Space::iTunes("PlayPause")
#Backspace::iTunes("Stop")
#Up::iTunes("CurrentTrack.Rating", "+", 20)
#Down::iTunes("CurrentTrack.Rating", "+", -20)

; more useage examples:
iTunes( "SoundVolume", "", 25 )		;set the sound directly to 25
iTunes( "SoundVolume", "+", 10 )	;add ten to the current soundvolume. you can "add" a negative too

iTunes( "Mute", "!" )				;toggles the mute state

iTunes( "PlayFirstTrack" )			;plays the first song in the current playlist
iTunes( "SongRepeat", "", 2 )		;song repeat mode: 0=Play playlist once, 1=Repeat song, 2=Repeat Playlist
iTunes( "PlayFile", "", "D:\Full\Path\To\FileToPlay.ext" ) ; cool, eh?
iTunes( "Quit" )					; uhm, do i really have to tell you this?

#Include iTunes.ahk

WaitThisHotkey() {
; by Infogulch ~ http://www.autohotkey.com/forum/topic35999.html
	RegEx := RegExMatch( A_ThisHotkey, "i)(?:[~#!<>\*\+\^\$]*([^ ]+)( UP)?)$", Key)
	KeyWait, %Key1%, % (Key2 ? "D" : "U")
}

Well, that's the "Control" part, what about the "Info"? First, the Info part is optional, and you don't have to use it if you only want to use the control part. After you start it up, it will fade in and display informaiton about the current playing song. It will then briefly and unobtrousively fade in and out whenever the track changes. Honestly, it may be best for shuffle mode when you may not know what song comes up next. But along with something like changing the rating or fast forwarding, it allows you to see what you're doing without having to open iTunes.

Screenshot:
Posted Image

Resources: I got ideas for much of what's coded here from what's in these links.http://www.autohotke...opic.php?t=5727
http://www.microsoft...zone/tunes.mspx
http://developer.app...unescomsdk.html (unfortuneately, this sdk is primarialy for iT 7x, and not all functions listed work in iT 8 )
Revision History:1.0 ~ initial release. Used WS4AHK as COM workaround.
2.0-2.2 ~ unreleased. 90% rewrite, port to sean's COM lib, debug
2.3 ~ current release. Fixed bugs.Comments:
Though it isn't too dramatic of a visual change, the entire underlying methods of getting and controlling iTunes have changed. With COM comes the ability for iTunes to notify the script of certian events that happen. This allows for less overhead than the previous versions, which basically polled iTunes waiting for different information. WS4AHK has other overhead as well, since I used JS or VBS as a middleman to iTunes' COM functionality. This was also done away with. Hopefully, this script can benefit you iTunes users out there, but even if not, it is a good example of the possibilities of the COM.

The main goals I have for this is an easy to use control of iTunes with an intuitive use of a gui for showing currently playing song info. All of this while being as inobtrousive as possible to the script itself, so I avoided loops and dramatically shortened any timers I had, as well as only creating a total of 10 global vars. So it comes out, intentionally, a script very much intended to be #included into another main script. I just want that possibility to be available.

Credits: Sean for his excellent COM lib, various threads around the forums for giving me ideas and encouragement for possibilities, any pre release testers.

If you use iTunes, I encourage you to try it out! And then tell why you like it! (Or don't) If anybody has any suggestions, I'd love to hear them. :)

Thanks for looking. :D

ophthalmos
  • Members
  • 20 posts
  • Last active: Sep 11 2016 02:38 AM
  • Joined: 17 Jun 2008
Great script! Special thank for your solution to receive trackart!

Do you know how to work with Events from iTunes like
OnQuittingEvent ()
OnPlayerPlayingTrackChangedEvent ([in]) ???

The gui has trouble with refreshing the times making it blink.


Here is my solution for fading in/out a gui. I do not use it inside a function.

iT_FadeOut:
  If WindowShow = False
      Return
  Loop
    {
      If not GetKeyState("LWin", "P") and not GetKeyState("RWin", "P") and not GetKeyState("Ctrl", "P")
        {
          break  ; allows FadeOut-Loop
        }
      Sleep, 10
    }
  WinSet, AlwaysOnTop, Off, %_iTg_GuiID%
  WindowShow := False
  SetTimer, iT_FadeOut, Off
  SetWinDelay, 5
  GuiTop := % A_ScreenHeight - 180
  WinMove, %_iTg_GuiID%,,, GuiTop
  Critical, On ; FadeOut should not be interrupted
  Loop, 76 ; 91
    {
      GuiTop += 2
      WinMove, %_iTg_GuiID%,,, GuiTop
    }
  WinMove, %_iTg_GuiID%,,, %A_ScreenHeight%
Return

iT_FadeIn:
  If WindowShow = True
      Return
  WinSet, AlwaysOnTop, On, %_iTg_GuiID%
  GuiTop := % A_ScreenHeight - 180
      WinMove, %_iTg_GuiID%,,, GuiTop
  SetTimer, iT_FadeOut, -%FadeTimeout%
  WindowShow := True
Return


infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008

Great script! Special thank for your solution to receive trackart!

Thank you! Yes, the track art was a big part of why I did it. It's good to know that someone likes it! :D

Do you know how to work with Events from iTunes like
OnQuittingEvent ()
OnPlayerPlayingTrackChangedEvent ([in]) ???

No, unfortunately. Actually, I'm so noob with JavaScript you wouldn't believe it. :lol: Try downloading the iTunes SDK (referenced above), that's where I figured out nearly everything.

Here is my solution for fading in/out a gui. I do not use it inside a function

Thanks, I'll have to take a closer look at it. Does it solve the flickering problem? (try commenting out the gui, color line to test)

Why not inside a function? Does it take a performance hit or something? I like using functions for as much as possible because my 24/7 script runs most all of my AHK scripts (mostly as includes), and I try to avoid namespace conflicts, Which is hard to do with short simple variables. (which i also like :p )

I'm coming out with a new version soon, It'll be shorter, more general use, with more capabilities. I'll probably change the fading to your suggestion. (or similar at least)

Thanks agian! :)

duckpuppy
  • Members
  • 2 posts
  • Last active: Sep 15 2008 02:56 AM
  • Joined: 15 Sep 2008
This is a great script! I'm loving it, but for one thing: the rating doesn't show anywhere in the display. I've tried playing with the script myself (even going so far as to display a MsgBox containing the calculated rating in the info box code - and it's always right).

The artwork shows up fine, so I know it's finding the iTRes folder fine. The .ico files are in there... I just can't for the life of me figure out what's going on. I've changed the code to display the album artwork as a test in that spot and that works (though it's squished down to 15 pixels high)

Any help out there? I'm loving this script so far - I've added some keys to rate the currently playing song and some other things - that's how I noticed it's not showing, since I redisplay the info when the rating is set to get a visual indicator that the rating changed.

duckpuppy
  • Members
  • 2 posts
  • Last active: Sep 15 2008 02:56 AM
  • Joined: 15 Sep 2008

This is a great script! I'm loving it, but for one thing: the rating doesn't show anywhere in the display. I've tried playing with the script myself (even going so far as to display a MsgBox containing the calculated rating in the info box code - and it's always right).

The artwork shows up fine, so I know it's finding the iTRes folder fine. The .ico files are in there... I just can't for the life of me figure out what's going on. I've changed the code to display the album artwork as a test in that spot and that works (though it's squished down to 15 pixels high)

Any help out there? I'm loving this script so far - I've added some keys to rate the currently playing song and some other things - that's how I noticed it's not showing, since I redisplay the info when the rating is set to get a visual indicator that the rating changed.


Figured it out - sResFolder is not in scope in the _iT_Check label. If I add "sResFolder = %A_ScriptDir%\iTRes" to the top of the _iT_Check label, it works. I printed the name of the icon file that should be chosen in a MsgBox and it came back "\rating5.ico" without any path before it, showing that sResFolder evaluated to a blank string.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
Thanks for trying it. :)

I am working on a rewrite that uses COM instead of working around it with WS4AHK, but it still might take a while.

Ah, the problem was that the "sResFolder" wasn't set as a static variable. If you add it to one of the Static lines at the top of the function, it should work. With a big function like that which has lots of global/static variables something like variable namespace declarations would be really handy.

:)

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
Finally, a new version! iTunes Info & Control has been ported to COM. It's got an updated gui, along with a lot of optimizations. You gotta check it out if you use iTunes!

Even if you don't use iTunes, it's a good example of the usage of various aspects of the COM lib, if you're interested.

I really appreciate feedback, so any suggestions are welcome!

:D

wrecklass
  • Members
  • 31 posts
  • Last active: Aug 22 2015 10:39 PM
  • Joined: 19 Mar 2007
I fixed one thing. If the current song doesn't have album art, and you pop up the info window an error message says the artwork object may be invalid. That's because it is empty. I just fixed it by changing the lines that look like this:
       sArtwork := COM_Invoke( CT, "Artwork", 1)
       COM_Invoke(sArtwork, "SaveArtworkToFile", sArtworkFile)
To look like this:
      sArtwork := COM_Invoke( CT, "Artwork", 1)
      if sArtwork
      {
            COM_Invoke(sArtwork, "SaveArtworkToFile", sArtworkFile)
      }


yyler
  • Members
  • 1 posts
  • Last active: Nov 30 2009 04:07 AM
  • Joined: 28 Nov 2009
I know this is now over a year old, but I really like this script. Wish AHK supported Unicode/this worked with AHKU.

Right now I have it set so that the window only pops up on track changes. I'd like for it to not pop up, except when I use the hotkey to make it appear, and also reflect track changes while staying popped up and so far I can't seem to make it work--it either stops appearing or doesn't refresh. Help?

Overall, though, this is one of the most useful things I have found.

Also I added some things. In the bit that builds the GUI I changed

Gui, Add, Text	, BackgroundTrans x132 y30 w261 h80 -Wrap v_iTg_TrackInfo, Track:`tName`nArtist:`tName`nAlbum:`tName`n`tPlaylist

so that it can show ampersands by adding 0x80 right after the TrackInfo stuff. I'd advise you put this into your version since a lot of songs/bands/albums are gonna have ampersands. Also, just a shortcut I added that you might want:

^F5::
	IfWinNotExist, ahk_class iTunes
		{
		Run %ProgramFiles%\iTunes\iTunes.exe  ;launch program
		return
		}

	IfWinExist, ahk_class iTunes ; toggle minimize/restore
		{
		IfWinNotActive ; restores window
		WinActivate
			Else
			WinMinimize ; minimizes windows
		return
		}

pretty straightforward.

claudeflame
  • Guests
  • Last active:
  • Joined: --
I understand how to implement the iTunes code into AHK, but I don't know where to put the extra files, i.e. iTres folder and COM file. If someone could give me a specific folders to place each file in that would be great.

I tried following the instructions in the first post but where to put the extra files is not clear enough to me. I can get the regular script to work such as Win+. changes my song, but the info does not come up.

Thanks for any help anyone can give me

drosen
  • Members
  • 23 posts
  • Last active: Jan 09 2012 10:50 PM
  • Joined: 13 Apr 2010
Thank you infogulch for this excellent script! I made a couple small changes that might be of interest to others:

- Pandora integration, if the standalone Pandora One player is running. If Pandora One is not running, the command will be sent to iTunes. If iTunes is not running, the keystroke will be sent along as normal.
- Changed shortcuts to use "media keys". On some laptops, these are accessed by using the blue Fn key. Removed handling of Volume Up/Down and Mute keys, since Windows handles these by default.

Available for download. (The only part that has changed from infogulch's original script version 2.3 is the first few lines at the top.)

Keyboard shortcuts are:
Media Key                 Pandora One  iTunes
------------------------  -----------  --------------------
PlayPause                 Play/Pause   Play/Pause
Stop                                   Stop
Next                      Skip Song    Next Track
Prev                                   Previous Track
Ctrl+Next or Shift+Next                Fast Forward, Resume
Ctrl+Prev or Shift+Prev                Fast Rewind, Resume
Alt+Next or Win+Next      Thumb Up     Rating Increase
Alt+Prev or Win+Prev      Thumb Down   Rating Decrease
(any modifier)+PlayPause
  or (any modifier)+Stop               Display info window


wanttolearnahk
  • Guests
  • Last active:
  • Joined: --
When the script tries to save the image file of the album artwork, it shows this error message:
Posted Image
any idea what is this? i get this on both ahk basic and ahk_L.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
This script is quite old now and was made for and older itunes (7 our 8). The api has probably changed dramatically since then. I would suggest downloading the new itunes documentation and copying/converting my code to use ahk com or ahk L with com library (or start fresh).

I don't use itunes anymore, I use musicbee. Unless someone else wants to, this is now unsupported. Sorry. :-/

Ps. Based on your pic it looks like the new itunes doesn't support copying artwork to a file, which happens to be the method of acquiring it to display in the ahk gui. So it may not be possible at all anymore :-(

luciano_arg
  • Members
  • 4 posts
  • Last active: Mar 24 2011 06:48 PM
  • Joined: 31 Jan 2011
I'm running itunes 10 on windows 7 and the script works perfectly!

Thanks for the work

jaaptina
  • Guests
  • Last active:
  • Joined: --
Hello, I have tried all ahk-itunes scripts looking for a script that can start specific songs. "Play File" does the trick. My question is how to read different songs from a specific location and than play that song. I want to write a song title or location to f.e. a text file. The "Play File" function than should read that textfile and have iTunes play the requested song. How should I do that?