Subversion Repositories eFlore/Applications.cel

Rev

Rev 1205 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1205 Rev 1224
Line 1... Line 1...
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Script d'extration des métadonnées des images pour intégration dans la BDD v2.
4
 * Script d'extration des métadonnées des images pour intégration dans la BDD v2.
-
 
5
 * Utilisation : /opt/lampp/bin/php cli.php ExtracteurMeta
5
 *
6
 *
6
 * @category	php 5.2
7
 * @category	php 5.2
7
 * @package		Cel/Scripts
8
 * @package		Cel/Scripts
-
 
9
 * @author		Aurelien PERONNET <aurelien@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @copyright	Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
11
 * @copyright	Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
10
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
 * @version	$Id$
14
 * @version		$Id$
13
 */
15
 */
14
class ExtracteurMeta {
16
class ExtracteurMeta {
Line 15... Line 17...
15
 
17
 
Line 16... Line 18...
16
	const DROIT = 0705;
18
	const DROIT = 0705;
17
 
19
 
-
 
20
	private $chemin_images = '';
Line 18... Line 21...
18
	public $config;
21
	private $bdd = null;
19
	public $bdd;
22
	private $script = null;
20
 
23
 
21
	private $idImg = null;
24
	private $idImg = null;
22
	private $metaComplet = null;
25
	private $metaComplet = null;
23
	private $exif = null;
26
	private $exif = null;
24
	private $iptc = null;
27
	private $iptc = null;
Line 25... Line 28...
25
	private $xmp = null;
28
	private $xmp = null;
26
	private $makerNotes = null;
-
 
27
	private $metaAutres = null;
-
 
28
 
-
 
29
 
29
	private $makerNotes = null;
30
	public function __construct($config, Conteneur $conteneur = null) {
30
	private $metaAutres = null;
-
 
31
 
31
		// Tableau contenant la config de Jrest
32
 
Line 32... Line 33...
32
		$this->config = $config;
33
	public function __construct(Conteneur $conteneur) {
33
 
-
 
34
		$conteneur = is_null($conteneur) ? new Conteneur($this->config) : $conteneur;
34
		$this->chemin_images = $conteneur->getParametre('cel.chemin_images');
35
		$this->bdd = $conteneur->getBdd();
35
		$this->bdd = $conteneur->getBdd();
Line -... Line 36...
-
 
36
		$this->script = $conteneur->getScript();
-
 
37
	}
-
 
38
 
-
 
39
	public function executer($arguments) {
36
	}
40
		echo "EXTRACTION des MÉTADONNÉES\n";
-
 
41
		echo "Vérification config : ".$this->verifierConfig()."\n";
37
 
42
 
38
	public function executer($arguments) {
43
		$images = $this->obtenirImagesEnBdd();
39
		$this->idImg = $arguments[0];
44
		foreach ($images as $img) {
40
		echo "EXTRACTION des MÉTADONNÉES\n";
-
 
41
		echo "Vérification config : ".$this->verifierConfig()."\n";
45
			$this->idImg = $img['id_image'];
42
 
46
 
43
		$cheminImage = $this->obtenirCheminImageOriginale($this->idImg);
47
			$cheminImage = $this->obtenirCheminImageOriginale($this->idImg);
44
		$cmd = "exiftool -X -file:comment $cheminImage";
48
			if (file_exists($cheminImage)) {clear
45
		$metaFile = $this->executerCommandeSysteme($cmd);
49
				$cmd = "exiftool -X -file:comment $cheminImage";
46
 
50
				$metaFile = $this->executerCommandeSysteme($cmd);
47
		$remplacement = 'NON';
51
 
48
		if ($this->neccessiterRemplacement($metaFile) === true) {
52
				if ($this->neccessiterRemplacement($metaFile) === true) {
49
			$remplacement = 'OUI';
53
					//print "Remplacement : {$this->idImg} \n";
50
 
54
 
51
			$cmd = "exiftool -X -D -U -b -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -All $cheminImage";
55
					$cmd = "exiftool -X -D -U -b -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -All $cheminImage";
52
			$this->metaComplet = $this->executerCommandeSysteme($cmd);
56
					$this->metaComplet = $this->executerCommandeSysteme($cmd);
53
 
57
 
54
			$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -exif:all $cheminImage";
58
					$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -exif:all $cheminImage";
55
			$this->exif = $this->executerCommandeSysteme($cmd);
59
					$this->exif = $this->executerCommandeSysteme($cmd);
56
 
60
 
57
			$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -iptc:all $cheminImage";
61
					$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -iptc:all $cheminImage";
58
			$this->iptc = $this->executerCommandeSysteme($cmd);
62
					$this->iptc = $this->executerCommandeSysteme($cmd);
59
 
63
 
60
			$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -xmp:all $cheminImage";
64
					$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -xmp:all $cheminImage";
61
			$this->xmp = $this->executerCommandeSysteme($cmd);
65
					$this->xmp = $this->executerCommandeSysteme($cmd);
62
 
66
 
63
			$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -makernotes:all $cheminImage";
67
					$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -makernotes:all $cheminImage";
-
 
68
					$this->makerNotes = $this->executerCommandeSysteme($cmd);
-
 
69
 
-
 
70
					$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' --exif:all --iptc:all --xmp:all --makernotes:all $cheminImage";
-
 
71
					$this->metaAutres = $this->executerCommandeSysteme($cmd);
-
 
72
 
64
			$this->makerNotes = $this->executerCommandeSysteme($cmd);
73
					$this->ecrireFichierRdf();
65
 
74
					$this->mettreAJourBdd();
66
			$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' --exif:all --iptc:all --xmp:all --makernotes:all $cheminImage";
75
				}
Line 67... Line 76...
67
			$this->metaAutres = $this->executerCommandeSysteme($cmd);
76
			} else {
68
 
77
				//print "Fichier image '{$this->idImg}' introuvable\n";
69
			$this->ecrireFichierRdf();
78
			}
70
			$this->mettreAJourBdd();
79
			$this->script->afficherAvancement("Analyse des images");
71
		}
80
		}
72
		echo "Remplacement : $remplacement \n";
81
		print "\n";
73
	}
82
	}
74
 
83
 
-
 
84
	private function verifierConfig() {
-
 
85
		if (empty($this->chemin_images)) {
-
 
86
			$message = "Vous devez indiquer le dossier contenant la hiérarchie des images dans le paramètre : ".
-
 
87
					"[cel] chemin_images";
-
 
88
			$code = (string) E_USER_ERROR;
-
 
89
			throw new Exception($message);
75
	private function verifierConfig() {
90
		}
Line 76... Line 91...
76
		if (empty($this->config['cel']['chemin_images'])) {
91
		return 'OK';
77
			$message = "Vous devez indiquer le dossier contenant la hiérarchie des images dans le paramètre : ".
92
	}
78
				"[cel] chemin_images";
93
 
Line 90... Line 105...
90
		}
105
		}
91
		fclose($handle);
106
		fclose($handle);
92
		return $metaXml;
107
		return $metaXml;
93
	}
108
	}
