Completed
Push — vendor/getid3 ( f84e24...1ec141 )
by Pauli
03:18
created

AudioInfo   B

Complexity

Total Complexity 39

Size/Duplication

Total Lines 271
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 271
rs 8.2857
c 0
b 0
f 0
wmc 39
lcom 1
cbo 1

15 Methods

Rating   Name   Duplication   Size   Complexity  
F Info() 0 34 20
A aacInfo() 0 3 1
A riffInfo() 0 15 3
A flacInfo() 0 3 1
A macInfo() 0 3 1
A laInfo() 0 3 1
A oggInfo() 0 19 4
A mpcInfo() 0 3 1
A mp3Info() 0 3 1
A mp2Info() 0 3 1
A mp1Info() 0 3 1
A asfInfo() 0 3 1
A realInfo() 0 3 1
A vqfInfo() 0 3 1
A __construct() 0 8 1
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
62
63
		// Initialize getID3 engine
64
		$this->getID3 = new getID3;
0 ignored issues
show
Bug introduced by
The property getID3 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
313
		$this->result['format_name']     = 'VQF';
314
	}
315
316
}
317