2007-10-20 22:37:52 +00:00
|
|
|
require "functions.pl";
|
|
|
|
|
2007-10-24 13:17:31 +00:00
|
|
|
#initialize session data
|
2008-04-15 18:56:13 +00:00
|
|
|
CGI::Session->name($config->{"page_cookie_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'))
|
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
#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())
|
2008-04-11 08:45:54 +00:00
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
#are we only watching this video or downloading it?
|
|
|
|
if($query->param('view'))
|
|
|
|
{
|
|
|
|
#seems we only want to watch it - update viewcount
|
|
|
|
$dbh->do(qq{update videos set viewcount=viewcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#video is being downloaded - update downloadcount
|
|
|
|
$dbh->do(qq{update videos set downloadcount=downloadcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#in both cases - do some slurp-eaze to the browser
|
2008-04-06 21:23:59 +00:00
|
|
|
$file = open(FILE, "<$root/videos/".$query->param('id'));
|
2008-02-14 22:15:38 +00:00
|
|
|
|
2008-04-01 16:16:04 +00:00
|
|
|
if($file)
|
2008-02-14 22:15:38 +00:00
|
|
|
{
|
2008-04-01 16:16:04 +00:00
|
|
|
$filesize = -s "$root/videos/".$query->param('id');
|
|
|
|
$range = $query->http('range');
|
|
|
|
$range =~ s/bytes=([0-9]+)-/$1/;
|
|
|
|
|
|
|
|
#if a specific range is requested send http partial content headers and seek in the inputfile
|
|
|
|
if($range)
|
2008-02-14 22:15:38 +00:00
|
|
|
{
|
2008-04-01 16:16:04 +00:00
|
|
|
#if $range is equal or more than filesize throw http 416 header
|
|
|
|
if($range >= $filesize)
|
|
|
|
{
|
|
|
|
print $query->header(-status=>'416 Requested Range Not Satisfiable');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print $query->header(-type=>'application/ogg',
|
|
|
|
-content_length=> $filesize-$range,
|
|
|
|
-status=>'206 Partial Content',
|
|
|
|
-attachment=>$title.".ogv",
|
|
|
|
-accept_ranges=> "bytes",
|
|
|
|
-content_range=> "bytes $range-".($filesize-1)."/$filesize"
|
|
|
|
);
|
|
|
|
|
|
|
|
seek FILE, $range, 0;
|
|
|
|
}
|
2008-02-14 22:15:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print $query->header(-type=>'application/ogg',
|
2008-04-01 16:16:04 +00:00
|
|
|
-content_length=> $filesize,
|
|
|
|
-attachment=>$title.".ogv"
|
2008-02-14 22:15:38 +00:00
|
|
|
);
|
|
|
|
}
|
2008-04-01 16:16:04 +00:00
|
|
|
|
|
|
|
while (my $BytesRead = read (FILE, $buff, 8192))
|
|
|
|
{
|
|
|
|
print $buff;
|
|
|
|
}
|
|
|
|
close(FILE);
|
2008-02-14 22:15:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-01 16:16:04 +00:00
|
|
|
print $session->header(
|
|
|
|
-status=>'500 Internal Server Error'
|
|
|
|
)
|
2008-02-14 22:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-01 16:16:04 +00:00
|
|
|
print $session->header(
|
|
|
|
-status=>'404 Not found'
|
|
|
|
)
|
2008-02-14 22:15:38 +00:00
|
|
|
}
|
2007-10-20 22:37:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
@userinfo = get_userinfo_from_sid($session->id);
|
2007-10-29 15:00:40 +00:00
|
|
|
|
2008-02-14 22:15:38 +00:00
|
|
|
@page = get_page_array(@userinfo);
|
|
|
|
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_202c";
|
|
|
|
|
|
|
|
print output_page();
|
2007-10-20 22:37:52 +00:00
|
|
|
}
|