diff --git a/trunk/config/backend.xml b/trunk/config/backend.xml
index ffa05a3..e053e80 100644
--- a/trunk/config/backend.xml
+++ b/trunk/config/backend.xml
@@ -27,10 +27,11 @@
240
1080
320
- 204800
+ 86388736
512
6000
64
+ 120
diff --git a/trunk/locale/en-us.xml b/trunk/locale/en-us.xml
index e12eb59..1bbde61 100755
--- a/trunk/locale/en-us.xml
+++ b/trunk/locale/en-us.xml
@@ -69,6 +69,8 @@
Cannot read video file
File is not a video
Video has already been uploaded
+ The filesize of the video you uploaded is too small
+ The filesize of the video you uploaded is too big
diff --git a/trunk/upload.pl b/trunk/upload.pl
index 82e75e7..e56d28b 100644
--- a/trunk/upload.pl
+++ b/trunk/upload.pl
@@ -36,7 +36,7 @@ if($userinfo->{'username'})
$subject =~ s/\s*$//;
$page->{'uploadform'}->{'DC.Subject'} = $subject;
- if($query->param('DC.Title')&&$query->param('DC.Subject')&&$query->param('DC.Description'))
+ if($query->param('DC.Title')&&$subject&&$query->param('DC.Description'))
{
$page->{'results-listing'} = [''];
diff --git a/trunk/uploader.pl b/trunk/uploader.pl
index 3f7f65c..cc02437 100644
--- a/trunk/uploader.pl
+++ b/trunk/uploader.pl
@@ -41,135 +41,166 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
#save uploaded file into temppath
$upload_filehandle = $query->upload("file");
+
open(TEMPFILE, ">/tmp/$id");
+ #check that nothing more than max filesize is being uploaded
while ( <$upload_filehandle> )
{
print TEMPFILE;
}
close TEMPFILE;
- $info = `export SDL_VIDEODRIVER="dummy"; ffplay -stats -an -vn -nodisp /tmp/$id 2>&1`;
-
- if($info =~ /ignoring/)
+ #check if file is too small or too big
+ if( -s "/tmp/$id" < $config->{"video_filesize_min"})
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
unlink "/tmp/$id";
- print $query->redirect("index.pl?error=error_upload_invalid_stream");
+ print $query->redirect("index.pl?error=error_upload_file_too_small&value=".$config->{"video_filesize_min"});
}
- elsif ($info =~ /I\/O error occured/)
+ elsif( -s "/tmp/$id" > $config->{"video_filesize_max"})
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
unlink "/tmp/$id";
- print $query->redirect("index.pl?error=error_upload_io");
- }
- elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/)
- {
- #delete from uploaded table
- $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
- unlink "/tmp/$id";
- print $query->redirect("index.pl?error=error_upload_not_a_video");
+ print $query->redirect("index.pl?error=error_upload_file_too_big&value=".$config->{"video_filesize_max"});
}
else
{
- $sha = new Digest::SHA(256);
- $sha->addfile("/tmp/$id");
- $sha = $sha->hexdigest;
+ $info = `export SDL_VIDEODRIVER="dummy"; ffplay -stats -an -vn -nodisp /tmp/$id 2>&1`;
- #check if this hash is already in database
- my $sth = $dbh->prepare(qq{select id from videos where hash = ? limit 1}) or die $dbh->errstr;
- $sth->execute($sha) or die $dbh->errstr;
- my ($resultid) = $sth->fetchrow_array();
- $sth->finish() or die $dbh->errstr;
-
- #if so, then video is a duplicate (alternatively ALL HAIL QUANTUM COMPUTING)
- if($resultid)
+ if($info =~ /ignoring/)
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
unlink "/tmp/$id";
- print $query->redirect("index.pl?error=error_upload_duplicate");
+ print $query->redirect("index.pl?error=error_upload_invalid_stream");
+ }
+ elsif ($info =~ /I\/O error occured/)
+ {
+ #delete from uploaded table
+ $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
+ unlink "/tmp/$id";
+ print $query->redirect("index.pl?error=error_upload_io");
+ }
+ elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/)
+ {
+ #delete from uploaded table
+ $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
+ unlink "/tmp/$id";
+ print $query->redirect("index.pl?error=error_upload_not_a_video");
}
else
{
- ($container, $duration) = $info =~ /Input \#0, (\w+),.+?\n.+?Duration: (\d{2}:\d{2}:\d{2}\.\d)/;
+ $sha = new Digest::SHA(256);
+ $sha->addfile("/tmp/$id");
+ $sha = $sha->hexdigest;
- #these two regexes have to be applied seperately because nobody knows which stream (audio or video) comes first
- ($audio) = $info =~ /Audio: (\w+)/;
- ($video, $width, $height, $fps) = $info =~ /Video: ([\w\d]+),.+?(\d+)x(\d+),.+?(\d+\.\d+) fps/;
+ #check if this hash is already in database
+ my $sth = $dbh->prepare(qq{select id from videos where hash = ? limit 1}) or die $dbh->errstr;
+ $sth->execute($sha) or die $dbh->errstr;
+ my ($resultid) = $sth->fetchrow_array();
+ $sth->finish() or die $dbh->errstr;
- if(!$video or !$duration)
+ #if so, then video is a duplicate (alternatively ALL HAIL QUANTUM COMPUTING)
+ if($resultid)
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
unlink "/tmp/$id";
- print $query->redirect("index.pl?error=error_upload_invalid_stream");
+ print $query->redirect("index.pl?error=error_upload_duplicate");
}
else
{
- $filesize = -s "/tmp/$id";
+ ($container, $duration) = $info =~ /Input \#0, (\w+),.+?\n.+?Duration: (\d{2}:\d{2}:\d{2}\.\d)/;
- #convert hh:mm:ss.s duration to full seconds - thanks perl for making this so damn easy!
- #don't want to know how this would look in python or php... hell I don't even have to create extra variables!
- $duration =~ /^(\d{2}):(\d{2}):(\d{2})\.(\d)$/;
- $duration = int($1*3600 + $2*60 + $3 + $4/10 + .5);
+ #these two regexes have to be applied seperately because nobody knows which stream (audio or video) comes first
+ ($audio) = $info =~ /Audio: (\w+)/;
+ ($video, $width, $height, $fps) = $info =~ /Video: ([\w\d]+),.+?(\d+)x(\d+),.+?(\d+\.\d+) fps/;
- #create thumbnail
- $thumbnailsec = int(rand($duration));
- $previewsec = $thumbnailsec;
-
- #the width/height calculation could of course be much shorter but less readable then
- #all thumbs have equal height
- $tnmaxheight = 120;
- $tnheight = $tnmaxheight;
- $tnwidth = int($tnheight*($width/$height)/2 + .5)*2;
-
- $ffthumb = system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $thumbnailsec -s ".$tnwidth."x$tnheight $root/video-stills/thumbnails/$id";
- $ffprev = system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $previewsec $root/video-stills/previews/$id";
-
- #if thumbnail was created successfully
- if($ffthumb == 0 and $ffprev == 0)
- {
- $vmaxheight = 640;
-
- #check if the upload already is in the right format and smaller/equal max-width/height
- if ($container eq 'ogg' and $video eq 'theora' and ($audio eq 'vorbis' or not $audio) and $height <= $vmaxheight)
- {
- if(move("/tmp/$id", "$root/videos/$id"))
- {
- #add video to videos table
- $dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
- subject, source, language, coverage, rights, license, ?, ?, ?, ?, ?, ?, 0, 0
- from uploaded where id = ?}, undef, $filesize, $duration, $width,
- $height, $fps, $sha, $id) or die $dbh->errstr;
-
- #delete from uploaded table
- $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
- }
- else
- {
- #delete from uploaded table
- $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
- die "cannot move video to $root/videos/$id - check your permissions!"
- }
- }
- else
- {
- #write all valueable information to database so the daemon can fetch it
- $dbh->do(qq{update uploaded set filesize = ?, duration = ?, width = ?,
- height = ?, fps = ?, hash = ? where id = ?}, undef, $filesize, $duration, $width,
- $height, $fps, $sha, $id) or die $dbh->errstr;
- }
-
- #print success to the user
- print $query->redirect("index.pl?information=information_uploaded&value=".$config->{"url_root"}."/video/".urlencode($query->param("DC.Title"))."/$id/");
- }
- else
+ if(!$video or !$duration)
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
- die "cannot create thumbnails - check your permissions!";
+ unlink "/tmp/$id";
+ print $query->redirect("index.pl?error=error_upload_invalid_stream");
+ }
+ elsif($width < $config->{"video_width_min"})
+ {
+ #delete from uploaded table
+ $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
+ unlink "/tmp/$id";
+ print $query->redirect("index.pl?error=error_upload_video_width_too_small&value=".$config->{"video_width_min"});
+ }
+ elsif($height < $config->{"video_height_min"})
+ {
+ #delete from uploaded table
+ $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
+ unlink "/tmp/$id";
+ print $query->redirect("index.pl?error=error_upload_video_height_too_small&value=".$config->{"video_height_min"});
+ }
+ else
+ {
+ $filesize = -s "/tmp/$id";
+
+ #convert hh:mm:ss.s duration to full seconds - thanks perl for making this so damn easy!
+ #don't want to know how this would look in python or php... hell I don't even have to create extra variables!
+ $duration =~ /^(\d{2}):(\d{2}):(\d{2})\.(\d)$/;
+ $duration = int($1*3600 + $2*60 + $3 + $4/10 + .5);
+
+ #create thumbnail
+ $thumbnailsec = int(rand($duration));
+ $previewsec = $thumbnailsec;
+
+ #the width/height calculation could of course be much shorter but less readable then
+ #all thumbs have equal height
+ $tnheight = $config->{"video_thumbnail_height"};
+ $tnwidth = int($tnheight*($width/$height)/2 + .5)*2;
+
+ $ffthumb = system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $thumbnailsec -s ".$tnwidth."x$tnheight $root/video-stills/thumbnails/$id";
+ $ffprev = system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $previewsec $root/video-stills/previews/$id";
+
+ #if thumbnail was created successfully
+ if($ffthumb == 0 and $ffprev == 0)
+ {
+ #check if the upload already is in the right format and smaller/equal max-width/height
+ if ($container eq 'ogg' and $video eq 'theora' and ($audio eq 'vorbis' or not $audio) and $height <= $config->{"video_height_max"} and $width <= $config->{"video_width_max"})
+ {
+ if(move("/tmp/$id", "$root/videos/$id"))
+ {
+ #add video to videos table
+ $dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
+ subject, source, language, coverage, rights, license, ?, ?, ?, ?, ?, ?, 0, 0
+ from uploaded where id = ?}, undef, $filesize, $duration, $width,
+ $height, $fps, $sha, $id) or die $dbh->errstr;
+
+ #delete from uploaded table
+ $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
+ }
+ else
+ {
+ #delete from uploaded table
+ $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
+ die "cannot move video to $root/videos/$id - check your permissions!"
+ }
+ }
+ else
+ {
+ #write all valueable information to database so the daemon can fetch it
+ $dbh->do(qq{update uploaded set filesize = ?, duration = ?, width = ?,
+ height = ?, fps = ?, hash = ? where id = ?}, undef, $filesize, $duration, $width,
+ $height, $fps, $sha, $id) or die $dbh->errstr;
+ }
+
+ #print success to the user
+ print $query->redirect("index.pl?information=information_uploaded&value=".$config->{"url_root"}."/video/".urlencode($query->param("DC.Title"))."/$id/");
+ }
+ else
+ {
+ #delete from uploaded table
+ $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
+ die "cannot create thumbnails - check your permissions!";
+ }
}
}
}
@@ -177,5 +208,5 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
}
else
{
- print $query->redirect("index.pl?error=error_202c");
+ #print $query->redirect("index.pl?error=error_202c");
}