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 |
10 // | Example wrapper class to extract information from audio files |
11 // | through getID3(). |
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 |
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 // +----------------------------------------------------------------------+
24 // | $au = new AudioInfo(); |
25 // | print_r($au->Info('file.flac'); |
26 // +----------------------------------------------------------------------+
27 // | Authors: Allan Hansen <ahØartemis*dk> |
28 // +----------------------------------------------------------------------+
37 require_once('../getid3/getid3.php');
43 * Class for extracting information from audio files with getID3().
61 function AudioInfo() {
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';
74 * Extract information - only public function
77 * @param string file Audio file to extract info from.
80 function Info($file) {
83 $this->info = $this->getID3->analyze($file);
86 if (isset($this->info['error'])) {
87 return array ('error' => $this->info['error']);
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'] : '');
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)) {
112 return $this->result;
119 * post-getID3() data handling for AAC files.
125 $this->result['format_name'] = 'AAC';
132 * post-getID3() data handling for Wave files.
137 function riffInfo() {
138 if ($this->info['audio']['dataformat'] == 'wav') {
140 $this->result['format_name'] = 'Wave';
142 } elseif (preg_match('#^mp[1-3]$#', $this->info['audio']['dataformat'])) {
144 $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']);
148 $this->result['format_name'] = 'riff/'.$this->info['audio']['dataformat'];
157 * * post-getID3() data handling for FLAC files.
162 function flacInfo() {
163 $this->result['format_name'] = 'FLAC';
171 * post-getID3() data handling for Monkey's Audio files.
177 $this->result['format_name'] = 'Monkey\'s Audio';
185 * post-getID3() data handling for Lossless Audio files.
191 $this->result['format_name'] = 'La';
199 * post-getID3() data handling for Ogg Vorbis files.
205 if ($this->info['audio']['dataformat'] == 'vorbis') {
207 $this->result['format_name'] = 'Ogg Vorbis';
209 } else if ($this->info['audio']['dataformat'] == 'flac') {
211 $this->result['format_name'] = 'Ogg FLAC';
213 } else if ($this->info['audio']['dataformat'] == 'speex') {
215 $this->result['format_name'] = 'Ogg Speex';
219 $this->result['format_name'] = 'Ogg '.$this->info['audio']['dataformat'];
228 * post-getID3() data handling for Musepack files.
234 $this->result['format_name'] = 'Musepack';
241 * post-getID3() data handling for MPEG files.
247 $this->result['format_name'] = 'MP3';
254 * post-getID3() data handling for MPEG files.
260 $this->result['format_name'] = 'MP2';
268 * post-getID3() data handling for MPEG files.
274 $this->result['format_name'] = 'MP1';
281 * post-getID3() data handling for WMA files.
287 $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']);
293 * post-getID3() data handling for Real files.
298 function realInfo() {
299 $this->result['format_name'] = 'Real';
307 * post-getID3() data handling for VQF files.
313 $this->result['format_name'] = 'VQF';