Line 94... Line 109...
94
 
109
 
95
	private function obtenirCheminImageRDF($id_image) {
110
	private function obtenirCheminImageRDF() {
96
		return $this->obtenirCheminImage($id_image, 'RDF', 'xml');
111
		return $this->obtenirCheminImage('RDF', 'xml');
Line 97... Line 112...
97
	}
112
	}
98
 
113
 
99
	private function obtenirCheminImageOriginale($id_image) {
114
	private function obtenirCheminImageOriginale() {
Line 100... Line 115...
100
		return $this->obtenirCheminImage($id_image, 'O');
115
		return $this->obtenirCheminImage('O');
101
	}
116
	}
102
 
117
 
103
	private function obtenirCheminImage($id_image, $format, $extension = 'jpg') {
118
	private function obtenirCheminImage($format, $extension = 'jpg') {
104
		$nom = $this->convertirIdBddVersNomFichier($id_image, $format, $extension);
119
		$nom = $this->convertirIdBddVersNomFichier($format, $extension);
105
		$cheminDossier = $this->obtenirDossierPourFormat($id_image, $format);
120
		$cheminDossier = $this->obtenirDossierPourFormat($format);
106
		if (file_exists($cheminDossier) === false) {
121
		if (file_exists($cheminDossier) === false) {
107
			$this->creerDossier($cheminDossier);
122
			$this->creerDossier($cheminDossier);
Line 108... Line 123...
108
		}
123
		}
109
		return $cheminDossier.'/'.$nom;
124
		return $cheminDossier.'/'.$nom;
110
	}
125
	}
111
 
126
 
112
	private function convertirIdBddVersNomFichier($id, $format, $extension) {
127
	private function convertirIdBddVersNomFichier($format, $extension) {
113
		$id_avec_zeros = sprintf('%09s', $id) ;
128
		$id_avec_zeros = sprintf('%09s', $this->idImg) ;
Line 114... Line 129...
114
		$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
129
		$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
115
		$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
-
 
116
		return $nom_fichier;
-
 
117
	}
-
 
118
 
130
		$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
119
	private function obtenirDossierPourFormat($id, $format) {
131
		return $nom_fichier;
120
		$chemin_base = $this->config['cel']['chemin_images'];
132
	}
Line 121... Line 133...
121
		$chemin_sur_serveur = $chemin_base;
133
 
122
 
134
	private function obtenirDossierPourFormat($format) {
123
		$id = sprintf('%09s', $id);
135
		$id = sprintf('%09s', $this->idImg);
Line 124... Line 136...
124
		$id = wordwrap($id, 3 , '_', true);
136
		$id = wordwrap($id, 3 , '_', true);
125
		list($dossierNiveau1, $dossierNiveau2) = explode('_', $id);
137
		list($dossierNiveau1, $dossierNiveau2) = explode('_', $id);