Checking for new podcasts at a specific time in iTunes (Windows)

As far as I can tell, you can't tell iTunes when you want to check for new podcast episodes – it simply adds the periodic time (e.g. 24 hours) to the last time a check was done.

My ISP has changed their broadband usage system so that half of my monthly transfer allowance is "off-peak" (from next month, 2am to 10am). This really doesn't suit me well, as I typically spend only about an hour to two hours (8am or 9am to 10am) of this time online, so what I end up with is a huge chunk of unused allowance, and maxing out my "peak" allowance.

I don't want to change my habits so that I schedule everything for download. The point of having broadband was that I got what I wanted when I wanted it. The exception to this is podcasts, which are all time-shifted anyway, so I don't care when they download. They also account for a reasonable portion of my downloads (in terms of size – particularly the two video podcasts). So I really want these to download these around 4am.

One way to do this would be to get up at 4am one day and manually update. However, I like my sleep. That also means that if I ever decided to 'check now', I'd have to redo this.

So, my solution is to write a little Python script that tells iTunes (via COM) to update all podcasts, set iTunes to only update manually, and have Windows run this Python script as a scheduled task. If you want to do anything with this script, help yourself (it's really only 6 lines).

#! /usr/bin/env python
"""Tell iTunes to update all podcasts."""
import win32com
import pythoncom
import win32com.client

def main():
    pythoncom.CoInitialize()
    app = "iTunes.Application"
    iTunes = win32com.client.Dispatch(app)
    iTunes.UpdatePodcastFeeds()

if __name__ == "__main__":
    main()

technorati tags: , ,

Advertisements

4 responses to this post.

  1. Posted by Carl on August 13, 2006 at 8:38 pm

    I was just about to write this myself; thanks!

    I didn’t see anything exposed in the COM interface to determine when the podcast updates are done, so I’ve created a script to quit iTunes as well (same as yours except “iTunes.Quit()” as the last line of main(). I’ve set up Windows Scheduler to run the update script at 4 am, then the quit script at 5 am. There may be a cleaner way to do this; this is my first experience with the iTunes COM interface.

    Anyway, thanks again, saved me some trouble!

  2. No worries – glad it was some use!

    I have iTunes running pretty much all the time on the machine that does the podcast retrieval, so didn’t need the Quit() myself. Really, it ought to check if iTunes is running to start with, and then Quit() if it wasn’t, but I’ve wanted to do similar for other things in the past and haven’t managed to figure out how to do that (via COM).

    I’m not sure if it’s possible to figure out if the update is done or not (Apple does publish information about the COM interface, or PythonWin will let you browse it in a very raw way). Waiting for a suitable amount of time ought to work well enough, though.

  3. Posted by Carl on August 14, 2006 at 7:01 pm

    Regarding determining if iTunes is running, here is one way to do it:

    ——-
    #! /usr/bin/env python
    “””Quit iTunes if running.”””
    import win32com
    import pythoncom
    import win32com.client
    imort win32gui

    def main():
    try:
    # this will throw an exception if the window is not found:
    win32gui.FindWindow(“iTunes”, “iTunes”)
    pythoncom.CoInitialize()
    app = “iTunes.Application”
    iTunes = win32com.client.Dispatch(app)
    iTunes.UpdatePodcastFeeds()
    iTunes.Quit()
    except:
    pass

    if __name__ == “__main__”:
    main()

    ——-

    I’ve modified my script to do this and it appears to work. Not really a general-purpose solution, but it works for iTunes. I used CowSpy to get the window classname.

    I didn’t see anything in the docs about explicitly getting notified when podcast updates are done. Perhaps there is and I didn’t see it, or maybe there is a roundabout way to determine it. But in my case I can’t imagine the update process ever taking more than about 5 minutes, as I don’t subscribe to that many podcasts and the script will be run every night. So I’m pretty happy with what I have. 🙂

  4. Posted by Carl on August 14, 2006 at 7:07 pm

    Ack, looks like my formatting didn’t carry over; maybe this will work. If not, sorry for the double post!


    #! /usr/bin/env python
    """Quit iTunes if running."""
    import win32com
    import pythoncom
    import win32com.client
    imort win32gui

    def main():
    try:
    # this will throw an exception if the window is not found:
    win32gui.FindWindow("iTunes", "iTunes")
    pythoncom.CoInitialize()
    app = "iTunes.Application"
    iTunes = win32com.client.Dispatch(app)
    iTunes.UpdatePodcastFeeds()
    iTunes.Quit()
    except:
    pass

    if __name__ == "__main__":
    main()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: