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