New iTunes plugin thread (latest version: v0.1.16)

Questions and comments specific to a particular plugin should go here.
Post Reply
User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

New iTunes plugin thread (latest version: v0.1.16)

Post by Boolean263 » Tue Aug 29, 2017 1:37 am

Version 0.1.16 is out! It's attached to this post. It's mostly minor fixes of things that have bothered me, but I hope you'll try it out and let me know if it breaks anything for you.
  • Touch up some config dialogs (particularly the rating dialog)
  • Lets you turn on or off (not just toggle) visualization, full-screen mode, and mute
  • Works better if you minimize iTunes to the system tray
  • No longer shows iTunes' script warning dialog when you try to quit iTunes
~ * ~ * ~

As requested, this is the new thread for supporting the iTunes plugin. This plugin lets you use actions to control many aspects of iTunes, from simple actions like play/pause to complex functionality like creating a new playlist populated with the results of search criteria. It also includes actions to fetch information about iTunes and the song that's playing, and generates events when you play a local or web-radio song.

Here's the original thread for this plugin, with all its development history and previous releases. The short version is that jitterjames saw a need for the plugin and created it, and in the process, inspired several others to contribute to it and expand it. I (Boolean263) am just the most recent person to take an interest in it, and I put it up on a github page.

Said github page is here: Boolean263/EventGhost-iTunes. If any of the other developers return with a canonical location, it'll move back there. In the meantime, the github page contains the documentation (which will be improved over time) and full changelog.

Download links for the last few versions:
  • 0.1.15 (egplugin): merge yokel22's changes from his nifty work on a WebUI into the version I adopted
  • 0.1.14 (__init__.py): yokel22's aforementioned changes
  • 0.1.13 (egplugin): improved behaviour when iTunes isn't running
  • 0.1.12 (egplugin): first new release in a while, added StreamTrackChanged event
  • Earlier releases are documented in the changelog.
Attachments
iTunes-0.1.16.egplugin
(17.67 KiB) Downloaded 41 times
Last edited by Boolean263 on Sat Sep 09, 2017 3:50 pm, edited 1 time in total.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

jachin99
Experienced User
Posts: 328
Joined: Sat Feb 13, 2016 8:39 pm

Re: New iTunes plugin thread

Post by jachin99 » Tue Aug 29, 2017 1:22 pm

Looks good. I was really surprised when I saw the iTunes thread pop up because I didn't know ever existed. It makes me wonder what else is buried in the forums

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

Re: New iTunes plugin thread

Post by Boolean263 » Sat Sep 09, 2017 3:53 pm

jachin99 wrote:Looks good. I was really surprised when I saw the iTunes thread pop up because I didn't know ever existed. It makes me wonder what else is buried in the forums
On occasion I'll just dig around in the archives and see what I can find that's interesting. I found this plugin by searching for it, but not every plugin will be so easy to find.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by Boolean263 » Sat Sep 16, 2017 1:43 am

There was a new iTunes update today, and with this update, this plugin is no longer receiving events. It can't tell when the song changes, or when someone's trying to close it (so you'll be warned that something's using the scripting interface).

Controlling iTunes from this plugin still seems to work.

If anyone has any ideas on what needs to be done to receive events again, I'd be grateful for help.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by Boolean263 » Fri Sep 22, 2017 1:51 am

I noticed that this error is appearing when I (re)start EventGhost with iTunes running (so the plugin can find it):

Code: Select all

Exception AttributeError: AttributeError("COMEventClass instance has no attribute '_olecp'",) in <bound method COMEventClass.__del__ of <win32com.client.COMEventClass instance at 0x08F8BAF8>> ignored
Recording it here in case anyone has any ideas. I'll also try googling it, of course.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
kgschlosser
Site Admin
Posts: 3111
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by kgschlosser » Fri Sep 22, 2017 3:20 am

that error is caused by a permissions issue. this could be because you ran eventghost as an administrator and it created files in %appdata%\EventGhost\gen_py that have administrative privileges assigned to them. or something along those lines.

You can try adding some exception catching for the AttributeError. and then call win32com.client.gencache.Rebuild() to see if this solves your problem.
If you like the work I have been doing then feel free to Image

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by Boolean263 » Fri Sep 22, 2017 10:00 am

