The storageAdmin module added with import script.
This commit is contained in:
parent
50930e9367
commit
cd32653d6c
4 changed files with 346 additions and 0 deletions
120
livesupport/modules/storageAdmin/bin/import.sh
Executable file
120
livesupport/modules/storageAdmin/bin/import.sh
Executable file
|
@ -0,0 +1,120 @@
|
|||
#!/bin/bash
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2004 Media Development Loan Fund
|
||||
#
|
||||
# This file is part of the LiveSupport project.
|
||||
# http://livesupport.campware.org/
|
||||
# To report bugs, send an e-mail to bugs@campware.org
|
||||
#
|
||||
# LiveSupport is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LiveSupport is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LiveSupport; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# Author : $Author: tomas $
|
||||
# Version : $Revision: 1.1 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/bin/import.sh,v $
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# This script imports audio files to LiveSupport storageServer.
|
||||
#
|
||||
# To get usage help, try the -h option
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Determine directories, files
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
reldir=`dirname $0`/..
|
||||
phpdir=`cd $reldir/bin/php; pwd`
|
||||
filelistpathname=.
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Print the usage information for this script.
|
||||
#-------------------------------------------------------------------------------
|
||||
printUsage()
|
||||
{
|
||||
echo "LiveSupport import script.";
|
||||
echo "parameters:";
|
||||
echo "";
|
||||
echo " -d, --directory The source directory, required;";
|
||||
echo " will be readed recursively.";
|
||||
echo " -l, --list The filename with list of absolute filepaths";
|
||||
echo " (newline-separated).";
|
||||
echo " -h, --help Print this message and exit.";
|
||||
echo "";
|
||||
echo "Usage:";
|
||||
echo " $0 -d <directory>";
|
||||
echo " $0 -l <listfile>";
|
||||
echo " $0 -h";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Process command line parameters
|
||||
#-------------------------------------------------------------------------------
|
||||
CMD=${0##*/}
|
||||
|
||||
opts=$(getopt -o d:l:h -l directory:,list:,help -n $CMD -- "$@") || exit 1
|
||||
eval set -- "$opts"
|
||||
while true; do
|
||||
case "$1" in
|
||||
-d|--directory)
|
||||
srcdir=$2;
|
||||
srcabsdir=`cd "$srcdir"; pwd`
|
||||
shift; shift;;
|
||||
-l|--list)
|
||||
filelist=$2;
|
||||
filelistbasename=`basename "$filelist"`
|
||||
filelistdir=`dirname "$filelist"`
|
||||
filelistabsdir=`cd "$filelistdir"; pwd`
|
||||
filelistpathname=$filelistabsdir/$filelistbasename
|
||||
shift; shift;;
|
||||
-h|--help)
|
||||
printUsage;
|
||||
exit 0;;
|
||||
--)
|
||||
shift;
|
||||
break;;
|
||||
*)
|
||||
echo "Unrecognized option $1.";
|
||||
printUsage;
|
||||
exit 1;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "x$srcabsdir" == "x" -a "x$filelist" == "x" ]; then
|
||||
echo "Directory or filelist option required.";
|
||||
printUsage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Do recursive import
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
cd $phpdir
|
||||
|
||||
if [ -f "$filelistpathname" ]; then
|
||||
cat "$filelistpathname" | php -q import.php || exit 1
|
||||
fi
|
||||
|
||||
if [ -d "$srcabsdir" ]; then
|
||||
find "$srcabsdir" -type f | php -q import.php || exit 1
|
||||
else
|
||||
echo "Warning: not a directory: $srcabsdir"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Say goodbye
|
||||
#-------------------------------------------------------------------------------
|
||||
echo "Import completed."
|
32
livesupport/modules/storageAdmin/bin/php/conf.php
Normal file
32
livesupport/modules/storageAdmin/bin/php/conf.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/bin/php/Attic/conf.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
$storageServerPath = dirname(__FILE__)."/../../../storageServer";
|
||||
?>
|
32
livesupport/modules/storageAdmin/bin/php/conf.php.template
Normal file
32
livesupport/modules/storageAdmin/bin/php/conf.php.template
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/bin/php/Attic/conf.php.template,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
$storageServerPath = 'ls_install_dir/var/storageServer';
|
||||
?>
|
162
livesupport/modules/storageAdmin/bin/php/import.php
Normal file
162
livesupport/modules/storageAdmin/bin/php/import.php
Normal file
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/bin/php/Attic/import.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
header("Content-type: text/plain");
|
||||
echo "\n#StorageServer import script:\n";
|
||||
//echo date('H:i:s')."\n";
|
||||
$start=intval(date('U'));
|
||||
|
||||
require_once 'conf.php';
|
||||
require_once "$storageServerPath/var/conf.php";
|
||||
require_once 'DB.php';
|
||||
require_once "$storageServerPath/var/GreenBox.php";
|
||||
|
||||
#PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
|
||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
$dbc = DB::connect($config['dsn'], TRUE);
|
||||
if(PEAR::isError($dbc)){ echo "ERROR: ".$dbc->getMessage()." ".$dbc->getUserInfo()."\n"; exit(1); }
|
||||
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
$gb = &new GreenBox($dbc, $config);
|
||||
|
||||
$errors=0;
|
||||
$filecount=0;
|
||||
function _err($r, $fn){
|
||||
global $errors;
|
||||
echo "ERROR\n ".$r->getMessage()." ".$r->getUserInfo()."\n";
|
||||
$errors++;
|
||||
}
|
||||
|
||||
$flds = array(
|
||||
// 'fileformat' => NULL,
|
||||
'mime_type' => 'dc:format',
|
||||
'bitrate' => 'ls:bitrate',
|
||||
'playtime_seconds' => 'dcterms:extent',
|
||||
'tags' => array(
|
||||
'TT2' => 'dc:title',
|
||||
'TIT2' => 'dc:title',
|
||||
'TP1' => 'dc:creator',
|
||||
'TPE1' => 'dc:creator',
|
||||
'TAL' => 'dc:source',
|
||||
'TALB' => 'dc:source',
|
||||
// 'TCO' => NULL,
|
||||
'TEN' => 'ls:encoded_by',
|
||||
'TENC' => 'ls:encoded_by',
|
||||
'TRK' => 'ls:track_num',
|
||||
'TRCK' => 'ls:track_num',
|
||||
),
|
||||
'audio' => array(
|
||||
'channels' => 'ls:channels',
|
||||
// 'bitrate' => 'ls:bitrate',
|
||||
),
|
||||
'comments' => array(
|
||||
'genre' => 'dc:type',
|
||||
// 'genreid' => 'GENREID',
|
||||
),
|
||||
'filename' => 'ls:filename',
|
||||
);
|
||||
|
||||
$r = $gb->getObjId('import', $gb->storId);
|
||||
if(PEAR::isError($r)){ echo "ERROR: ".$r->getMessage()." ".$r->getUserInfo()."\n"; exit(1); }
|
||||
if(is_null($r)){
|
||||
$r = $gb->bsCreateFolder($gb->storId, 'import');
|
||||
if(PEAR::isError($r)){ echo "ERROR: ".$r->getMessage()." ".$r->getUserInfo()."\n"; exit(1); }
|
||||
}
|
||||
$parid = $r;
|
||||
|
||||
$stdin = fopen('php://stdin', 'r');
|
||||
while($filename = fgets($stdin, 2048)){
|
||||
$filename = rtrim($filename);
|
||||
echo "$filename: ";
|
||||
set_time_limit(30);
|
||||
$ia = GetAllFileInfo("$filename", 'mp3');
|
||||
if(PEAR::isError($ia)){ _err($ia, $filename); continue; }
|
||||
if(!$ia['fileformat']){ echo "???\n"; continue; }
|
||||
|
||||
$mdata = array();
|
||||
foreach($flds as $k1=>$fn1){
|
||||
if(is_null($fn1)) continue;
|
||||
list($fn, $v) = array($fn1, $ia[$k1]);
|
||||
if(is_array($fn1)){
|
||||
$k0 = $k1;
|
||||
if($k0=='tags') $k1=$ia['tags'][0];
|
||||
list($fn, $v) = array($fn1, $ia[$k1]);
|
||||
foreach($fn1 as $k2=>$fn2){
|
||||
if(is_null($fn2)) continue;
|
||||
if(!isset($ia[$k1][$k2])) continue;
|
||||
switch($k0){
|
||||
case"tags":
|
||||
list($fn, $v) = array($fn2, $ia[$k1][$k2]['data']);
|
||||
$enc = $ia[$k1][$k2]['encoding'];
|
||||
if($enc != 'UTF-8' && $enc != 'ISO-8859-1'){
|
||||
echo " Warning: wrong encoding '$enc' in $fn2.\n";
|
||||
}
|
||||
break;
|
||||
case"comments":
|
||||
list($fn, $v) = array($fn2, $ia[$k1][$k2][0]);
|
||||
break;
|
||||
default;
|
||||
list($fn, $v) = array($fn2, $ia[$k1][$k2]);
|
||||
}
|
||||
# if(is_array($fn)) var_dump($fn);
|
||||
if(!is_null($v)) $mdata[$fn] = addslashes($v);
|
||||
}
|
||||
}else{
|
||||
switch($fn){
|
||||
case"dcterms:extent":
|
||||
list($fn, $v) = array($fn1, round($ia[$k1], 6));
|
||||
break;
|
||||
default:
|
||||
list($fn, $v) = array($fn1, $ia[$k1]);
|
||||
}
|
||||
if(!is_null($v)) $mdata[$fn] = addslashes($v);
|
||||
}
|
||||
}
|
||||
|
||||
$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; }
|
||||
$id = $r;
|
||||
|
||||
$r = $gb->bsSetMetadataBatch($id, $mdata);
|
||||
if(PEAR::isError($r)){ _err($r, $filename); echo var_export($mdata)."\n"; continue; }
|
||||
|
||||
# $r = $gb->bsGetMetadata($id);
|
||||
# if(PEAR::isError($r)){ _err($r, $filename); continue; }
|
||||
# echo "$r\n";
|
||||
echo "OK\n";
|
||||
$filecount++;
|
||||
}
|
||||
|
||||
fclose($stdin);
|
||||
$end = intval(date('U'));
|
||||
//echo date('H:i:s')."\n";
|
||||
$time = $end-$start;
|
||||
if($time>0) $speed = round(($filecount+$errors)/$time, 1);
|
||||
else $speed = "N/A";
|
||||
echo " File imported: $filecount, in $time s, $speed files/s, errors: $errors\n";
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue