upload now works again - fixed daemon.pl

git-svn-id: http://yolanda.mister-muffin.de/svn@171 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2007-11-01 23:00:14 +00:00
parent 77eae53dc5
commit de6e466797
4 changed files with 235 additions and 26 deletions

View file

@ -5,16 +5,16 @@ use DBI;
use Digest::SHA; use Digest::SHA;
use File::Copy; use File::Copy;
$database = 'gnutube'; $database = 'yolanda';
$dbhost = 'localhost'; $dbhost = 'localhost';
$dbuser = 'root'; $dbuser = 'root';
$dbpass = ''; $dbpass = '';
$gnutube_root = '/var/www/gnutube'; $root = '/var/www/yolanda';
#TODO: deamonize by uncommenting this line #TODO: deamonize by uncommenting this line
#Proc::Daemon::Init; #Proc::Daemon::Init;
$LOG = "/var/www/gnutube/daemon.log"; $LOG = "$root/daemon.log";
sub appendlog sub appendlog
@ -53,7 +53,7 @@ while(1)
if($id) if($id)
{ {
$info = `ffplay -stats -an -vn -nodisp $gnutube_root/tmp/$id 2>&1`; $info = `ffplay -stats -an -vn -nodisp $root/tmp/$id 2>&1`;
if($info =~ /ignoring/) if($info =~ /ignoring/)
{ {
@ -61,7 +61,7 @@ while(1)
#write status 2 to uploaded table #write status 2 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr;
unlink "$gnutube_root/tmp/$id"; unlink "$root/tmp/$id";
} }
elsif ($info =~ /I\/O error occured/) elsif ($info =~ /I\/O error occured/)
{ {
@ -69,7 +69,7 @@ while(1)
#write status 3 to uploaded table #write status 3 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 3, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 3, $id) or interrupt $dbh->errstr;
unlink "$gnutube_root/tmp/$id"; unlink "$root/tmp/$id";
} }
elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/) elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/)
{ {
@ -77,12 +77,12 @@ while(1)
#write status 4 to uploaded table #write status 4 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 4, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 4, $id) or interrupt $dbh->errstr;
unlink "$gnutube_root/tmp/$id"; unlink "$root/tmp/$id";
} }
else else
{ {
$sha = new Digest::SHA(256); $sha = new Digest::SHA(256);
$sha->addfile("$gnutube_root/tmp/$id"); $sha->addfile("$root/tmp/$id");
$sha = $sha->hexdigest; $sha = $sha->hexdigest;
#check if this hash is already in database #check if this hash is already in database
@ -98,7 +98,7 @@ while(1)
#write status 5 to uploaded table #write status 5 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 5, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 5, $id) or interrupt $dbh->errstr;
unlink "$gnutube_root/tmp/$id"; unlink "$root/tmp/$id";
} }
else else
{ {
@ -114,12 +114,12 @@ while(1)
#write status 2 to uploaded table #write status 2 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr;
unlink "$gnutube_root/tmp/$id"; unlink "$root/tmp/$id";
} }
else else
{ {
#TODO: maybe delete entry from uploaded table after successful upload? #TODO: maybe delete entry from uploaded table after successful upload?
$filesize = -s "$gnutube_root/tmp/$id"; $filesize = -s "$root/tmp/$id";
#convert hh:mm:ss.s duration to full seconds - thanks perl for making this so damn easy! #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! #don't want to know how this would look in python or php... hell I don't even have to create extra variables!
@ -137,7 +137,7 @@ while(1)
$tnheight = 120; $tnheight = 120;
$tnwidth = int(120*($width/$height)/2 + .5)*2; $tnwidth = int(120*($width/$height)/2 + .5)*2;
} }
system "ffmpeg -i $gnutube_root/tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $thumbnailsec -s ".$tnwidth."x$tnheight $gnutube_root/video-stills/$id"; system "ffmpeg -i $root/tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $thumbnailsec -s ".$tnwidth."x$tnheight $root/video-stills/$id";
#check if the upload already is in the right format #check if the upload already is in the right format
if ($container eq 'ogg' and $video eq 'theora' and $audio eq 'vorbis') if ($container eq 'ogg' and $video eq 'theora' and $audio eq 'vorbis')
@ -152,13 +152,13 @@ while(1)
$height, $fps, $sha, $id) or interrupt $dbh->errstr; $height, $fps, $sha, $id) or interrupt $dbh->errstr;
#move video #move video
move "$gnutube_root/tmp/$id", "$gnutube_root/videos/$id"; move "$root/tmp/$id", "$root/videos/$id";
} }
else #encode video else #encode video
{ {
#FIXME: remove endtime - this is for testing only #FIXME: remove endtime - this is for testing only
#TODO: addmetadata information #TODO: addmetadata information
system "ffmpeg2theora --optimize --videobitrate 1000 --audiobitrate 64 --sharpness 0 --endtime 10 --output $gnutube_root/videos/$id $gnutube_root/tmp/$id 2>&1"; system "ffmpeg2theora --optimize --videobitrate 1000 --audiobitrate 64 --sharpness 0 --endtime 10 --output $root/videos/$id $root/tmp/$id 2>&1";
appendlog $id, $audio, $video, $width, $height, $fps, $duration, $sha; appendlog $id, $audio, $video, $width, $height, $fps, $duration, $sha;
#add video to videos table #add video to videos table
@ -169,7 +169,7 @@ while(1)
$height, $fps, $sha, $id) or interrupt $dbh->errstr; $height, $fps, $sha, $id) or interrupt $dbh->errstr;
#delete temp file #delete temp file
unlink "$gnutube_root/tmp/$id"; unlink "$root/tmp/$id";
} }
#write status 1 to uploaded table #write status 1 to uploaded table

