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-2013 - Distribué sous licence GNU/GPL |
---|
9 | * |
---|
10 | * Ecriture des tags ID3 ou vorbis |
---|
11 | */ |
---|
12 | |
---|
13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
---|
14 | |
---|
15 | /** |
---|
16 | * Enregistre dans les fichiers sons les tags ID3 |
---|
17 | * |
---|
18 | * @param int $id_document |
---|
19 | * L'identifiant numérique du document |
---|
20 | * @param array $infos |
---|
21 | * Un array des informations à écrire dans le fichier |
---|
22 | * @param array $images |
---|
23 | * Un array correspondant à la cover à ajouter au fichier |
---|
24 | * @param array $formats |
---|
25 | * Un array correspondant aux types de tags à écrire |
---|
26 | */ |
---|
27 | |
---|
28 | function inc_getid3_ecrire_infos($id_document,$infos=array(),$images=null,$formats = array('id3v1', 'id3v2.3')){ |
---|
29 | if(!intval($id_document)) |
---|
30 | return false; |
---|
31 | |
---|
32 | $document = sql_fetsel("fichier,distant,extension", "spip_documents","id_document=".intval($id_document)); |
---|
33 | |
---|
34 | if($document['distant'] != 'oui'){ |
---|
35 | |
---|
36 | if($document['extension'] == 'ogg'){ |
---|
37 | $formats = array('vorbiscomment'); |
---|
38 | $infos['date'] = $infos['year']; |
---|
39 | }else if($document['extension'] == 'flac'){ |
---|
40 | $formats = array('metaflac'); |
---|
41 | $infos['date'] = $infos['year']; |
---|
42 | } |
---|
43 | |
---|
44 | $err = $TagData = array(); |
---|
45 | |
---|
46 | include_spip('inc/documents'); |
---|
47 | $document_chemin = get_spip_doc($document['fichier']); |
---|
48 | |
---|
49 | include_spip('getid3/getid3'); |
---|
50 | $getid3 = new getID3; |
---|
51 | if(!$getid3) |
---|
52 | return false; |
---|
53 | |
---|
54 | include_spip('getid3/write'); |
---|
55 | $getid3->encoding = 'UTF-8'; |
---|
56 | $getid3->encoding_id3v1 = 'ISO-8859-1'; |
---|
57 | $getid3->option_tags_html = false; |
---|
58 | |
---|
59 | $ecrire = new getid3_writetags; |
---|
60 | $ecrire->filename = $document_chemin; |
---|
61 | $ecrire->tagformats = $formats; |
---|
62 | $ecrire->tag_encoding = 'UTF-8'; |
---|
63 | $ecrire->overwrite_tags = true; |
---|
64 | $ecrire->remove_other_tags = false; |
---|
65 | |
---|
66 | /** |
---|
67 | * On utilise nos valeurs |
---|
68 | */ |
---|
69 | foreach ($infos as $info => $value) { |
---|
70 | $TagData[$info][] = $value; |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * Ajout des images |
---|
75 | */ |
---|
76 | if(is_array($images)){ |
---|
77 | foreach ($images as $image){ |
---|
78 | if(!is_array($image) && strlen($image) > 0){ |
---|
79 | $image_finale['chemin'] = $image; |
---|
80 | $image_finale['picturetypeid'] = '3'; |
---|
81 | $image_finale['description'] = 'Front Cover'; |
---|
82 | $image_infos = getimagesize($image_finale['chemin']); |
---|
83 | $image_finale['mime'] = image_type_to_mime_type($image_infos[2]); |
---|
84 | $image = $image_finale; |
---|
85 | } |
---|
86 | if(is_array($image)){ |
---|
87 | if($formats[0] != 'metaflac'){ |
---|
88 | $TagData['attached_picture'][] = array( |
---|
89 | 'data' => file_get_contents($image['chemin']), |
---|
90 | 'picturetypeid' => $image['picturetypeid'], |
---|
91 | 'description' => $image['description'], |
---|
92 | 'mime' => $image['mime'] |
---|
93 | ); |
---|
94 | }else{ |
---|
95 | $TagData['attached_picture'][] = array( |
---|
96 | 'file' => $image['chemin'], |
---|
97 | 'picturetypeid' => $image['picturetypeid'], |
---|
98 | 'description' => $image['description'], |
---|
99 | 'mime' => $image['mime'] |
---|
100 | ); |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Le pipeline de pre_edition |
---|
108 | * Avant l'écriture des tags dans le fichier |
---|
109 | */ |
---|
110 | $TagData = pipeline('pre_edition', |
---|
111 | array( |
---|
112 | 'args' => array( |
---|
113 | 'table' => 'spip_documents', // compatibilite |
---|
114 | 'table_objet' => 'documents', |
---|
115 | 'spip_table_objet' => 'spip_documents', |
---|
116 | 'type' =>'document', |
---|
117 | 'id_objet' => $id_document, |
---|
118 | 'action' => 'getid3_ecrire_infos' |
---|
119 | ), |
---|
120 | 'data' => $TagData |
---|
121 | ) |
---|
122 | ); |
---|
123 | |
---|
124 | /** |
---|
125 | * On écrit le tout |
---|
126 | */ |
---|
127 | $ecrire->tag_data = $TagData; |
---|
128 | $ecrire->WriteTags(); |
---|
129 | |
---|
130 | /** |
---|
131 | * Les warnings |
---|
132 | */ |
---|
133 | if (!empty($ecrire->warnings)) |
---|
134 | $err = array_merge($err,$ecrire->warnings); |
---|
135 | |
---|
136 | /** |
---|
137 | * Les erreurs |
---|
138 | */ |
---|
139 | if (!empty($ecrire->errors)) |
---|
140 | $err = array_merge($err,$ecrire->errors); |
---|
141 | |
---|
142 | /** |
---|
143 | * Modification de la taille du document en base |
---|
144 | * car elle peut être modifiée par l'ajout de tags ou de cover |
---|
145 | */ |
---|
146 | $taille = filesize($document_chemin); |
---|
147 | include_spip('action/editer_document'); |
---|
148 | document_modifier($id_document, array('taille'=>$taille)); |
---|
149 | |
---|
150 | /** |
---|
151 | * Le pipeline de post_edition du document |
---|
152 | */ |
---|
153 | pipeline('post_edition', |
---|
154 | array( |
---|
155 | 'args' => array( |
---|
156 | 'table' => 'spip_documents', // compatibilite |
---|
157 | 'table_objet' => 'documents', |
---|
158 | 'spip_table_objet' => 'spip_documents', |
---|
159 | 'type' =>'document', |
---|
160 | 'id_objet' => $id_document, |
---|
161 | 'action' => 'getid3_ecrire_infos' |
---|
162 | ), |
---|
163 | 'data' => $infos |
---|
164 | ) |
---|
165 | ); |
---|
166 | } |
---|
167 | return $err; |
---|
168 | } |
---|
169 | ?> |
---|