|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// +----------------------------------------------------------------------+ |
|
4
|
|
|
// | PHP version 4.1.0 | |
|
5
|
|
|
// +----------------------------------------------------------------------+ |
|
6
|
|
|
// | Placed in public domain by Allan Hansen, 2002. Share and enjoy! | |
|
7
|
|
|
// +----------------------------------------------------------------------+ |
|
8
|
|
|
// | /demo/demo.audioinfo.class.php | |
|
9
|
|
|
// | | |
|
10
|
|
|
// | Example wrapper class to extract information from audio files | |
|
11
|
|
|
// | through getID3(). | |
|
12
|
|
|
// | | |
|
13
|
|
|
// | getID3() returns a lot of information. Much of this information is | |
|
14
|
|
|
// | not needed for the end-application. It is also possible that some | |
|
15
|
|
|
// | users want to extract specific info. Modifying getID3() files is a | |
|
16
|
|
|
// | bad idea, as modifications needs to be done to future versions of | |
|
17
|
|
|
// | getID3(). | |
|
18
|
|
|
// | | |
|
19
|
|
|
// | Modify this wrapper class instead. This example extracts certain | |
|
20
|
|
|
// | fields only and adds a new root value - encoder_options if possible. | |
|
21
|
|
|
// | It also checks for mp3 files with wave headers. | |
|
22
|
|
|
// +----------------------------------------------------------------------+ |
|
23
|
|
|
// | Example code: | |
|
24
|
|
|
// | $au = new AudioInfo(); | |
|
25
|
|
|
// | print_r($au->Info('file.flac'); | |
|
26
|
|
|
// +----------------------------------------------------------------------+ |
|
27
|
|
|
// | Authors: Allan Hansen <ahØartemis*dk> | |
|
28
|
|
|
// +----------------------------------------------------------------------+ |
|
29
|
|
|
// |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* getID3() settings |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
require_once('../getid3/getid3.php'); |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Class for extracting information from audio files with getID3(). |
|
44
|
|
|
*/ |
|
45
|
|
|
|
|
46
|
|
|
class AudioInfo { |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Private variables |
|
50
|
|
|
*/ |
|
51
|
|
|
var $result = NULL; |
|
52
|
|
|
var $info = NULL; |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Constructor |
|
59
|
|
|
*/ |
|
60
|
|
|
|
|
61
|
|
|
function __construct() { |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
// Initialize getID3 engine |
|
64
|
|
|
$this->getID3 = new getID3; |
|
|
|
|
|
|
65
|
|
|
$this->getID3->option_md5_data = true; |
|
66
|
|
|
$this->getID3->option_md5_data_source = true; |
|
67
|
|
|
$this->getID3->encoding = 'UTF-8'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Extract information - only public function |
|
75
|
|
|
* |
|
76
|
|
|
* @access public |
|
77
|
|
|
* @param string file Audio file to extract info from. |
|
78
|
|
|
*/ |
|
79
|
|
|
|
|
80
|
|
|
function Info($file) { |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
// Analyze file |
|
83
|
|
|
$this->info = $this->getID3->analyze($file); |
|
84
|
|
|
|
|
85
|
|
|
// Exit here on error |
|
86
|
|
|
if (isset($this->info['error'])) { |
|
87
|
|
|
return array ('error' => $this->info['error']); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
// Init wrapper object |
|
91
|
|
|
$this->result = array(); |
|
92
|
|
|
$this->result['format_name'] = (isset($this->info['fileformat']) ? $this->info['fileformat'] : '').'/'.(isset($this->info['audio']['dataformat']) ? $this->info['audio']['dataformat'] : '').(isset($this->info['video']['dataformat']) ? '/'.$this->info['video']['dataformat'] : ''); |
|
93
|
|
|
$this->result['encoder_version'] = (isset($this->info['audio']['encoder']) ? $this->info['audio']['encoder'] : ''); |
|
94
|
|
|
$this->result['encoder_options'] = (isset($this->info['audio']['encoder_options']) ? $this->info['audio']['encoder_options'] : ''); |
|
95
|
|
|
$this->result['bitrate_mode'] = (isset($this->info['audio']['bitrate_mode']) ? $this->info['audio']['bitrate_mode'] : ''); |
|
96
|
|
|
$this->result['channels'] = (isset($this->info['audio']['channels']) ? $this->info['audio']['channels'] : ''); |
|
97
|
|
|
$this->result['sample_rate'] = (isset($this->info['audio']['sample_rate']) ? $this->info['audio']['sample_rate'] : ''); |
|
98
|
|
|
$this->result['bits_per_sample'] = (isset($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : ''); |
|
99
|
|
|
$this->result['playing_time'] = (isset($this->info['playtime_seconds']) ? $this->info['playtime_seconds'] : ''); |
|
100
|
|
|
$this->result['avg_bit_rate'] = (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : ''); |
|
101
|
|
|
$this->result['tags'] = (isset($this->info['tags']) ? $this->info['tags'] : ''); |
|
102
|
|
|
$this->result['comments'] = (isset($this->info['comments']) ? $this->info['comments'] : ''); |
|
103
|
|
|
$this->result['warning'] = (isset($this->info['warning']) ? $this->info['warning'] : ''); |
|
104
|
|
|
$this->result['md5'] = (isset($this->info['md5_data']) ? $this->info['md5_data'] : ''); |
|
105
|
|
|
|
|
106
|
|
|
// Post getID3() data handling based on file format |
|
107
|
|
|
$method = (isset($this->info['fileformat']) ? $this->info['fileformat'] : '').'Info'; |
|
108
|
|
|
if ($method && method_exists($this, $method)) { |
|
109
|
|
|
$this->$method(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $this->result; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* post-getID3() data handling for AAC files. |
|
120
|
|
|
* |
|
121
|
|
|
* @access private |
|
122
|
|
|
*/ |
|
123
|
|
|
|
|
124
|
|
|
function aacInfo() { |
|
|
|
|
|
|
125
|
|
|
$this->result['format_name'] = 'AAC'; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* post-getID3() data handling for Wave files. |
|
133
|
|
|
* |
|
134
|
|
|
* @access private |
|
135
|
|
|
*/ |
|
136
|
|
|
|
|
137
|
|
|
function riffInfo() { |
|
|
|
|
|
|
138
|
|
|
if ($this->info['audio']['dataformat'] == 'wav') { |
|
139
|
|
|
|
|
140
|
|
|
$this->result['format_name'] = 'Wave'; |
|
141
|
|
|
|
|
142
|
|
|
} elseif (preg_match('#^mp[1-3]$#', $this->info['audio']['dataformat'])) { |
|
143
|
|
|
|
|
144
|
|
|
$this->result['format_name'] = strtoupper($this->info['audio']['dataformat']); |
|
145
|
|
|
|
|
146
|
|
|
} else { |
|
147
|
|
|
|
|
148
|
|
|
$this->result['format_name'] = 'riff/'.$this->info['audio']['dataformat']; |
|
149
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* * post-getID3() data handling for FLAC files. |
|
158
|
|
|
* |
|
159
|
|
|
* @access private |
|
160
|
|
|
*/ |
|
161
|
|
|
|
|
162
|
|
|
function flacInfo() { |
|
|
|
|
|
|
163
|
|
|
$this->result['format_name'] = 'FLAC'; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* post-getID3() data handling for Monkey's Audio files. |
|
172
|
|
|
* |
|
173
|
|
|
* @access private |
|
174
|
|
|
*/ |
|
175
|
|
|
|
|
176
|
|
|
function macInfo() { |
|
|
|
|
|
|
177
|
|
|
$this->result['format_name'] = 'Monkey\'s Audio'; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* post-getID3() data handling for Lossless Audio files. |
|
186
|
|
|
* |
|
187
|
|
|
* @access private |
|
188
|
|
|
*/ |
|
189
|
|
|
|
|
190
|
|
|
function laInfo() { |
|
|
|
|
|
|
191
|
|
|
$this->result['format_name'] = 'La'; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* post-getID3() data handling for Ogg Vorbis files. |
|
200
|
|
|
* |
|
201
|
|
|
* @access private |
|
202
|
|
|
*/ |
|
203
|
|
|
|
|
204
|
|
|
function oggInfo() { |
|
|
|
|
|
|
205
|
|
|
if ($this->info['audio']['dataformat'] == 'vorbis') { |
|
206
|
|
|
|
|
207
|
|
|
$this->result['format_name'] = 'Ogg Vorbis'; |
|
208
|
|
|
|
|
209
|
|
|
} else if ($this->info['audio']['dataformat'] == 'flac') { |
|
210
|
|
|
|
|
211
|
|
|
$this->result['format_name'] = 'Ogg FLAC'; |
|
212
|
|
|
|
|
213
|
|
|
} else if ($this->info['audio']['dataformat'] == 'speex') { |
|
214
|
|
|
|
|
215
|
|
|
$this->result['format_name'] = 'Ogg Speex'; |
|
216
|
|
|
|
|
217
|
|
|
} else { |
|
218
|
|
|
|
|
219
|
|
|
$this->result['format_name'] = 'Ogg '.$this->info['audio']['dataformat']; |
|
220
|
|
|
|
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* post-getID3() data handling for Musepack files. |
|
229
|
|
|
* |
|
230
|
|
|
* @access private |
|
231
|
|
|
*/ |
|
232
|
|
|
|
|
233
|
|
|
function mpcInfo() { |
|
|
|
|
|
|
234
|
|
|
$this->result['format_name'] = 'Musepack'; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* post-getID3() data handling for MPEG files. |
|
242
|
|
|
* |
|
243
|
|
|
* @access private |
|
244
|
|
|
*/ |
|
245
|
|
|
|
|
246
|
|
|
function mp3Info() { |
|
|
|
|
|
|
247
|
|
|
$this->result['format_name'] = 'MP3'; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* post-getID3() data handling for MPEG files. |
|
255
|
|
|
* |
|
256
|
|
|
* @access private |
|
257
|
|
|
*/ |
|
258
|
|
|
|
|
259
|
|
|
function mp2Info() { |
|
|
|
|
|
|
260
|
|
|
$this->result['format_name'] = 'MP2'; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* post-getID3() data handling for MPEG files. |
|
269
|
|
|
* |
|
270
|
|
|
* @access private |
|
271
|
|
|
*/ |
|
272
|
|
|
|
|
273
|
|
|
function mp1Info() { |
|
|
|
|
|
|
274
|
|
|
$this->result['format_name'] = 'MP1'; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
|
|
278
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* post-getID3() data handling for WMA files. |
|
282
|
|
|
* |
|
283
|
|
|
* @access private |
|
284
|
|
|
*/ |
|
285
|
|
|
|
|
286
|
|
|
function asfInfo() { |
|
|
|
|
|
|
287
|
|
|
$this->result['format_name'] = strtoupper($this->info['audio']['dataformat']); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
|
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* post-getID3() data handling for Real files. |
|
294
|
|
|
* |
|
295
|
|
|
* @access private |
|
296
|
|
|
*/ |
|
297
|
|
|
|
|
298
|
|
|
function realInfo() { |
|
|
|
|
|
|
299
|
|
|
$this->result['format_name'] = 'Real'; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
|
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* post-getID3() data handling for VQF files. |
|
308
|
|
|
* |
|
309
|
|
|
* @access private |
|
310
|
|
|
*/ |
|
311
|
|
|
|
|
312
|
|
|
function vqfInfo() { |
|
|
|
|
|
|
313
|
|
|
$this->result['format_name'] = 'VQF'; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
} |
|
317
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.