Reformatted to Campware PHP coding conventions.
This commit is contained in:
parent
a988446e12
commit
c63be46437
1 changed files with 102 additions and 49 deletions
|
@ -9,16 +9,19 @@ echo "\n#StorageServer import script:\n";
|
||||||
//echo date('H:i:s')."\n";
|
//echo date('H:i:s')."\n";
|
||||||
$start = intval(date('U'));
|
$start = intval(date('U'));
|
||||||
|
|
||||||
require_once 'conf.php';
|
require_once('conf.php');
|
||||||
require_once "$storageServerPath/var/conf.php";
|
require_once("$storageServerPath/var/conf.php");
|
||||||
require_once 'DB.php';
|
require_once('DB.php');
|
||||||
require_once "$storageServerPath/var/GreenBox.php";
|
require_once("$storageServerPath/var/GreenBox.php");
|
||||||
|
|
||||||
//PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
|
//PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
|
||||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||||
//PEAR::setErrorHandling(PEAR_ERROR_DIE, "%s\n");
|
//PEAR::setErrorHandling(PEAR_ERROR_DIE, "%s\n");
|
||||||
$dbc = DB::connect($config['dsn'], TRUE);
|
$dbc = DB::connect($config['dsn'], TRUE);
|
||||||
if(PEAR::isError($dbc)){ echo "ERROR: ".$dbc->getMessage()." ".$dbc->getUserInfo()."\n"; exit(1); }
|
if (PEAR::isError($dbc)) {
|
||||||
|
echo "ERROR: ".$dbc->getMessage()." ".$dbc->getUserInfo()."\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||||
$gb = &new GreenBox($dbc, $config);
|
$gb = &new GreenBox($dbc, $config);
|
||||||
|
|
||||||
|
@ -26,10 +29,15 @@ $testonly = (isset($argv[1]) && $argv[1] == '-t');
|
||||||
|
|
||||||
$errors = 0;
|
$errors = 0;
|
||||||
$filecount = 0;
|
$filecount = 0;
|
||||||
function _err($r, $fn, $txt=''){
|
|
||||||
|
function _err($r, $fn, $txt='')
|
||||||
|
{
|
||||||
global $errors;
|
global $errors;
|
||||||
if(PEAR::isError($r)) $msg = $r->getMessage()." ".$r->getUserInfo();
|
if (PEAR::isError($r)) {
|
||||||
else $msg = $txt;
|
$msg = $r->getMessage()." ".$r->getUserInfo();
|
||||||
|
} else {
|
||||||
|
$msg = $txt;
|
||||||
|
}
|
||||||
echo "ERROR\n $msg\n";
|
echo "ERROR\n $msg\n";
|
||||||
$errors++;
|
$errors++;
|
||||||
}
|
}
|
||||||
|
@ -90,14 +98,21 @@ $flds = array(
|
||||||
$titleKey = 'dc:title';
|
$titleKey = 'dc:title';
|
||||||
|
|
||||||
$r = $gb->getObjId('import', $gb->storId);
|
$r = $gb->getObjId('import', $gb->storId);
|
||||||
if(PEAR::isError($r)){ echo "ERROR: ".$r->getMessage()." ".$r->getUserInfo()."\n"; exit(1); }
|
if (PEAR::isError($r)) {
|
||||||
|
echo "ERROR: ".$r->getMessage()." ".$r->getUserInfo()."\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
if (is_null($r)) {
|
if (is_null($r)) {
|
||||||
$r = $gb->bsCreateFolder($gb->storId, 'import');
|
$r = $gb->bsCreateFolder($gb->storId, 'import');
|
||||||
if(PEAR::isError($r)){ echo "ERROR: ".$r->getMessage()." ".$r->getUserInfo()."\n"; exit(1); }
|
if (PEAR::isError($r)) {
|
||||||
|
echo "ERROR: ".$r->getMessage()." ".$r->getUserInfo()."\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$parid = $r;
|
$parid = $r;
|
||||||
|
|
||||||
function addMdata($key, $val, $iEnc='iso-8859-1'){
|
function addMdata($key, $val, $iEnc='iso-8859-1')
|
||||||
|
{
|
||||||
global $mdata, $titleHaveSet, $titleKey;
|
global $mdata, $titleHaveSet, $titleKey;
|
||||||
#echo "$key($iEnc): $val\n";
|
#echo "$key($iEnc): $val\n";
|
||||||
if (!is_null($val)) {
|
if (!is_null($val)) {
|
||||||
|
@ -110,7 +125,9 @@ function addMdata($key, $val, $iEnc='iso-8859-1'){
|
||||||
$data = $val; // fallback
|
$data = $val; // fallback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($key == $titleKey) $titleHaveSet = TRUE;
|
if ($key == $titleKey) {
|
||||||
|
$titleHaveSet = TRUE;
|
||||||
|
}
|
||||||
$mdata[$key] = trim($data);
|
$mdata[$key] = trim($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,15 +146,26 @@ while($filename = fgets($stdin, 2048)){
|
||||||
$getID3 = new getID3;
|
$getID3 = new getID3;
|
||||||
$infoFromFile = $getID3->analyze("$filename");
|
$infoFromFile = $getID3->analyze("$filename");
|
||||||
//echo "\n".var_export($infoFromFile)."\n"; exit;
|
//echo "\n".var_export($infoFromFile)."\n"; exit;
|
||||||
if(PEAR::isError($infoFromFile)){ _err($infoFromFile, $filename); continue; }
|
if (PEAR::isError($infoFromFile)) {
|
||||||
if(isset($infoFromFile['error'])){ _err(NULL, $filename, $infoFromFile['error']); continue; }
|
_err($infoFromFile, $filename);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isset($infoFromFile['error'])) {
|
||||||
|
_err(NULL, $filename, $infoFromFile['error']);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#if(!$infoFromFile['fileformat']){ echo "???\n"; continue; }
|
#if(!$infoFromFile['fileformat']){ echo "???\n"; continue; }
|
||||||
if(!$infoFromFile['bitrate']){ echo "not audio?\n"; continue; }
|
if (!$infoFromFile['bitrate']) {
|
||||||
|
echo "not audio?\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$mdata = array();
|
$mdata = array();
|
||||||
$titleHaveSet = FALSE;
|
$titleHaveSet = FALSE;
|
||||||
foreach ($flds as $key => $getid3keys) {
|
foreach ($flds as $key => $getid3keys) {
|
||||||
if($testonly) echo "$key\n";
|
if ($testonly) {
|
||||||
|
echo "$key\n";
|
||||||
|
}
|
||||||
foreach ($getid3keys as $getid3key) {
|
foreach ($getid3keys as $getid3key) {
|
||||||
// defaults:
|
// defaults:
|
||||||
$ignoreEnc = FALSE;
|
$ignoreEnc = FALSE;
|
||||||
|
@ -146,11 +174,15 @@ while($filename = fgets($stdin, 2048)){
|
||||||
$enc = "UTF-8";
|
$enc = "UTF-8";
|
||||||
extract($getid3key);
|
extract($getid3key);
|
||||||
$vn = "\$infoFromFile$path$dataPath";
|
$vn = "\$infoFromFile$path$dataPath";
|
||||||
if($testonly) echo " $vn -> ";
|
if ($testonly) {
|
||||||
|
echo " $vn -> ";
|
||||||
|
}
|
||||||
eval("\$vnFl = isset($vn);");
|
eval("\$vnFl = isset($vn);");
|
||||||
if ($vnFl) {
|
if ($vnFl) {
|
||||||
eval("\$data = $vn;");
|
eval("\$data = $vn;");
|
||||||
if($testonly) echo "$data\n";
|
if ($testonly) {
|
||||||
|
echo "$data\n";
|
||||||
|
}
|
||||||
if (!$ignoreEnc && $encPath != "") {
|
if (!$ignoreEnc && $encPath != "") {
|
||||||
$encVn = "\$infoFromFile$path$encPath";
|
$encVn = "\$infoFromFile$path$encPath";
|
||||||
eval("\$encVnFl = isset($encVn);");
|
eval("\$encVnFl = isset($encVn);");
|
||||||
|
@ -158,29 +190,47 @@ while($filename = fgets($stdin, 2048)){
|
||||||
eval("\$enc = $encVn;");
|
eval("\$enc = $encVn;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($testonly) echo " ENC=$enc\n";
|
if ($testonly) {
|
||||||
|
echo " ENC=$enc\n";
|
||||||
|
}
|
||||||
//addMdata($key, $data);
|
//addMdata($key, $data);
|
||||||
addMdata($key, $data, $enc);
|
addMdata($key, $data, $enc);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if($testonly) echo "\n";
|
if ($testonly) {
|
||||||
|
echo "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($testonly) var_dump($mdata);
|
}
|
||||||
|
if ($testonly) {
|
||||||
|
var_dump($mdata);
|
||||||
|
}
|
||||||
|
|
||||||
if(!$titleHaveSet || trim($mdata[$titleKey])=='') addMdata($titleKey, basename($filename));
|
if (!$titleHaveSet || trim($mdata[$titleKey]) == '') {
|
||||||
|
addMdata($titleKey, basename($filename));
|
||||||
|
}
|
||||||
|
|
||||||
if (!$testonly) {
|
if (!$testonly) {
|
||||||
$r = $gb->bsPutFile($parid, $mdata['ls:filename'], "$filename", "$storageServerPath/var/emptyMdata.xml", NULL, 'audioclip');
|
$r = $gb->bsPutFile($parid, $mdata['ls:filename'], "$filename", "$storageServerPath/var/emptyMdata.xml", NULL, 'audioclip');
|
||||||
if(PEAR::isError($r)){ _err($r, $filename); echo var_export($mdata)."\n"; continue; }
|
if (PEAR::isError($r)) {
|
||||||
|
_err($r, $filename);
|
||||||
|
echo var_export($mdata)."\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$id = $r;
|
$id = $r;
|
||||||
|
|
||||||
$r = $gb->bsSetMetadataBatch($id, $mdata);
|
$r = $gb->bsSetMetadataBatch($id, $mdata);
|
||||||
if(PEAR::isError($r)){ _err($r, $filename); echo var_export($mdata)."\n"; continue; }
|
if (PEAR::isError($r)) {
|
||||||
|
_err($r, $filename);
|
||||||
|
echo var_export($mdata)."\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var_dump($infoFromFile); echo"======================= ";
|
var_dump($infoFromFile);
|
||||||
var_dump($mdata); echo"======================= ";
|
echo"======================= ";
|
||||||
|
var_dump($mdata);
|
||||||
|
echo"======================= ";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "OK\n";
|
echo "OK\n";
|
||||||
|
@ -191,7 +241,10 @@ fclose($stdin);
|
||||||
$end = intval(date('U'));
|
$end = intval(date('U'));
|
||||||
//echo date('H:i:s')."\n";
|
//echo date('H:i:s')."\n";
|
||||||
$time = $end - $start;
|
$time = $end - $start;
|
||||||
if($time>0) $speed = round(($filecount+$errors)/$time, 1);
|
if ($time > 0) {
|
||||||
else $speed = "N/A";
|
$speed = round(($filecount+$errors)/$time, 1);
|
||||||
|
} else {
|
||||||
|
$speed = "N/A";
|
||||||
|
}
|
||||||
echo " Files ".($testonly ? "analyzed" : "imported").": $filecount, in $time s, $speed files/s, errors: $errors\n";
|
echo " Files ".($testonly ? "analyzed" : "imported").": $filecount, in $time s, $speed files/s, errors: $errors\n";
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue