#!/usr/bin/perl -wT # bttvgrab 0.13.1 [1998-07-30] # (c) 1998 by Joerg Walter <trouble@moes.pmnet.uni-oldenburg.de> # (c) 1997,1998 by Adam Kopacz <Adam.K@idnet.de> # Maintained by: Joerg Walter # Current version at http://moes.pmnet.uni-oldenburg.de/bttvgrab/ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # directory of temporary files $BTTVDIR = "/tmp/bttvgrab"; # file to show when not grabbing $OFFIMG = "tv_off.jpg"; $OFFTYPE = "jpeg"; $WIDTH = 320; $HEIGHT = 240; $REFRESH = 1; #see also end of document for widht/height statements # end configuration if ($ENV{'QUERY_STRING'} eq "") { print "HTTP/1.0 200 OK\n"; $agent = $ENV{'HTTP_USER_AGENT'}; $TYPE = "run"; $REFRESHT = ""; if ($agent =~ m/Mozilla/) { if ($agent =~ m/compatible/ or substr($agent,8,1) < 2) { $TYPE = "one"; $REFRESHT = "<meta http-equiv=\"refresh\" content=\"$REFRESH\">"; } } print "Content-type: text/html\n"; print "\n"; while (<DATA>) { s/\@WIDTH\@/$WIDTH/; s/\@HEIGHT\@/$HEIGHT/; s/\@TYPE\@/$TYPE/; s/\@REFRESH\@/$REFRESHT/; print; } exit(0); } sub cat { local $CATFILE; open(CATFILE,shift); print <CATFILE>; close(CATFILE); } # test if grabbing... if (not (-d "$BTTVDIR" and -p "$BTTVDIR/status" and -f "$BTTVDIR/format")) { print "HTTP/1.0 200 OK\n"; print "Pragma: no-cache\n"; print "Expires: now\n"; print "Content-type: image/$OFFTYPE\n"; print "\n"; cat($OFFIMG); exit 0; } $| = 1; # yes, web-tv is active open(FORMFILE,"$BTTVDIR/format"); $TYPE=<FORMFILE>; close(FORMFILE); if ("$TYPE" eq "jpg") { $TYPE="jpeg"; } else { if ("$TYPE" eq "gif") { $TYPE="gif"; } else { $TYPE="x-$TYPE"; } } if ($ENV{'QUERY_STRING'} eq "one") { print "HTTP/1.0 200 OK\n"; print "Pragma: no-cache\n"; print "Expires: now\n"; print "Content-type: image/$TYPE\n"; print "\n"; cat("$BTTVDIR/image"); exit 0; } print "HTTP/1.0 200 OK\n"; print "Pragma: no-cache\n"; print "Expires: now\n"; print "Content-type: multipart/x-mixed-replace;boundary=--this-is-a-random-boundary-created-by-bttvgrab\n"; print "\n"; print "--this-is-a-random-boundary-created-by-bttvgrab\n"; open(STATUS,"<$BTTVDIR/status"); open(STATUS_LOCK,"<$BTTVDIR/status-lock"); $MASK = ''; vec($MASK,fileno(STATUS),1) = 1; $MASK_LOCK = ''; vec($MASK_LOCK,fileno(STATUS_LOCK),1) = 1; $NO = ''; vec($NO,fileno(STATUS),1) = 0; print "Content-type: image/$TYPE\n"; print "\n"; cat("$BTTVDIR/image"); print "\n--this-is-a-random-boundary-created-by-bttvgrab\n"; while (-f "$BTTVDIR/format") { $read = $MASK_LOCK; $write = $NO; $error = $NO; $n = select($read,$write,$error,undef); $read = $MASK; $write = $NO; $error = $NO; $n = select($read,$write,$error,undef); print "Content-type: image/$TYPE\n"; print "\n"; cat("$BTTVDIR/image"); print "\n--this-is-a-random-boundary-created-by-bttvgrab\n"; } print "Content-type: image/$OFFTYPE\n"; print "\n"; cat($OFFIMG); print "\n--this-is-a-random-boundary-created-by-bttvgrab\n"; close(STATUS); close(STATUS_LOCK); exit 0; __END__ <HTML><HEAD>@REFRESH@<TITLE>bttvgrab WebCam</TITLE></HEAD> <BODY BGCOLOR="black" TEXT="black" LINK="blue" VLINK="blue" ALINK="red"> <DIV ALIGN=CENTER> <P>><IMG SRC="../images/bttvgrab.jpg"></P> <P><TABLE BORDER=0 BGCOLOR=white CELLPADDING=1><TR><TD><IMG SRC="nph-webcam.pl?@TYPE@" WIDTH="@WIDTH@" HEIGHT="@HEIGHT@" ALT="-bttvgrab WebCam Picture-"></TD></TD></TABLE></P> <P><A HREF="http://moes.pmnet.uni-oldenburg.de/bttvgrab">Get bttvgrab here</A></P> </DIV> </BODY></HTML>