From 6b9ccd32230f195451def2d5eedb0aee76e2ac51 Mon Sep 17 00:00:00 2001 From: josch Date: Tue, 15 Apr 2008 18:56:13 +0000 Subject: [PATCH] added config file - second part git-svn-id: http://yolanda.mister-muffin.de/svn@301 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/config/backend.xml | 5 ++--- trunk/download.pl | 2 +- trunk/include.pl | 3 --- trunk/index.pl | 2 +- trunk/init_sql.pl | 2 +- trunk/login.pl | 2 +- trunk/register.pl | 2 +- trunk/search.pl | 2 +- trunk/settings.pl | 2 +- trunk/tools/daemon.pl | 33 +++++++++++++++++++-------------- trunk/tools/tagcloud.pl | 18 ++++++++++-------- trunk/upload.pl | 2 +- trunk/uploader.pl | 2 +- trunk/video.pl | 2 +- 14 files changed, 41 insertions(+), 38 deletions(-) diff --git a/trunk/config/backend.xml b/trunk/config/backend.xml index 3026afd..ffa05a3 100644 --- a/trunk/config/backend.xml +++ b/trunk/config/backend.xml @@ -11,8 +11,6 @@ http://localhost - /var/www/yolanda/ - en-us xhtml.xsl @@ -25,12 +23,13 @@ sid - 720 + 720 240 1080 320 204800 512 + 6000 64 diff --git a/trunk/download.pl b/trunk/download.pl index 7c55bd2..42604ea 100644 --- a/trunk/download.pl +++ b/trunk/download.pl @@ -1,7 +1,7 @@ require "functions.pl"; #initialize session data -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session; diff --git a/trunk/include.pl b/trunk/include.pl index bb12203..3e492a4 100644 --- a/trunk/include.pl +++ b/trunk/include.pl @@ -22,8 +22,5 @@ $config = XMLin("$root/config/backend.xml", KeyAttr => {string => 'id'}, ForceAr $config = $config->{"strings"}->{"string"}; #set global variables -$session_name = 'sid'; -$locale = "en-US"; - $dbh = DBI->connect("DBI:mysql:".$config->{"database_name"}.":".$config->{"database_host"}, $config->{"database_username"}, $config->{"database_password"}) or die $DBI::errstr; 1; diff --git a/trunk/index.pl b/trunk/index.pl index 43dfdb2..3f8a6cc 100644 --- a/trunk/index.pl +++ b/trunk/index.pl @@ -1,7 +1,7 @@ require "functions.pl"; #create or resume session -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session; diff --git a/trunk/init_sql.pl b/trunk/init_sql.pl index f1f3f8a..1eaf2f1 100644 --- a/trunk/init_sql.pl +++ b/trunk/init_sql.pl @@ -1,7 +1,7 @@ require "include.pl"; #create or resume session -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); my $session = new CGI::Session; $dbh->do(qq{drop table config}); diff --git a/trunk/login.pl b/trunk/login.pl index cca542b..0bd3c68 100644 --- a/trunk/login.pl +++ b/trunk/login.pl @@ -1,7 +1,7 @@ require "functions.pl"; #initialize session data -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session; diff --git a/trunk/register.pl b/trunk/register.pl index 7add87b..86d933f 100644 --- a/trunk/register.pl +++ b/trunk/register.pl @@ -1,7 +1,7 @@ require "functions.pl"; #initialize session data -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session; diff --git a/trunk/search.pl b/trunk/search.pl index e299816..7087943 100644 --- a/trunk/search.pl +++ b/trunk/search.pl @@ -1,7 +1,7 @@ require "functions.pl"; #initialize session data -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session; diff --git a/trunk/settings.pl b/trunk/settings.pl index c935391..ee28ff6 100644 --- a/trunk/settings.pl +++ b/trunk/settings.pl @@ -1,7 +1,7 @@ require "functions.pl"; #initialize session data -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session; diff --git a/trunk/tools/daemon.pl b/trunk/tools/daemon.pl index bdaeff9..9cc8ccd 100755 --- a/trunk/tools/daemon.pl +++ b/trunk/tools/daemon.pl @@ -4,14 +4,14 @@ use Proc::Daemon; use DBI; use Digest::SHA; use File::Copy; +use XML::Simple qw(:strict); -#TODO: put this into central configuration file -$database = 'yolanda'; -$dbhost = 'localhost'; -$dbuser = 'root'; -$dbpass = ''; $root = '/var/www/yolanda'; +#set global config variable +$config = XMLin("$root/config/backend.xml", KeyAttr => {string => 'id'}, ForceArray => [ 'string' ], ContentKey => '-content'); +$config = $config->{"strings"}->{"string"}; + #TODO: deamonize by uncommenting this line #Proc::Daemon::Init; @@ -37,7 +37,7 @@ sub interrupt die; } -$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or interrupt "could not connect to db"; +$dbh = DBI->connect("DBI:mysql:".$config->{"database_name"}.":".$config->{"database_host"}, $config->{"database_username"}, $config->{"database_password"}) or die $DBI::errstr; while(1) { @@ -51,21 +51,26 @@ while(1) if($id) { - $vmaxheight = 640; - #video height is either the maximum video height #or (when the original is smaller than that) the original height #check for multiple by 8 - $vheight = $vmaxheight <= $height ? $vmaxheight : int($height/8 + .5)*8; + $vheight = $height <= $config->{"video_height_max"} ? int($height/8 + .5)*8 : $config->{"video_height_max"}; $vwidth = int($vheight*($width/$height)/8 + .5)*8; - $abitrate = 64; - $vbitrate = int((int(($filesize*8) / $duration + .5) - $abitrate)/1000); - #check if the bitrate is lower than 16000 (maximum for ffmpeg) - $vbitrate = $vbitrate <= 16000 ? $vbitrate : 16000; + #if calculated width is greater than max_width, recalculate height + if($vwidth > $config->{"video_width_max"}) + { + $vwidth = $config->{"video_width_max"}; + $vheight = int($vwidth*($height/$width)/8 + .5)*8; + } + + #calculate video bitrate - try to keep the original filesize + $vbitrate = int((int(($filesize*8) / $duration + .5) - $config->{"video_audio_bitrate"})/1000); + #check if the bitrate is lower than $config->{"video_bitrate_max"} and adjust if necessary + $vbitrate = $vbitrate <= $config->{"video_bitrate_max"} ? $vbitrate : $config->{"video_bitrate_max"}; #TODO: add metadata information - $ffmpeg = system "ffmpeg2theora --optimize --videobitrate $vbitrate --audiobitrate $abitrate --sharpness 0 --width $vwidth --height $vheight --output $root/videos/$id /tmp/$id"; + $ffmpeg = system "ffmpeg2theora --optimize --videobitrate $vbitrate --audiobitrate ".$config->{"video_audio_bitrate"}." --sharpness 0 --width $vwidth --height $vheight --output $root/videos/$id /tmp/$id"; appendlog $id, $vbitrate, $filesize, $vwidth, $vheight, $fps, $duration, $sha, $ffmpeg; diff --git a/trunk/tools/tagcloud.pl b/trunk/tools/tagcloud.pl index 367b719..c4d14a2 100755 --- a/trunk/tools/tagcloud.pl +++ b/trunk/tools/tagcloud.pl @@ -1,13 +1,15 @@ #!/usr/bin/perl -w use DBI; +use XML::Simple qw(:strict); -$database = 'yolanda'; -$dbhost = 'localhost'; -$dbuser = 'root'; -$dbpass = ''; +$root = '/var/www/yolanda'; -$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass); +#set global config variable +$config = XMLin("$root/config/backend.xml", KeyAttr => {string => 'id'}, ForceArray => [ 'string' ], ContentKey => '-content'); +$config = $config->{"strings"}->{"string"}; + +$dbh = DBI->connect("DBI:mysql:".$config->{"database_name"}.":".$config->{"database_host"}, $config->{"database_username"}, $config->{"database_password"}) or die $DBI::errstr; $sth = $dbh->prepare("select subject from videos"); $sth->execute(); @@ -20,7 +22,7 @@ while(($subject) = $sth->fetchrow_array()) { #strip whitespaces $val =~ s/^\s*(.*?)\s*$/$1/; - if(length($val) >= 3) + if(length($val) >= $config->{"page_tag_lenght_min"}) { %hash->{$val}++; } @@ -33,8 +35,8 @@ $sth->finish(); $dbh->do("delete from tagcloud"); $sth = $dbh->prepare("insert into tagcloud (text, count) values (?, ?)"); -#insert first 20 tags into tagcloud table -for($i=0;$i<20 and $i<=$#sorted;$i++) +#insert tags into tagcloud table +for($i=0;$i<$config->{"page_tag_count"} and $i<=$#sorted;$i++) { $sth->execute( $sorted[$i], %hash->{$sorted[$i]} ); } diff --git a/trunk/upload.pl b/trunk/upload.pl index dca997c..82e75e7 100644 --- a/trunk/upload.pl +++ b/trunk/upload.pl @@ -1,7 +1,7 @@ require "functions.pl"; #create or resume session -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session; diff --git a/trunk/uploader.pl b/trunk/uploader.pl index 8aba2af..3f7f65c 100644 --- a/trunk/uploader.pl +++ b/trunk/uploader.pl @@ -1,6 +1,6 @@ require "functions.pl"; -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = CGI->new(\&hook); $session = new CGI::Session; diff --git a/trunk/video.pl b/trunk/video.pl index de8cecf..b4dee3d 100644 --- a/trunk/video.pl +++ b/trunk/video.pl @@ -1,7 +1,7 @@ require "functions.pl"; #initialize session data -CGI::Session->name($session_name); +CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session;