Archive for January, 2008

Automated webcam capture/image downloader

Wednesday, January 2nd, 2008

The other day I was checking out a webcam at a local ski resort, and wanted to see what an entire day’s worth of shots looked like played in a movie. I’m sure there are apps out there that do this sort of thing, and might even be an easier way of doing this. Regardless, I decided to have a play.

Below is a simple VB Script file (sorry windowless folks) that will download and save an image to your hard drive. It will save the images in the same directory the script is running.

Dim imageURL
imageURL = "http://www.mtbachelor.com/@@/cams/wvskycam.jpg"
Function SaveBinaryData(FileName, ByteArray)
	Const adTypeBinary = 1
	Const adSaveCreateOverWrite = 2
	Dim BinaryStream
	Set BinaryStream = CreateObject("ADODB.Stream")
	BinaryStream.Type = adTypeBinary
	BinaryStream.Open
	BinaryStream.Write ByteArray
	BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
Function BinaryGetURL(URL)
	Dim Http
	Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
	Http.Open "GET", URL, False
	Http.Send
	BinaryGetURL = Http.ResponseBody
End Function
Function doSave()
	Dim image, fName, p_month, p_day, p_hour, p_minute, p_second
	image = BinaryGetURL(imageURL)
	p_month = padZero(Month(Now))
	p_day = padZero(Day(Now))
	p_hour = padZero(Hour(Now))
	p_minute = padZero(Minute(Now))
	p_second = padZero(Second(Now))
	fName = p_month & "_" & p_day & "_" & Year(Now) & "-" & p_hour & "_" & p_minute & "_" & p_second & ".jpg"
	SaveBinaryData fName,image
End Function
Function padZero(val)
	If(Len(val) < 2) Then
		val = "0" & val
	End If
	padZero = val
End Function
doSave()

Copy and paste the above script into an empty text file. Go find a webcam you’d like to capture. When viewing the webcam image, right click and copy the images URL. Change the imageURL variable at the top of the script. Save the script (.vbs extension). Next you’ll need to set up an automated task to run the script. For help on how to set up tasks, check out this KB article. You’ll want to schedule it run somewhat frequently, but no more frequent than the webcam updates.

That’s pretty much all you need to do. If everything goes right, image files should start appearing in the directory that the script is located.

To create a movie from the sequence, you’ll need to find some software to do that. Out of sheer laziness, I just use QuickTime Pro, but there’s a bunch of shareware/freeware options available out there.

Have fun…