View file

@ -116,7 +116,7 @@ sub fill_results
#before code cleanup, this was a really obfuscated array/hash creation #before code cleanup, this was a really obfuscated array/hash creation
push @{ $page->{'results'}->{'result'} }, push @{ $page->{'results'}->{'result'} },
{ {
'thumbnail' => "/video-stills/$id", 'thumbnail' => $duration == 0 ? "/images/tango/video-x-generic.png" : "/video-stills/$id",
'duration' => $duration, 'duration' => $duration,
'viewcount' => $viewcount, 'viewcount' => $viewcount,
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false", 'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
@ -128,7 +128,7 @@ sub fill_results
'dc:title' => [$title], 'dc:title' => [$title],
'dc:creator' => [$creator], 'dc:creator' => [$creator],
'dc:date' => [$timestamp], 'dc:date' => [$timestamp],
'dc:identifier' => ["$domain/video/$title/$id"], 'dc:identifier' => ["$domain/video/$title/$id" . ($duration == 0 ? "/edit=true" : "")],
'dc:publisher' => [$publisher] 'dc:publisher' => [$publisher]
}, },
'cc:License' => 'cc:License' =>

View file

@ -15,28 +15,37 @@ if($userinfo->{'username'})
{ {
if($query->param('2')) if($query->param('2'))
{ {
$page->{uploadform} = {'page' => '2'}; $page->{'uploadform'}->{'page'} = '2';
} }
elsif($query->param('3')) elsif($query->param('3'))
{ {
$page->{uploadform} = {'page' => '3'}; $page->{'uploadform'}->{'page'} = '3';
} }
elsif($query->param('4')) elsif($query->param('4'))
{ {
$page->{uploadform} = {'page' => '4'}; $page->{'uploadform'}->{'page'} = '4';
} }
elsif($query->param('5')) elsif($query->param('5'))
{ {
$page->{uploadform} = {'page' => '5'}; $page->{'uploadform'}->{'page'} = '5';
} }
elsif($query->param('6')) elsif($query->param('6'))
{ {
$page->{uploadform} = {'page' => '6'}; $page->{'uploadform'}->{'page'} = '6';
} }
else else
{ {
$page->{uploadform} = {'page' => '1'}; $page->{'uploadform'}->{'page'} = '1';
} }
$temp = $query->param('DC.Description');
$temp =~ s/\r\n/\n/g;
$page->{'uploadform'}->{'DC.Title'} = $query->param('DC.Title');
$page->{'uploadform'}->{'DC.Subject'} = $query->param('DC.Subject');
$page->{'uploadform'}->{'DC.Description'} = $temp;
$page->{'uploadform'}->{'DC.Creator'} = $query->param('DC.Creator');
$page->{'uploadform'}->{'DC.Source'} = $query->param('DC.Source');
$page->{'uploadform'}->{'DC.Language'} = $query->param('DC.Language');
$page->{'uploadform'}->{'DC.Coverage'} = $query->param('DC.Coverage');
} }
else else
{ {

View file

@ -436,22 +436,52 @@
<xsl:attribute name="action"> <xsl:attribute name="action">
<xsl:value-of select="$site_strings[@id='page_upload']" /> <xsl:value-of select="$site_strings[@id='page_upload']" />
</xsl:attribute> </xsl:attribute>
<input name="DC.Creator" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Creator" />
</xsl:attribute>
</input>
<input name="DC.Source" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Source" />
</xsl:attribute>
</input>
<input name="DC.Language" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Language" />
</xsl:attribute>
</input>
<input name="DC.Coverage" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Coverage" />
</xsl:attribute>
</input>
<fieldset> <fieldset>
<input type="hidden" name="page" value="2" /> <input type="hidden" name="page" value="2" />
<div class="messagebox"> <div class="messagebox">
<xsl:value-of select="$locale_strings[@id='instruction_title']" /> <xsl:value-of select="$locale_strings[@id='instruction_title']" />
<br /> <br />
<input name="DC.Title" type="text" size="30" /> <input name="DC.Title" type="text" size="30">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Title" />
</xsl:attribute>
</input>
</div> </div>
<div class="messagebox"> <div class="messagebox">
<xsl:value-of select="$locale_strings[@id='instruction_subject']" /> <xsl:value-of select="$locale_strings[@id='instruction_subject']" />
<br /> <br />
<input name="DC.Subject" type="text" size="30" /> <input name="DC.Subject" type="text" size="30">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Subject" />
</xsl:attribute>
</input>
</div> </div>
<div class="messagebox"> <div class="messagebox">
<xsl:value-of select="$locale_strings[@id='instruction_description']" /> <xsl:value-of select="$locale_strings[@id='instruction_description']" />
<br /> <br />
<textarea name="DC.Description" cols="50" rows="5"></textarea> <textarea name="DC.Description" cols="50" rows="5">
<xsl:value-of select="//uploadform/@DC.Description" />
</textarea>
</div> </div>
<input type="submit" name="2"> <input type="submit" name="2">
<xsl:attribute name="value"> <xsl:attribute name="value">
@ -474,6 +504,41 @@
<xsl:attribute name="action"> <xsl:attribute name="action">
<xsl:value-of select="$site_strings[@id='page_upload']" /> <xsl:value-of select="$site_strings[@id='page_upload']" />
</xsl:attribute> </xsl:attribute>
<input name="DC.Title" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Title" />
</xsl:attribute>
</input>
<input name="DC.Subject" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Subject" />
</xsl:attribute>
</input>
<input name="DC.Description" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Description" />
</xsl:attribute>
</input>
<input name="DC.Creator" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Creator" />
</xsl:attribute>
</input>
<input name="DC.Source" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Source" />
</xsl:attribute>
</input>
<input name="DC.Language" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Language" />
</xsl:attribute>
</input>
<input name="DC.Coverage" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Coverage" />
</xsl:attribute>
</input>
<fieldset> <fieldset>
<input type="submit" name="1"> <input type="submit" name="1">
<xsl:attribute name="value"> <xsl:attribute name="value">
@ -501,6 +566,21 @@
<xsl:attribute name="action"> <xsl:attribute name="action">
<xsl:value-of select="$site_strings[@id='page_upload']" /> <xsl:value-of select="$site_strings[@id='page_upload']" />
</xsl:attribute> </xsl:attribute>
<input name="DC.Title" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Title" />
</xsl:attribute>
</input>
<input name="DC.Subject" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Subject" />
</xsl:attribute>
</input>
<input name="DC.Description" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Description" />
</xsl:attribute>
</input>
<fieldset> <fieldset>
<div class="messagebox"> <div class="messagebox">
<xsl:value-of select="$locale_strings[@id='instruction_creator']" /> <xsl:value-of select="$locale_strings[@id='instruction_creator']" />
@ -554,6 +634,41 @@
<xsl:attribute name="action"> <xsl:attribute name="action">
<xsl:value-of select="$site_strings[@id='page_upload']" /> <xsl:value-of select="$site_strings[@id='page_upload']" />
</xsl:attribute> </xsl:attribute>
<input name="DC.Title" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Title" />
</xsl:attribute>
</input>
<input name="DC.Subject" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Subject" />
</xsl:attribute>
</input>
<input name="DC.Description" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Description" />
</xsl:attribute>
</input>
<input name="DC.Creator" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Creator" />
</xsl:attribute>
</input>
<input name="DC.Source" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Source" />
</xsl:attribute>
</input>
<input name="DC.Language" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Language" />
</xsl:attribute>
</input>
<input name="DC.Coverage" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Coverage" />
</xsl:attribute>
</input>
<fieldset> <fieldset>
<div class="messagebox"> <div class="messagebox">
<input type="radio" name="license" checked="checked" />none <input type="radio" name="license" checked="checked" />none
@ -598,7 +713,57 @@
<xsl:attribute name="action"> <xsl:attribute name="action">
<xsl:value-of select="$site_strings[@id='page_upload']" /> <xsl:value-of select="$site_strings[@id='page_upload']" />
</xsl:attribute> </xsl:attribute>
<input name="DC.Title" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Title" />
</xsl:attribute>
</input>
<input name="DC.Subject" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Subject" />
</xsl:attribute>
</input>
<input name="DC.Description" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Description" />
</xsl:attribute>
</input>
<fieldset> <fieldset>
<input name="DC.Title" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Title" />
</xsl:attribute>
</input>
<input name="DC.Subject" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Subject" />
</xsl:attribute>
</input>
<input name="DC.Description" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Description" />
</xsl:attribute>
</input>
<input name="DC.Creator" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Creator" />
</xsl:attribute>
</input>
<input name="DC.Source" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Source" />
</xsl:attribute>
</input>
<input name="DC.Language" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Language" />
</xsl:attribute>
</input>
<input name="DC.Coverage" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Coverage" />
</xsl:attribute>
</input>
<div class="messagebox"> <div class="messagebox">
title: title:
<br /> <br />
@ -643,6 +808,41 @@
<xsl:attribute name="action"> <xsl:attribute name="action">
<xsl:value-of select="$site_strings[@id='page_uploader']" /> <xsl:value-of select="$site_strings[@id='page_uploader']" />
</xsl:attribute> </xsl:attribute>
<input name="DC.Title" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Title" />
</xsl:attribute>
</input>
<input name="DC.Subject" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Subject" />
</xsl:attribute>
</input>
<input name="DC.Description" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Description" />
</xsl:attribute>
</input>
<input name="DC.Creator" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Creator" />
</xsl:attribute>
</input>
<input name="DC.Source" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Source" />
</xsl:attribute>
</input>
<input name="DC.Language" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Language" />
</xsl:attribute>
</input>
<input name="DC.Coverage" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="//uploadform/@DC.Coverage" />
</xsl:attribute>
</input>
<fieldset> <fieldset>
<div class="messagebox"> <div class="messagebox">
<xsl:value-of select="$locale_strings[@id='instruction_file']" /> <xsl:value-of select="$locale_strings[@id='instruction_file']" />