How to schedule iTunes to download Podcasts on Windows

I use iTunes on Windows only because I have to. I don't really care for it as a music organizer and besides, I rarely listen to music on my computer. I have an iPod though and what I do like about iTunes is that I can just plug in my iPod and it will automatically sync everything without any intervention from me. I also like that iTunes allows me to subscribe to podcasts. It annoys me though that unless I have iTunes running it will not update my podcast subscriptions. Since I only use iTunes for syncing my iPod, iTunes is never running.

Luckily iTunes has an COM automation interface that you can use to force it to update your podcasts. With a bit of PowerShell scripting I am now able to automatically update all of my podcasts in the middle of the night when I don't have to be bothered with the fact that iTunes is running. I used PowerShell for this scripting task as again, it seems perfect for a task like this.

My script is a little more complicated than just starting up iTunes and then starting the podcast downloads. Since I am scheduling this process to run nightly I also wanted to be able to close iTunes once it was finished. Unfortunately the iTunes COM automation interface provides no way to tell whether or not iTunes is busy downloading new podcasts. However it seems that iTunes creates a pretty predictable temporary download folder structure, which it then removes when it has finished downloading all of the podcasts that it updates. I used this bit of knowledge in my script to detect when iTunes was busy downloading new podcasts. I just watch for those directories, waiting for iTunes to finish and then I shut down iTunes. So far this has worked pretty well although I'm sure it is not complete robust under all circumstances.

Here is the PowerShell script I developed. If you want to use it you'll have to tweak the directory path that is checkedĀ in the script to match your computer. I should also mention that on at least one of my machines iTunes creates the temporary 'downloads\podcast' directory in a different place under the iTunes music folder. I have not found a setting in iTunes that determines where the temporary folder gets created so you may have to poke around a little while iTunes is downloading podcast updates to figure out where it is on your machine if this does not work.

# update iTunes pod casts function test-Downloading { if(test-path 'C:\Documents and Settings\MusicBox\My Documents\My Music\iTunes\iTunes Music\Downloads\Podcasts') { return $True } return $False } $iTunes = new-Object -comobject iTunes.Application if($iTunes -ne $null) { 'iTunes started' | out-Host # start iTunes podcasts update 'updating podcasts' | out-Host $iTunes.UpdatePodcastFeeds() # set a time out time $TimeOut = (get-Date).AddMinutes(30) # wait a few minutes and check if it is downloading 'waiting for downloads to start...' | out-Host start-sleep (30) # loop while iTunes seems to be downloading (presence of temporary download folder) 'checking for download activity' | out-Host while(test-Downloading -and ((get-Date) -lt $TimeOut)) { # give it some more time 'download activity detected, waiting...' | out-Host start-sleep (60) } if((get-Date) -ge $TimeOut) { 'downloading timed-out' | out-Host } # now quit iTunes after a little settling time start-Sleep (30) 'quitting iTunes' | out-Host $iTunes.Quit() $iTunes = $null }
del.icio.us tags: , , ,

Print | posted on Thursday, November 30, 2006 1:31 PM

Feedback

# re: How to schedule iTunes to download Podcasts on Windows

Left by Fortezza at 1/28/2007 12:47 PM
Gravatar This looks interesting. Assuming that have .Net 2.0, how would I run this script? Do I just save it as a certain extension, edit the paths, and then double-click on it? If so, what is that extension?

Thank You,

Fortezza

# re: How to schedule iTunes to download Podcasts on Windows

Left by David Jade at 1/29/2007 10:36 AM
Gravatar First you'll have to install the PowerShell scripting language, which is separate from .Net 2.0. You can get this free from Microsoft.

Then once you have fixed up the paths in the above scrip, you can use PowerShell to launch the script, which should be saved as a .PS1 file. Note that by default PowerShell will not execute a script when you double-click on it. You have to set up a file association to do that. There is another article on my blog for how to set this up:
http://mutable.net/blog/archive/2006/10/05/PowerTips-for-PowerShell.aspx

Also I should note that the current version of iTunes seems to crash if it is launched from a script while the screen saver is running. The simple solution is to disable or stop the screen saver if you want to run this script from a scheduled task.

david

# re: How to schedule iTunes to download Podcasts on Windows

Left by Nazar at 4/25/2007 9:02 PM
Gravatar How would you tell Itunes to download _ALL_ podcasts, not only latest available?

# re: How to schedule iTunes to download Podcasts on Windows

Left by Pierre Poquet at 12/19/2007 4:36 PM
Gravatar You might want to mention that by default powershell includes something called execution policy and that policy is set by default to restricted.
You need to open powershell and type
Set-ExecutionPolicy RemoteSigned
if you want your script to run.

Once I did that your code ran like a charm.
Thank you
Pierre

Your comment:





 
Please add 4 and 4 and type the answer here:

Copyright © David Jade

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski