[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / medias / metadata / audio.php
1 <?php
2 /**
3 * GetID3
4 * Gestion des métadonnées de fichiers sonores et vidéos directement dans SPIP
5 *
6 * Auteurs :
7 * kent1 (http://www.kent1.info - kent1@arscenic.info), BoOz
8 * 2008-2016 - Distribué sous licence GNU/GPL
9 *
10 * @package SPIP\GetID3\Metadatas
11 */
12
13 if (!defined('_ECRIRE_INC_VERSION')) {
14 return;
15 }
16
17 /**
18 * Fonction de récupération des métadonnées sur les fichiers audio
19 * appelée à l'insertion en base dans le plugin medias (inc/renseigner_document)
20 *
21 * @param string $file
22 * Le chemin du fichier à analyser
23 * @return array $metas
24 * Le tableau comprenant les différentes metas à mettre en base
25 */
26 function metadata_audio($file) {
27 $meta = array();
28
29 include_spip('lib/getid3/getid3');
30 $getID3 = new getID3;
31 $getID3->setOption(array('tempdir' => _DIR_TMP));
32
33 // Scan file - should parse correctly if file is not corrupted
34 $file_info = $getID3->analyze($file);
35
36 if (isset($file_info['id3v2']['comments']['title'])) {
37 $meta['titre'] = ucfirst(trim(implode(' ',$file_info['id3v2']['comments']['title'])));
38 }
39 if (isset($file_info['id3v2']['comments']['artist'])) {
40 $meta['credits'] = implode(', ',$file_info['id3v2']['comments']['artist']);
41 if (isset($file_info['id3v2']['comments']['album'])) {
42 $meta['credits'] .= '/'.trim(implode(' ',$file_info['id3v2']['comments']['album']));
43 }
44 if (isset($file_info['id3v2']['comments']['year'])) {
45 $meta['credits'] .= ' ('.trim(implode(' ',$file_info['id3v2']['comments']['year'])).')';
46 }
47 }
48 if (isset($file_info['playtime_seconds'])) {
49 $meta['duree'] = round($file_info['playtime_seconds'], 0);
50 }
51
52 return $meta;
53 }