added config file - second part

git-svn-id: http://yolanda.mister-muffin.de/svn@301 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-04-15 18:56:13 +00:00
parent e555b062cb
commit 6b9ccd3223
14 changed files with 41 additions and 38 deletions

View file

@ -11,8 +11,6 @@
<string id="url_root">http://localhost</string><!-- MUST NOT end with trailing slash --> <string id="url_root">http://localhost</string><!-- MUST NOT end with trailing slash -->
<string id="path_root">/var/www/yolanda/</string><!-- MUST end with trailing slash -->
<!-- general page settings --> <!-- general page settings -->
<string id="page_locale">en-us</string> <string id="page_locale">en-us</string>
<string id="page_xslt">xhtml.xsl</string> <string id="page_xslt">xhtml.xsl</string>
@ -25,12 +23,13 @@
<string id="page_cookie_name">sid</string> <string id="page_cookie_name">sid</string>
<!-- settings for video uploads --> <!-- settings for video uploads -->
<string id="video_height_max">720</string><!-- in pixels --> <string id="video_height_max">720</string><!-- in pixels - MUST be multiple of 8 -->
<string id="video_height_min">240</string> <string id="video_height_min">240</string>
<string id="video_width_max">1080</string> <string id="video_width_max">1080</string>
<string id="video_width_min">320</string> <string id="video_width_min">320</string>
<string id="video_filesize_max">204800</string><!-- in bytes --> <string id="video_filesize_max">204800</string><!-- in bytes -->
<string id="video_filesize_min">512</string> <string id="video_filesize_min">512</string>
<string id="video_bitrate_max">6000</string>
<string id="video_audio_bitrate">64</string> <string id="video_audio_bitrate">64</string>
<!-- settings for xml output --> <!-- settings for xml output -->

View file

@ -1,7 +1,7 @@
require "functions.pl"; require "functions.pl";
#initialize session data #initialize session data
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI; $query = new CGI;
$session = new CGI::Session; $session = new CGI::Session;

View file

@ -22,8 +22,5 @@ $config = XMLin("$root/config/backend.xml", KeyAttr => {string => 'id'}, ForceAr
$config = $config->{"strings"}->{"string"}; $config = $config->{"strings"}->{"string"};
#set global variables #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; $dbh = DBI->connect("DBI:mysql:".$config->{"database_name"}.":".$config->{"database_host"}, $config->{"database_username"}, $config->{"database_password"}) or die $DBI::errstr;
1; 1;

View file

@ -1,7 +1,7 @@
require "functions.pl"; require "functions.pl";
#create or resume session #create or resume session
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI; $query = new CGI;
$session = new CGI::Session; $session = new CGI::Session;

View file

@ -1,7 +1,7 @@
require "include.pl"; require "include.pl";
#create or resume session #create or resume session
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
my $session = new CGI::Session; my $session = new CGI::Session;
$dbh->do(qq{drop table config}); $dbh->do(qq{drop table config});

View file

@ -1,7 +1,7 @@
require "functions.pl"; require "functions.pl";
#initialize session data #initialize session data
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI; $query = new CGI;
$session = new CGI::Session; $session = new CGI::Session;

View file

@ -1,7 +1,7 @@
require "functions.pl"; require "functions.pl";
#initialize session data #initialize session data
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI; $query = new CGI;
$session = new CGI::Session; $session = new CGI::Session;

View file

@ -1,7 +1,7 @@
require "functions.pl"; require "functions.pl";
#initialize session data #initialize session data
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI; $query = new CGI;
$session = new CGI::Session; $session = new CGI::Session;

View file

@ -1,7 +1,7 @@
require "functions.pl"; require "functions.pl";
#initialize session data #initialize session data
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI; $query = new CGI;
$session = new CGI::Session; $session = new CGI::Session;

View file

@ -4,14 +4,14 @@ use Proc::Daemon;
use DBI; use DBI;
use Digest::SHA; use Digest::SHA;
use File::Copy; 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'; $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 #TODO: deamonize by uncommenting this line
#Proc::Daemon::Init; #Proc::Daemon::Init;
@ -37,7 +37,7 @@ sub interrupt
die; 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) while(1)
{ {
@ -51,21 +51,26 @@ while(1)
if($id) if($id)
{ {
$vmaxheight = 640;
#video height is either the maximum video height #video height is either the maximum video height
#or (when the original is smaller than that) the original height #or (when the original is smaller than that) the original height
#check for multiple by 8 #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; $vwidth = int($vheight*($width/$height)/8 + .5)*8;
$abitrate = 64; #if calculated width is greater than max_width, recalculate height
$vbitrate = int((int(($filesize*8) / $duration + .5) - $abitrate)/1000); if($vwidth > $config->{"video_width_max"})
#check if the bitrate is lower than 16000 (maximum for ffmpeg) {
$vbitrate = $vbitrate <= 16000 ? $vbitrate : 16000; $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 #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; appendlog $id, $vbitrate, $filesize, $vwidth, $vheight, $fps, $duration, $sha, $ffmpeg;

View file

@ -1,13 +1,15 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use DBI; use DBI;
use XML::Simple qw(:strict);
$database = 'yolanda'; $root = '/var/www/yolanda';
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$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 = $dbh->prepare("select subject from videos");
$sth->execute(); $sth->execute();
@ -20,7 +22,7 @@ while(($subject) = $sth->fetchrow_array())
{ {
#strip whitespaces #strip whitespaces
$val =~ s/^\s*(.*?)\s*$/$1/; $val =~ s/^\s*(.*?)\s*$/$1/;
if(length($val) >= 3) if(length($val) >= $config->{"page_tag_lenght_min"})
{ {
%hash->{$val}++; %hash->{$val}++;
} }
@ -33,8 +35,8 @@ $sth->finish();
$dbh->do("delete from tagcloud"); $dbh->do("delete from tagcloud");
$sth = $dbh->prepare("insert into tagcloud (text, count) values (?, ?)"); $sth = $dbh->prepare("insert into tagcloud (text, count) values (?, ?)");
#insert first 20 tags into tagcloud table #insert tags into tagcloud table
for($i=0;$i<20 and $i<=$#sorted;$i++) for($i=0;$i<$config->{"page_tag_count"} and $i<=$#sorted;$i++)
{ {
$sth->execute( $sorted[$i], %hash->{$sorted[$i]} ); $sth->execute( $sorted[$i], %hash->{$sorted[$i]} );
} }

View file

@ -1,7 +1,7 @@
require "functions.pl"; require "functions.pl";
#create or resume session #create or resume session
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI; $query = new CGI;
$session = new CGI::Session; $session = new CGI::Session;

View file

@ -1,6 +1,6 @@
require "functions.pl"; require "functions.pl";
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = CGI->new(\&hook); $query = CGI->new(\&hook);
$session = new CGI::Session; $session = new CGI::Session;

View file

@ -1,7 +1,7 @@
require "functions.pl"; require "functions.pl";
#initialize session data #initialize session data
CGI::Session->name($session_name); CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI; $query = new CGI;
$session = new CGI::Session; $session = new CGI::Session;