Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1205 → Rev 1224

/trunk/jrest/scripts/ExtracteurMeta.php
2,21 → 2,24
// declare(encoding='UTF-8');
/**
* Script d'extration des métadonnées des images pour intégration dans la BDD v2.
* Utilisation : /opt/lampp/bin/php cli.php ExtracteurMeta
*
* @category php 5.2
* @package Cel/Scripts
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
* @version $Id$
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
* @version $Id$
*/
class ExtracteurMeta {
 
const DROIT = 0705;
 
public $config;
public $bdd;
private $chemin_images = '';
private $bdd = null;
private $script = null;
 
private $idImg = null;
private $metaComplet = null;
27,61 → 30,73
private $metaAutres = null;
 
 
public function __construct($config, Conteneur $conteneur = null) {
// Tableau contenant la config de Jrest
$this->config = $config;
 
$conteneur = is_null($conteneur) ? new Conteneur($this->config) : $conteneur;
public function __construct(Conteneur $conteneur) {
$this->chemin_images = $conteneur->getParametre('cel.chemin_images');
$this->bdd = $conteneur->getBdd();
$this->script = $conteneur->getScript();
}
 
public function executer($arguments) {
$this->idImg = $arguments[0];
echo "EXTRACTION des MÉTADONNÉES\n";
echo "EXTRACTION des MÉTADONNÉES\n";
echo "Vérification config : ".$this->verifierConfig()."\n";
 
$cheminImage = $this->obtenirCheminImageOriginale($this->idImg);
$cmd = "exiftool -X -file:comment $cheminImage";
$metaFile = $this->executerCommandeSysteme($cmd);
$images = $this->obtenirImagesEnBdd();
foreach ($images as $img) {
$this->idImg = $img['id_image'];
 
$remplacement = 'NON';
if ($this->neccessiterRemplacement($metaFile) === true) {
$remplacement = 'OUI';
$cheminImage = $this->obtenirCheminImageOriginale($this->idImg);
if (file_exists($cheminImage)) {clear
$cmd = "exiftool -X -file:comment $cheminImage";
$metaFile = $this->executerCommandeSysteme($cmd);
 
$cmd = "exiftool -X -D -U -b -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -All $cheminImage";
$this->metaComplet = $this->executerCommandeSysteme($cmd);
if ($this->neccessiterRemplacement($metaFile) === true) {
//print "Remplacement : {$this->idImg} \n";
 
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -exif:all $cheminImage";
$this->exif = $this->executerCommandeSysteme($cmd);
$cmd = "exiftool -X -D -U -b -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -All $cheminImage";
$this->metaComplet = $this->executerCommandeSysteme($cmd);
 
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -iptc:all $cheminImage";
$this->iptc = $this->executerCommandeSysteme($cmd);
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -exif:all $cheminImage";
$this->exif = $this->executerCommandeSysteme($cmd);
 
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -xmp:all $cheminImage";
$this->xmp = $this->executerCommandeSysteme($cmd);
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -iptc:all $cheminImage";
$this->iptc = $this->executerCommandeSysteme($cmd);
 
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -makernotes:all $cheminImage";
$this->makerNotes = $this->executerCommandeSysteme($cmd);
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -xmp:all $cheminImage";
$this->xmp = $this->executerCommandeSysteme($cmd);
 
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' --exif:all --iptc:all --xmp:all --makernotes:all $cheminImage";
$this->metaAutres = $this->executerCommandeSysteme($cmd);
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -makernotes:all $cheminImage";
$this->makerNotes = $this->executerCommandeSysteme($cmd);
 
$this->ecrireFichierRdf();
$this->mettreAJourBdd();
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' --exif:all --iptc:all --xmp:all --makernotes:all $cheminImage";
$this->metaAutres = $this->executerCommandeSysteme($cmd);
 
$this->ecrireFichierRdf();
$this->mettreAJourBdd();
}
} else {
//print "Fichier image '{$this->idImg}' introuvable\n";
}
$this->script->afficherAvancement("Analyse des images");
}
echo "Remplacement : $remplacement \n";
print "\n";
}
 
private function verifierConfig() {
if (empty($this->config['cel']['chemin_images'])) {
$message = "Vous devez indiquer le dossier contenant la hiérarchie des images dans le paramètre : ".
"[cel] chemin_images";
$code = (string) E_USER_ERROR;
throw new Exception($message);
}
return 'OK';
private function verifierConfig() {
if (empty($this->chemin_images)) {
$message = "Vous devez indiquer le dossier contenant la hiérarchie des images dans le paramètre : ".
"[cel] chemin_images";
$code = (string) E_USER_ERROR;
throw new Exception($message);
}
return 'OK';
}
 
private function obtenirImagesEnBdd() {
$requete = 'SELECT id_image FROM cel_images ';
$images = $this->bdd->requeter($requete);
return $images;
}
 
private function executerCommandeSysteme($commande) {
$handle = popen($commande, 'r');
$metaXml = '';
92,17 → 107,17
return $metaXml;
}
 
private function obtenirCheminImageRDF($id_image) {
return $this->obtenirCheminImage($id_image, 'RDF', 'xml');
private function obtenirCheminImageRDF() {
return $this->obtenirCheminImage('RDF', 'xml');
}
 
private function obtenirCheminImageOriginale($id_image) {
return $this->obtenirCheminImage($id_image, 'O');
private function obtenirCheminImageOriginale() {
return $this->obtenirCheminImage('O');
}
 
private function obtenirCheminImage($id_image, $format, $extension = 'jpg') {
$nom = $this->convertirIdBddVersNomFichier($id_image, $format, $extension);
$cheminDossier = $this->obtenirDossierPourFormat($id_image, $format);
private function obtenirCheminImage($format, $extension = 'jpg') {
$nom = $this->convertirIdBddVersNomFichier($format, $extension);
$cheminDossier = $this->obtenirDossierPourFormat($format);
if (file_exists($cheminDossier) === false) {
$this->creerDossier($cheminDossier);
}
109,22 → 124,19
return $cheminDossier.'/'.$nom;
}
 
private function convertirIdBddVersNomFichier($id, $format, $extension) {
$id_avec_zeros = sprintf('%09s', $id) ;
private function convertirIdBddVersNomFichier($format, $extension) {
$id_avec_zeros = sprintf('%09s', $this->idImg) ;
$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
return $nom_fichier;
}
 
private function obtenirDossierPourFormat($id, $format) {
$chemin_base = $this->config['cel']['chemin_images'];
$chemin_sur_serveur = $chemin_base;
 
$id = sprintf('%09s', $id);
private function obtenirDossierPourFormat($format) {
$id = sprintf('%09s', $this->idImg);
$id = wordwrap($id, 3 , '_', true);
list($dossierNiveau1, $dossierNiveau2) = explode('_', $id);
 
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
$chemin_sur_serveur_final = $this->chemin_images.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
return $chemin_sur_serveur_final;
}