kgschlosser wrote:that error is caused by a permissions issue. this could be because you ran eventghost as an administrator and it created files in %appdata%\EventGhost\gen_py that have administrative privileges assigned to them. or something along those lines.

You can try adding some exception catching for the AttributeError. and then call win32com.client.gencache.Rebuild() to see if this solves your problem.
I tried deleting the gen_py directory and restarting EventGhost, but it didn't help. I'll try the exception handling next and see if I get any better results that way.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

COMEventClass error

Post by Boolean263 » Sun Sep 24, 2017 6:16 pm

I've changed the Setup routine in iTunes/__init__.py to this:

Code: Select all

    def Setup(self, plugin, eventHandler):
        self.plugin = plugin
        self.eventHandler = eventHandler
        try:
            win32com.client.gencache.Rebuild()
            self.comInstance = win32com.client.gencache.EnsureDispatch("iTunes.Application")
            win32com.client.WithEvents(self.comInstance,self.eventHandler)
            self.eventHandler.comInstance = self.comInstance
        except Exception as e:
            eg.PrintError("Error attaching to iTunes COM instance: "+repr(e))
These are the messages I get in my log when I restart EventGhost with these changes:

Code: Select all

   Plugin: iTunes
      Rebuilding cache of generated files for COM support...
      Checking 9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13
      Done.
      Error attaching to iTunes COM instance: com_error(-2147467259, 'Unspecified error', None, None)
      Exception AttributeError: AttributeError("COMEventClass instance has no attribute '_olecp'",) in <bound method COMEventClass.__del__ of <win32com.client.COMEventClass instance at 0x05540918>> ignored
So rebuilding the cache doesn't seem to be the answer.

Searching around on the internet hasn't helped much. Lots of people run into a problem like this, but few seem to get the answers they need. This thread points out that "That's 0x80004005, which for MAPI is MAPI_E_CALL_FAILED. Very generic." and suggests using EnsureDispatch() which this plugin already uses. This user found that their 64-bit Python was having trouble with accessing (what I presume was) a 32-bit app, but I uninstalled my system Python, and EventGhost's Python still has this issue.

Like I said above, this started when I upgraded iTunes. I don't recall whether iTunes was 32-bit or 64-bit before, but it's installed in the 64-bit location now. Is it possible that win32com can't talk to 64-bit apps?

Edited to add: I've done more debugging and found that the com_error is generated by this specific statement:

Code: Select all

win32com.client.WithEvents(self.comInstance,self.eventHandler)
I'm having a harder time figuring out where the original AttributeError is being generated, since there's no backtrace generated.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
kgschlosser
Site Admin
Posts: 3111
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by kgschlosser » Sun Sep 24, 2017 7:21 pm

you can get a backtrace from

Code: Select all

eg.log.PrintStack(skip=0)
the skip works 2 fold. it is used in a slicing fashion. so if you send it a - number this is how far nack it will go. and if you send it a + number this is how many it will shave off the beginning of the trace.

so if the trace is 10 long and you only want to return the last 3 then send it a -3 or a 7. the -3 returns the last 3. and the 7 cuts off the first 7. so they are the same thing.

the detailed description is for anyone else that may want to use this feature.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3111
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by kgschlosser » Sun Sep 24, 2017 7:33 pm

also is there a pattern when this happens..??

i know it only happens if iTunes is already open. but see if we can get a more definitive cause.

try closing EG then closing iTunes and then open iTunes and then EG. see if it occurs. I am curious to know if it could be an issue like EG is open then you open iTunes then close EG and then reopen EG and pow the problem happens. that would lead me to believe that the COM connection isn't getting closed.

Also I do now that windows is extremely picky about when and where things get run and messages come in. so since you are getting messages from an external program I would believe that they are coming in on the main thread. but if you start the COM up from inside of the __start__ that is being done in the action thread. so my suggestion would be to create a function/method and put all of the startup crap for the COM into it and use wx.CallAfter(func/meth) to call the func/meth from the main thread.

I have had some really really really odd behavior with extremely cryptic errors like what you are having or no errors at all just strange random behavior. so this is worth a shot as well and even if it doesn't fix it I would leave it because it's good to get into this habit any time you are dealing with the Windows API.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3111
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by kgschlosser » Sun Sep 24, 2017 7:54 pm

you can try this code

Code: Select all

