3553f3f6cc377f1520ce6a93e4edbd054bb517fc
[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 header('Content-Type: text/plain');
37 if (isset($file_info['id3v2']['comments']['title'])) {
38 $meta['titre'] = ucfirst(trim(implode(' ',$file_info['id3v2']['comments']['title'])));
39 }
40 if (isset($file_info['id3v2']['comments']['artist'])) {
41 $meta['credits'] = implode(', ',$file_info['id3v2']['comments']['artist']);
42 if (isset($file_info['id3v2']['comments']['album'])) {
43 $meta['credits'] .= '/'.trim(implode(' ',$file_info['id3v2']['comments']['album']));
44 }
45 if (isset($file_info['id3v2']['comments']['year'])) {
46 $meta['credits'] .= ' ('.trim(implode(' ',$file_info['id3v2']['comments']['year'])).')';
47 }
48 }
49 if (isset($file_info['playtime_seconds'])) {
50 $meta['duree'] = round($file_info['playtime_seconds'], 0);
51 }
52
53 return $meta;
54 }