After scouring the net for free webcam recording programs, I came up with pretty much a whole lotta nothin. Keep in mind, I don't mean a program to record my own webcam; I mean something that will record images from a cam already on the net, saving them for me to view at a later time, since I have better things to do than to watch an image refresh in a browser window every 10 seconds waiting for something interesting to happen. I know there's some good programs out there that'll do this, but they seem to be all shareware and such now. I'm not paying for something I probably won't use for more than a week before getting tired of it.
So I put Perl to use! It's not only great for web programming, but I've found myself using it many a time just for small projects and tasks on my own computer. The version for Windows is called ActivePerl, which is free and works great, especially when it comes to testing software before I put it up on a website.
I initially wrote a really simple script using a module already included: LWP::Simple. This lets you easily fetch pages and files off of the web for use in the program. Here's what I started out with:
#!/usr/bin/perl
use LWP::Simple;
startagain:
getstore('http://media.g4techtv.com/images/webcam/tss/sarah.jpg', 'images/sarah' . time() . '.jpg');
sleep 10;
goto startagain;
For this example, it's using Sarah Lane's (of TechTV/G4 fame) cam. It saves the current image into the "images" folder from there, named "sarah4302434.jpg", where the numbers make up the unix time stamp of when it was captured. It waits 10 seconds, and does it again. This way I save every picture, and can go back later to look for something non-boring, and baleet the rest.
The problem with this is that it was keeping a console window open, since Perl is in fact a console application. So I found out about the Win32::GUI module, which allows one to create windows and tray icons and the like. I didn't need anything that fancy, just one feature in particular: the ability to hide a window. So with a little extra code, I was able to hide the console window, letting it run in the background and save cam shots every 10 seconds without me seeing.
Then I realized I needed some way of stopping it without killing the task every time. So I used a pretty simple method, where it creates a file called process.txt when it starts, and looks for this file at every loop. If it exists, the loop continues. If not, it unhides the console window and exits. This means all you have to do is delete process.txt from the directory it's running from to make it exit. Works perfect!
#!/usr/bin/perl
use LWP::Simple;
use Win32::GUI;
my ($DOS) = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);
open (PROCFILE, "> process.txt");
print PROCFILE 1;
close (PROCFILE);
startagain:
getstore('http://media.g4techtv.com/images/webcam/tss/sarah.jpg', 'images/sarah' . time() . '.jpg');
sleep 10;
if (-e 'process.txt') { goto startagain; }
Win32::GUI::Show($DOS);
So any other Perl users who were interested in webcams can feel free to steal the code. Just change the url and filename it's using for whatever cam you want (unless you wanted to watch Sarah Lane all along!). You could also add in extra getstore lines to fetch multiple cams. Put'em in seperate directories though for easy sorting.