2007-10-20 22:37:52 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
require "include.pl";
|
|
|
|
require "functions.pl";
|
|
|
|
|
2007-10-24 13:17:31 +00:00
|
|
|
#initialize session data
|
|
|
|
CGI::Session->name($session_name);
|
2007-10-20 22:37:52 +00:00
|
|
|
$query = new CGI;
|
2007-10-24 13:17:31 +00:00
|
|
|
$session = new CGI::Session;
|
2007-10-20 22:37:52 +00:00
|
|
|
|
|
|
|
#do we have an id?
|
|
|
|
if($query->param('id'))
|
|
|
|
{
|
|
|
|
#connect to db
|
|
|
|
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
|
|
|
|
|
|
|
|
#check if video with requested id is in the database
|
|
|
|
my $sth = $dbh->prepare(qq{select title from videos where id = ? });
|
|
|
|
$sth->execute($query->param('id'));
|
|
|
|
|
|
|
|
if(($title) = $sth->fetchrow_array())
|
|
|
|
{
|
2007-10-21 22:28:02 +00:00
|
|
|
#if referer is not the local site update referer table
|
|
|
|
$referer = $query->referer() or $referer = '';
|
|
|
|
$server_name = $query->server_name();
|
|
|
|
if($referer !~ /^\w+:\/\/$server_name/)
|
|
|
|
{
|
|
|
|
#check if already in database
|
|
|
|
$sth = $dbh->prepare(qq{select 1 from referer where videoid = ? and referer = ? }) or die $dbh->errstr;
|
|
|
|
my $rowcount = $sth->execute($query->param('id'), $referer) or die $dbh->errstr;
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
|
|
|
|
if($rowcount > 0)
|
|
|
|
{
|
|
|
|
#video is in database - increase referercount
|
2007-10-24 11:25:18 +00:00
|
|
|
$dbh->do(qq{update referer set count=count+1 where videoid = ? and referer = ? },
|
|
|
|
undef, $query->param('id'), $referer) or die $dbh->errstr;
|
2007-10-21 22:28:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#add new referer
|
2007-10-24 11:25:18 +00:00
|
|
|
$dbh->do(qq{insert into referer (videoid, referer) values (?, ?) },
|
|
|
|
undef, $query->param('id'), $referer) or die $dbh->errstr;
|
2007-10-21 22:28:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-20 22:37:52 +00:00
|
|
|
#are we only watching this video or downloading it?
|
|
|
|
if($query->param('view'))
|
|
|
|
{
|
|
|
|
#seems we only want to watch it - update viewcount
|
2007-10-24 11:25:18 +00:00
|
|
|
$dbh->do(qq{update videos set viewcount=viewcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
2007-10-20 22:37:52 +00:00
|
|
|
|
|
|
|
print $query->header(-type=>'application/ogg');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#video is being downloaded - update downloadcount
|
2007-10-24 11:25:18 +00:00
|
|
|
$dbh->do(qq{update videos set downloadcount=downloadcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
2007-10-20 22:37:52 +00:00
|
|
|
|
|
|
|
print $query->header(-type=>'application/x-download',
|
2007-10-22 09:45:26 +00:00
|
|
|
-attachment=>$title.".ogv");
|
2007-10-20 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#in both cases - do some slurp-eaze to the browser
|
|
|
|
open(FILE, "<$gnutube_root/videos/".$query->param('id'));
|
|
|
|
print <FILE>;
|
|
|
|
close(FILE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-24 11:25:18 +00:00
|
|
|
#there is no video with this id
|
2007-10-21 22:55:29 +00:00
|
|
|
%page = ();
|
|
|
|
|
|
|
|
$page->{'username'} = get_username_from_sid($session->id);
|
|
|
|
$page->{'locale'} = $locale;
|
|
|
|
$page->{'stylesheet'} = $stylesheet;
|
|
|
|
$page->{'xmlns:dc'} = $xmlns_dc;
|
|
|
|
$page->{'xmlns:cc'} = $xmlns_cc;
|
|
|
|
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
|
|
|
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_202c";
|
|
|
|
|
|
|
|
#print xml http header along with session cookie
|
2007-10-26 17:42:03 +00:00
|
|
|
print $session->header(-type=>'text/xml', -charset=>'UTF-8');
|
2007-10-21 22:55:29 +00:00
|
|
|
|
|
|
|
#print xml
|
|
|
|
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page');
|
2007-10-20 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#disconnect db
|
|
|
|
$dbh->disconnect();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-21 22:55:29 +00:00
|
|
|
%page = ();
|
|
|
|
|
|
|
|
#if a username is associated with session id, username is nonempty
|
|
|
|
$page->{'username'} = get_username_from_sid($session->id);
|
|
|
|
$page->{'locale'} = $locale;
|
|
|
|
$page->{'stylesheet'} = $stylesheet;
|
|
|
|
$page->{'xmlns:dc'} = $xmlns_dc;
|
|
|
|
$page->{'xmlns:cc'} = $xmlns_cc;
|
|
|
|
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
|
|
|
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_202c";
|
|
|
|
|
|
|
|
#print xml http header along with session cookie
|
2007-10-26 17:42:03 +00:00
|
|
|
print $session->header(-type=>'text/xml', -charset=>'UTF-8');
|
2007-10-21 22:55:29 +00:00
|
|
|
|
|
|
|
#print xml
|
|
|
|
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page');
|
2007-10-20 22:37:52 +00:00
|
|
|
}
|