Author Topic: Free Webcam Watcher  (Read 29591 times)

FyberOptic

  • King of Earth
  • Administrator
  • Hero Member
  • *****
  • Posts: 2522
  • Oh god what is that?
    • Fybertech.com
Free Webcam Watcher
« on: May 04, 2005, 03:38:23 pm »
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:

Code: [Select]
#!/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! 

Code: [Select]
#!/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.

Professor Hazard

  • Jr. Member
  • **
  • Posts: 86
  • ^ ^ v v < > < > B A SNIPE
    • Snipe Hunt Media
Re: Free Webcam Watcher
« Reply #1 on: May 10, 2005, 11:46:40 am »
So much effort to watch a girl sit there and not get naked.

FyberOptic

  • King of Earth
  • Administrator
  • Hero Member
  • *****
  • Posts: 2522
  • Oh god what is that?
    • Fybertech.com
Re: Free Webcam Watcher
« Reply #2 on: May 10, 2005, 11:23:47 pm »
It probably only took 15 minutes to make overall, and I got to find out that she has a tattoo on her lower back when she bent over !1

I just play the images back for different cams (like one of a New York city block) really fast, so I can watch numerous hours in a couple of minutes time, looking for interesting things it captured.

Red_Raven

  • Guest
Re: Free Webcam Watcher
« Reply #3 on: October 11, 2005, 05:38:13 pm »
bah.. its prof

FyberOptic

  • King of Earth
  • Administrator
  • Hero Member
  • *****
  • Posts: 2522
  • Oh god what is that?
    • Fybertech.com
Re: Free Webcam Watcher
« Reply #4 on: March 21, 2009, 07:51:47 pm »
lawl, I was sorting topics after making the new UserJS section to put scripts in, and found this, which I had done forgot about.  More to the point, I can't believe I was interested in viewing a Sarah Lane webcam.  HOW THINGS CHANGE.  Though the code might still be useful to someone so I'll leave it up.

These days instead of the weird method of detecting the presence of a text file and deleting it to make the hidden process end, I'd create a system tray icon with the Win32::GUI library.  I used that method for a script proxy once and it works pretty well.