added new table 'uploaded' - a lot of little fixes
git-svn-id: http://yolanda.mister-muffin.de/svn@85 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
426addef3a
commit
ddea677b1c
4 changed files with 68 additions and 48 deletions
|
@ -3,6 +3,7 @@
|
||||||
use Proc::Daemon;
|
use Proc::Daemon;
|
||||||
use DBI;
|
use DBI;
|
||||||
use Digest::SHA;
|
use Digest::SHA;
|
||||||
|
use File::Copy;
|
||||||
|
|
||||||
$database = 'gnutube';
|
$database = 'gnutube';
|
||||||
$dbhost = 'localhost';
|
$dbhost = 'localhost';
|
||||||
|
@ -43,9 +44,9 @@ $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or interrup
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
#get fresh video id from db
|
#get fresh video id from db
|
||||||
my $sth = $dbh->prepare(qq{select id from videos where status = 0 limit 1}) or interrupt $dbh->errstr;
|
my $sth = $dbh->prepare(qq{select id, title, caption, userid, timestamp from uploaded where status = 0 limit 1}) or interrupt $dbh->errstr;
|
||||||
$sth->execute() or interrupt $dbh->errstr;
|
$sth->execute() or interrupt $dbh->errstr;
|
||||||
my ($id) = $sth->fetchrow_array();
|
my ($id, $title, $caption, $userid, $timestamp) = $sth->fetchrow_array();
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
|
|
||||||
if($id)
|
if($id)
|
||||||
|
@ -56,28 +57,31 @@ while(1)
|
||||||
{
|
{
|
||||||
appendlog $id, "invalid stream";
|
appendlog $id, "invalid stream";
|
||||||
|
|
||||||
#write status 2 to database
|
#write status 2 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
||||||
$sth->execute(2, $id) or interrupt $dbh->errstr;
|
$sth->execute(2, $id) or interrupt $dbh->errstr;
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
elsif ($info =~ /I\/O error occured/)
|
elsif ($info =~ /I\/O error occured/)
|
||||||
{
|
{
|
||||||
appendlog $id, "file not found";
|
appendlog $id, "file not found";
|
||||||
|
|
||||||
#write status 3 to database
|
#write status 3 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
||||||
$sth->execute(3, $id) or interrupt $dbh->errstr;
|
$sth->execute(3, $id) or interrupt $dbh->errstr;
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
|
unlink "$gnutube_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/)
|
||||||
{
|
{
|
||||||
appendlog $id, "file is no video";
|
appendlog $id, "file is no video";
|
||||||
|
|
||||||
#write status 4 to database
|
#write status 4 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
||||||
$sth->execute(4, $id) or interrupt $dbh->errstr;
|
$sth->execute(4, $id) or interrupt $dbh->errstr;
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -96,10 +100,11 @@ while(1)
|
||||||
{
|
{
|
||||||
appendlog "$id, video already uploaded: $resultid";
|
appendlog "$id, video already uploaded: $resultid";
|
||||||
|
|
||||||
#write status 5 to database
|
#write status 5 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
||||||
$sth->execute(5, $id) or interrupt $dbh->errstr;
|
$sth->execute(5, $id) or interrupt $dbh->errstr;
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -113,10 +118,11 @@ while(1)
|
||||||
{
|
{
|
||||||
appendlog $id, "a stream is missing or video is corrupt";
|
appendlog $id, "a stream is missing or video is corrupt";
|
||||||
|
|
||||||
#write status 2 to database
|
#write status 2 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
||||||
$sth->execute(2, $id) or interrupt $dbh->errstr;
|
$sth->execute(2, $id) or interrupt $dbh->errstr;
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -127,40 +133,40 @@ while(1)
|
||||||
{
|
{
|
||||||
appendlog $id, "file already is ogg-theora/vorbis";
|
appendlog $id, "file already is ogg-theora/vorbis";
|
||||||
|
|
||||||
#fill database
|
#write status 1 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update videos set
|
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
||||||
status = ?,
|
$sth->execute(1, $id) or interrupt $dbh->errstr;
|
||||||
hash = ?,
|
|
||||||
filesize = ?,
|
|
||||||
duration = time_to_sec( ? ),
|
|
||||||
width = ?,
|
|
||||||
height = ?,
|
|
||||||
fps = ?
|
|
||||||
where id = ?}) or interrupt $dbh->errstr;
|
|
||||||
$sth->execute(1, $sha, $filesize, $duration, $width, $height, $fps, $id) or interrupt $dbh->errstr;
|
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
#TODO move video
|
|
||||||
|
#add video to videos table
|
||||||
|
$sth = $dbh->prepare(qq{insert into videos (id, title, caption, userid, timestamp,
|
||||||
|
hash, filesize, duration, width, height, fps)
|
||||||
|
values (?, ?, ?, ?, ?, ?, ?, time_to_sec( ? ), ?, ?, ?)}) or interrupt $dbh->errstr;
|
||||||
|
$sth->execute($id, $title, $caption, $userid, $timestamp, $sha, $filesize, $duration, $width, $height, $fps) or interrupt $dbh->errstr;
|
||||||
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
|
|
||||||
|
#move video
|
||||||
|
move "$gnutube_root/tmp/$id", "$gnutube_root/videos/$id";
|
||||||
}
|
}
|
||||||
else #encode video
|
else #encode video
|
||||||
{
|
{
|
||||||
|
system "ffmpeg2theora --optimize --videobitrate 1000 --audiobitrate 64 --sharpness 0 --endtime 10 --output $gnutube_root/videos/$id $gnutube_root/tmp/$id 2>&1";
|
||||||
#TODO uncomment the following line
|
|
||||||
#exec "ffmpeg2theora --optimize --videobitrate 1000 --audiobitrate 64 --sharpness 0 --endtime 10 --output $gnutube_root/videos/$id $gnutube_root/tmp/$id 2>&1";
|
|
||||||
appendlog $id, $audio, $video, $width, $height, $fps, $duration, $sha;
|
appendlog $id, $audio, $video, $width, $height, $fps, $duration, $sha;
|
||||||
|
|
||||||
#fill database
|
#write status 1 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update videos set
|
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
||||||
status = ?,
|
$sth->execute(1, $id) or interrupt $dbh->errstr;
|
||||||
hash = ?,
|
|
||||||
filesize = ?,
|
|
||||||
duration = time_to_sec( ? ),
|
|
||||||
width = ?,
|
|
||||||
height = ?,
|
|
||||||
fps = ?
|
|
||||||
where id = ?}) or interrupt $dbh->errstr;
|
|
||||||
$sth->execute(1, $sha, $filesize, $duration, $width, $height, $fps, $id) or interrupt $dbh->errstr;
|
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
#TODO delete temp file
|
|
||||||
|
#add video to videos table
|
||||||
|
$sth = $dbh->prepare(qq{insert into videos (id, title, caption, userid, timestamp,
|
||||||
|
hash, filesize, duration, width, height, fps)
|
||||||
|
values (?, ?, ?, ?, ?, ?, ?, time_to_sec( ? ), ?, ?, ?)}) or interrupt $dbh->errstr;
|
||||||
|
$sth->execute($id, $title, $caption, $userid, $timestamp, $sha, $filesize, $duration, $width, $height, $fps) or interrupt $dbh->errstr;
|
||||||
|
$sth->finish() or interrupt $dbh->errstr;
|
||||||
|
|
||||||
|
#delete temp file
|
||||||
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ $dbh->do(qq{drop table users});
|
||||||
|
|
||||||
$dbh->do(qq{drop table videos});
|
$dbh->do(qq{drop table videos});
|
||||||
|
|
||||||
|
$dbh->do(qq{drop table uploaded});
|
||||||
|
|
||||||
$dbh->do(qq{drop table tagcloud});
|
$dbh->do(qq{drop table tagcloud});
|
||||||
|
|
||||||
$dbh->do(qq{create table
|
$dbh->do(qq{create table
|
||||||
|
@ -19,14 +21,14 @@ $dbh->do(qq{create table
|
||||||
text varchar(255) not null,
|
text varchar(255) not null,
|
||||||
count int not null
|
count int not null
|
||||||
)
|
)
|
||||||
});
|
}) or die $dbh->errstr;
|
||||||
|
|
||||||
$dbh->do(qq{insert into
|
$dbh->do(qq{insert into
|
||||||
tagcloud values
|
tagcloud values
|
||||||
(
|
(
|
||||||
'web tv', 68
|
'web tv', 68
|
||||||
)
|
)
|
||||||
});
|
}) or die $dbh->errstr;
|
||||||
|
|
||||||
$dbh->do(qq{create table
|
$dbh->do(qq{create table
|
||||||
users
|
users
|
||||||
|
@ -37,7 +39,20 @@ $dbh->do(qq{create table
|
||||||
sid char(32) not null,
|
sid char(32) not null,
|
||||||
primary key (id)
|
primary key (id)
|
||||||
)
|
)
|
||||||
});
|
}) or die $dbh->errstr;
|
||||||
|
|
||||||
|
$dbh->do(qq{create table
|
||||||
|
uploaded
|
||||||
|
(
|
||||||
|
id int auto_increment not null,
|
||||||
|
title varchar(255) not null,
|
||||||
|
caption text not null,
|
||||||
|
userid int not null,
|
||||||
|
status int not null,
|
||||||
|
timestamp datetime not null,
|
||||||
|
primary key (id)
|
||||||
|
)
|
||||||
|
}) or die $dbh->errstr;
|
||||||
|
|
||||||
$dbh->do(qq{create table
|
$dbh->do(qq{create table
|
||||||
videos
|
videos
|
||||||
|
@ -47,7 +62,6 @@ $dbh->do(qq{create table
|
||||||
caption text not null,
|
caption text not null,
|
||||||
userid int not null,
|
userid int not null,
|
||||||
hash char(64) not null,
|
hash char(64) not null,
|
||||||
status int not null,
|
|
||||||
timestamp datetime not null,
|
timestamp datetime not null,
|
||||||
filesize int not null,
|
filesize int not null,
|
||||||
duration float not null,
|
duration float not null,
|
||||||
|
@ -57,7 +71,7 @@ $dbh->do(qq{create table
|
||||||
primary key (id),
|
primary key (id),
|
||||||
fulltext (title, caption)
|
fulltext (title, caption)
|
||||||
)
|
)
|
||||||
});
|
}) or die $dbh->errstr;
|
||||||
|
|
||||||
$dbh->disconnect() or die $dbh->errstr;
|
$dbh->disconnect() or die $dbh->errstr;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ if($userid)
|
||||||
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
||||||
|
|
||||||
#make new entry for video into the databse
|
#make new entry for video into the databse
|
||||||
my $sth = $dbh->prepare(qq{insert into videos (title, caption, userid, status, timestamp) values ( ?, ?, ?, 0, now())}) or die $dbh->errstr;
|
my $sth = $dbh->prepare(qq{insert into uploaded (title, caption, userid, status, timestamp) values ( ?, ?, ?, 0, now())}) or die $dbh->errstr;
|
||||||
$sth->execute($query->param("title"), $query->param("caption"), $userid) or die $dbh->errstr;
|
$sth->execute($query->param("title"), $query->param("caption"), $userid) or die $dbh->errstr;
|
||||||
$sth->finish() or die $dbh->errstr;
|
$sth->finish() or die $dbh->errstr;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ if($query->param('title') or $query->param('id'))
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#prepare query
|
#prepare query
|
||||||
$sth = $dbh->prepare(qq{select id, title, caption, userid, timestamp from videos where title = ? and status = 1 }) or die $dbh->errstr;
|
$sth = $dbh->prepare(qq{select id, title, caption, userid, timestamp from videos where title = ? }) or die $dbh->errstr;
|
||||||
#execute it
|
#execute it
|
||||||
$rowcount = $sth->execute($query->param('title')) or die $dbh->errstr;
|
$rowcount = $sth->execute($query->param('title')) or die $dbh->errstr;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ if($query->param('title') or $query->param('id'))
|
||||||
{
|
{
|
||||||
'cc:Work' =>
|
'cc:Work' =>
|
||||||
{
|
{
|
||||||
'rdf:about' => "./videos/".$query->param('id'),
|
'rdf:about' => "./videos/$id",
|
||||||
'dc:title' => [$title],
|
'dc:title' => [$title],
|
||||||
'dc:date' => [$timestamp],
|
'dc:date' => [$timestamp],
|
||||||
'dc:publisher' => [get_username_from_id($userid)],
|
'dc:publisher' => [get_username_from_id($userid)],
|
||||||
|
|
Loading…
Reference in a new issue