<?
include "../include/database_config.php";
$vtable = "se_videos";
$dir = $_SERVER["DOCUMENT_ROOT"]."/uploads_video/encoding/jobs";
$count = 1;
$max_count = 3;
$mysql_link = mysql_connect( $database_host, $database_username, $database_password) or die('Could not connect to mysql server.' );
mysql_select_db($database_name, $mysql_link) or die('Could not select database.');
$d = dir($dir);
while (false !== ($entry = $d->read())) {
echo $entry." - ";
$pieces = explode(".", $entry);
if($pieces[1] == "bat") {
echo "File is correct. Processing...<br>\n";
$report = `$dir/$entry`;
ereg ("Duration: [0-9][0-9]:[0-9][0-9]:[0-9][0-9]", $report, $time);
$time[0] = strtr($time[0], "Duration: ", "");
$duration = explode(":", $time[0]);
$hour = $duration[1] * 60 * 60;
$minutes = $duration[2] * 60;
$allduration = $hour + $minutes + $duration[3];
echo "Movie duration: $allduration<br>\n";
echo "Entering movie information in data base...<br>\n";
$query_st = "UPDATE ".$vtable." SET video_is_converted=1 WHERE video_id=".$pieces[0];
$query_dur = "UPDATE ".$vtable." SET video_duration_in_sec=".$allduration." WHERE video_id=".$pieces[0];
mysql_query($query_st) or die(mysql_error());
mysql_query($query_dur) or die(mysql_error());
unlink($dir."/".$entry);
echo "File procession end.<br><br>\n\n";
$count++;
} else {
echo "Incorrect file, skipping (Extension: ".$pieces[1].")<br>\n";
}
if($count == $max_count) {
die("Max File Processing");
}
}
$d->close();
mysql_close();
?>