AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

iTunes Info & Control - v2.3

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Thu Jun 05, 2008 8:29 pm    Post subject: iTunes Info & Control - v2.3 Reply with quote

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


Resources: I got ideas for much of what's coded here from what's in these links.

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. Smile

Thanks for looking. Very Happy
_________________
Scripts - License


Last edited by infogulch on Tue Sep 30, 2008 6:14 am; edited 2 times in total
Back to top
View user's profile Send private message
ophthalmos



Joined: 17 Jun 2008
Posts: 19
Location: Kiel, Germany

PostPosted: Tue Jun 17, 2008 8:44 pm    Post subject: Reply with quote

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

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


Quote:
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.

Code:
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
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Tue Jun 17, 2008 9:28 pm    Post subject: Reply with quote

ophthalmos wrote:
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! Very Happy

Quote:
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. Laughing Try downloading the iTunes SDK (referenced above), that's where I figured out nearly everything.

Quote:
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 Razz )

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! Smile
_________________
Scripts - License
Back to top
View user's profile Send private message
duckpuppy



Joined: 15 Sep 2008
Posts: 2

PostPosted: Mon Sep 15, 2008 3:03 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
duckpuppy



Joined: 15 Sep 2008
Posts: 2

PostPosted: Mon Sep 15, 2008 3:21 am    Post subject: Reply with quote

duckpuppy wrote:
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.
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Tue Sep 16, 2008 5:00 pm    Post subject: Reply with quote

Thanks for trying it. Smile

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.

Smile
_________________
Scripts - License
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Tue Sep 30, 2008 6:22 am    Post subject: New Version! - iTunes Info & Control Reply with quote

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!

Very Happy
_________________
Scripts - License
Back to top
View user's profile Send private message
wrecklass



Joined: 19 Mar 2007
Posts: 29

PostPosted: Sat Oct 04, 2008 9:02 pm    Post subject: Reply with quote

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

       sArtwork := COM_Invoke( CT, "Artwork", 1)
       COM_Invoke(sArtwork, "SaveArtworkToFile", sArtworkFile)

To look like this:
Code:

      sArtwork := COM_Invoke( CT, "Artwork", 1)
      if sArtwork
      {
            COM_Invoke(sArtwork, "SaveArtworkToFile", sArtworkFile)
      }
Back to top
View user's profile Send private message
yyler



Joined: 28 Nov 2009
Posts: 1

PostPosted: Sat Nov 28, 2009 11:28 am    Post subject: Reply with quote

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

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

Code:
^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.
Back to top
View user's profile Send private message
claudeflame
Guest





PostPosted: Tue Dec 22, 2009 3:11 am    Post subject: Help with song ingo Reply with quote

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
Back to top
drosen



Joined: 13 Apr 2010
Posts: 23

PostPosted: Wed May 19, 2010 7:09 pm    Post subject: Reply with quote

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:
Code:
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
Back to top
View user's profile Send private message
wanttolearnahk
Guest





PostPosted: Sun Dec 19, 2010 7:27 am    Post subject: Reply with quote

When the script tries to save the image file of the album artwork, it shows this error message:

any idea what is this? i get this on both ahk basic and ahk_L.
Back to top
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Sun Dec 19, 2010 9:43 pm    Post subject: Reply with quote

This script is quite old now and was made for and older itunes (7 our Cool. 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 Sad
_________________
Scripts - License
Back to top
View user's profile Send private message
luciano_arg



Joined: 31 Jan 2011
Posts: 4

PostPosted: Fri Mar 11, 2011 3:18 am    Post subject: Reply with quote

I'm running itunes 10 on windows 7 and the script works perfectly!

Thanks for the work
Back to top
View user's profile Send private message
jaaptina
Guest





PostPosted: Fri Jun 10, 2011 9:58 pm    Post subject: read song title Reply with quote

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?
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group