self.comInstance = win32com.client.dynamic.EnsureDispatch("iTunes.Application")            win32com.client.WithEvents(self.comInstance,self.eventHandler)
i have a feeling this one may be the solution tho

Code: Select all

self.comInstance = win32com.client.dynamic.EnsureDispatch("iTunes.Application")
win32com.client.WithDispatch(self.comInstance, self.eventHandler)
you can also skip the whole dynamic portion of it.

Code: Select all

self.comInstance = win32com.client.Dispatch("iTunes.Application")
win32com.client.WithEvents(self.comInstance,self.eventHandler)

I also found this while poking about

here is a nice link to all of the COM API for ITunes

http://www.joshkunz.com/iTunesControl/i ... Tunes.html
If you like the work I have been doing then feel free to Image

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by Boolean263 » Thu Sep 28, 2017 12:08 am

kgschlosser wrote:
Sun Sep 24, 2017 7:54 pm
you can try this code

Code: Select all

self.comInstance = win32com.client.dynamic.EnsureDispatch("iTunes.Application")            win32com.client.WithEvents(self.comInstance,self.eventHandler)
That gives `Error attaching to iTunes COM instance: AttributeError("'module' object has no attribute 'EnsureDispatch'",)`

If I change it to just Dispatch instead of EnsureDispatch, I get my original error: `Error attaching to iTunes COM instance: com_error(-2147467259, 'Unspecified error', None, None)`
kgschlosser wrote:
Sun Sep 24, 2017 7:54 pm
i have a feeling this one may be the solution tho

Code: Select all

self.comInstance = win32com.client.dynamic.EnsureDispatch("iTunes.Application")
win32com.client.WithDispatch(self.comInstance, self.eventHandler)
Again, `Error attaching to iTunes COM instance: AttributeError("'module' object has no attribute 'EnsureDispatch'",)`

If I change the first line again to Dispatch, the error becomes `Error attaching to iTunes COM instance: AttributeError("'module' object has no attribute 'WithDispatch'",)`
kgschlosser wrote:
Sun Sep 24, 2017 7:54 pm
you can also skip the whole dynamic portion of it.

Code: Select all

self.comInstance = win32com.client.Dispatch("iTunes.Application")
win32com.client.WithEvents(self.comInstance,self.eventHandler)
Back to the original error again: `Error attaching to iTunes COM instance: com_error(-2147467259, 'Unspecified error', None, None)`
kgschlosser wrote:
Sun Sep 24, 2017 7:54 pm
I also found this while poking about

here is a nice link to all of the COM API for ITunes

http://www.joshkunz.com/iTunesControl/i ... Tunes.html
Thanks! I've been using that site for a while now, it's pretty handy.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by Boolean263 » Thu Sep 28, 2017 12:24 am

kgschlosser wrote:
Sun Sep 24, 2017 7:33 pm
also is there a pattern when this happens..??
I don't know if this is the answer you were hoping for, but it happens 100% of the time. It doesn't matter whether I open EG or iTunes first. It's even a problem after a reboot, which should resolve any problems involving COM connections not being closed.
kgschlosser wrote:
Sun Sep 24, 2017 7:33 pm
Also I do now that windows is extremely picky about when and where things get run and messages come in. so since you are getting messages from an external program I would believe that they are coming in on the main thread. but if you start the COM up from inside of the __start__ that is being done in the action thread. so my suggestion would be to create a function/method and put all of the startup crap for the COM into it and use wx.CallAfter(func/meth) to call the func/meth from the main thread.

I have had some really really really odd behavior with extremely cryptic errors like what you are having or no errors at all just strange random behavior. so this is worth a shot as well and even if it doesn't fix it I would leave it because it's good to get into this habit any time you are dealing with the Windows API.
Thanks for the tip. It didn't help me with the iTunes plugin (I still get the same error), but I'll still keep it in mind for this and other plugins.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
kgschlosser
Site Admin
Posts: 3111
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: New iTunes plugin thread (latest version: v0.1.16)

Post by kgschlosser » Thu Sep 28, 2017 2:42 am

I guess you are going to force my hand on this. I am going to have to break down and install iTunes ACK!.. I know there has to be a solution and it is going to be far easier for me to simply try and fail and try and fail and try some more.
If you like the work I have been doing then feel free to Image

Post Reply