From ddea677b1c310db81a8a905be8447cd170e63b8c Mon Sep 17 00:00:00 2001 From: josch Date: Thu, 18 Oct 2007 09:41:19 +0000 Subject: [PATCH] added new table 'uploaded' - a lot of little fixes git-svn-id: http://yolanda.mister-muffin.de/svn@85 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/gnutube_daemon.pl | 86 ++++++++++++++++++++++------------------- trunk/init_sql.pl | 24 +++++++++--- trunk/uploader.pl | 2 +- trunk/video.pl | 4 +- 4 files changed, 68 insertions(+), 48 deletions(-) diff --git a/trunk/gnutube_daemon.pl b/trunk/gnutube_daemon.pl index dde21c3..c4e915c 100755 --- a/trunk/gnutube_daemon.pl +++ b/trunk/gnutube_daemon.pl @@ -3,6 +3,7 @@ use Proc::Daemon; use DBI; use Digest::SHA; +use File::Copy; $database = 'gnutube'; $dbhost = 'localhost'; @@ -43,9 +44,9 @@ $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or interrup while(1) { #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; - my ($id) = $sth->fetchrow_array(); + my ($id, $title, $caption, $userid, $timestamp) = $sth->fetchrow_array(); $sth->finish() or interrupt $dbh->errstr; if($id) @@ -56,28 +57,31 @@ while(1) { appendlog $id, "invalid stream"; - #write status 2 to database - $sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr; + #write status 2 to uploaded table + $sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr; $sth->execute(2, $id) or interrupt $dbh->errstr; $sth->finish() or interrupt $dbh->errstr; + unlink "$gnutube_root/tmp/$id"; } elsif ($info =~ /I\/O error occured/) { appendlog $id, "file not found"; - #write status 3 to database - $sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr; + #write status 3 to uploaded table + $sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr; $sth->execute(3, $id) 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/) { appendlog $id, "file is no video"; - #write status 4 to database - $sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr; + #write status 4 to uploaded table + $sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr; $sth->execute(4, $id) or interrupt $dbh->errstr; $sth->finish() or interrupt $dbh->errstr; + unlink "$gnutube_root/tmp/$id"; } else { @@ -96,10 +100,11 @@ while(1) { appendlog "$id, video already uploaded: $resultid"; - #write status 5 to database - $sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr; + #write status 5 to uploaded table + $sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr; $sth->execute(5, $id) or interrupt $dbh->errstr; $sth->finish() or interrupt $dbh->errstr; + unlink "$gnutube_root/tmp/$id"; } else { @@ -113,10 +118,11 @@ while(1) { appendlog $id, "a stream is missing or video is corrupt"; - #write status 2 to database - $sth = $dbh->prepare(qq{update videos set status = ? where id = ?}) or interrupt $dbh->errstr; + #write status 2 to uploaded table + $sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr; $sth->execute(2, $id) or interrupt $dbh->errstr; $sth->finish() or interrupt $dbh->errstr; + unlink "$gnutube_root/tmp/$id"; } else { @@ -127,40 +133,40 @@ while(1) { appendlog $id, "file already is ogg-theora/vorbis"; - #fill database - $sth = $dbh->prepare(qq{update videos set - status = ?, - 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; + #write status 1 to uploaded table + $sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr; + $sth->execute(1, $id) 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 { - - #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"; + system "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; - - #fill database - $sth = $dbh->prepare(qq{update videos set - status = ?, - 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; + + #write status 1 to uploaded table + $sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr; + $sth->execute(1, $id) 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"; } } } diff --git a/trunk/init_sql.pl b/trunk/init_sql.pl index 1090e4f..3ab5cca 100644 --- a/trunk/init_sql.pl +++ b/trunk/init_sql.pl @@ -11,6 +11,8 @@ $dbh->do(qq{drop table users}); $dbh->do(qq{drop table videos}); +$dbh->do(qq{drop table uploaded}); + $dbh->do(qq{drop table tagcloud}); $dbh->do(qq{create table @@ -19,14 +21,14 @@ $dbh->do(qq{create table text varchar(255) not null, count int not null ) -}); +}) or die $dbh->errstr; $dbh->do(qq{insert into tagcloud values ( 'web tv', 68 ) -}); +}) or die $dbh->errstr; $dbh->do(qq{create table users @@ -37,7 +39,20 @@ $dbh->do(qq{create table sid char(32) not null, 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 videos @@ -47,7 +62,6 @@ $dbh->do(qq{create table caption text not null, userid int not null, hash char(64) not null, - status int not null, timestamp datetime not null, filesize int not null, duration float not null, @@ -57,7 +71,7 @@ $dbh->do(qq{create table primary key (id), fulltext (title, caption) ) -}); +}) or die $dbh->errstr; $dbh->disconnect() or die $dbh->errstr; diff --git a/trunk/uploader.pl b/trunk/uploader.pl index 4b06532..a71c3ab 100644 --- a/trunk/uploader.pl +++ b/trunk/uploader.pl @@ -26,7 +26,7 @@ if($userid) my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr; #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->finish() or die $dbh->errstr; diff --git a/trunk/video.pl b/trunk/video.pl index 072e859..5efa505 100644 --- a/trunk/video.pl +++ b/trunk/video.pl @@ -32,7 +32,7 @@ if($query->param('title') or $query->param('id')) else { #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 $rowcount = $sth->execute($query->param('title')) or die $dbh->errstr; } @@ -49,7 +49,7 @@ if($query->param('title') or $query->param('id')) { 'cc:Work' => { - 'rdf:about' => "./videos/".$query->param('id'), + 'rdf:about' => "./videos/$id", 'dc:title' => [$title], 'dc:date' => [$timestamp], 'dc:publisher' => [get_username_from_id($userid)],