Conditions | 46 |
Paths | 4405 |
Total Lines | 359 |
Code Lines | 239 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
27 | public function Analyze() |
||
28 | { |
||
29 | $getid3 = $this->getid3; |
||
30 | |||
31 | $getid3->include_module('audio-video.riff'); |
||
32 | |||
33 | $getid3->info['fileformat'] = 'real'; |
||
34 | $getid3->info['bitrate'] = 0; |
||
35 | $getid3->info['playtime_seconds'] = 0; |
||
36 | |||
37 | fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); |
||
38 | $chunk_counter = 0; |
||
39 | |||
40 | while (ftell($getid3->fp) < $getid3->info['avdataend']) { |
||
41 | $chunk_data = fread($getid3->fp, 8); |
||
42 | $chunk_name = substr($chunk_data, 0, 4); |
||
43 | $chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4)); |
||
44 | |||
45 | if ($chunk_name == '.ra' . "\xFD") { |
||
46 | $chunk_data .= fread($getid3->fp, $chunk_size - 8); |
||
47 | |||
48 | if ($this->ParseOldRAheader(substr($chunk_data, 0, 128), $getid3->info['real']['old_ra_header'])) { |
||
49 | $getid3->info['audio']['dataformat'] = 'real'; |
||
50 | $getid3->info['audio']['lossless'] = false; |
||
51 | $getid3->info['audio']['sample_rate'] = $getid3->info['real']['old_ra_header']['sample_rate']; |
||
52 | $getid3->info['audio']['bits_per_sample'] = $getid3->info['real']['old_ra_header']['bits_per_sample']; |
||
53 | $getid3->info['audio']['channels'] = $getid3->info['real']['old_ra_header']['channels']; |
||
54 | |||
55 | $getid3->info['playtime_seconds'] = 60 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['real']['old_ra_header']['bytes_per_minute']); |
||
56 | $getid3->info['audio']['bitrate'] = 8 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['playtime_seconds']); |
||
57 | $getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($getid3->info['real']['old_ra_header']['fourcc'], $getid3->info['audio']['bitrate']); |
||
58 | |||
59 | foreach ($getid3->info['real']['old_ra_header']['comments'] as $key => $value_array) { |
||
60 | if (strlen(trim($value_array[0])) > 0) { |
||
61 | $getid3->info['real']['comments'][$key][] = trim($value_array[0]); |
||
62 | } |
||
63 | } |
||
64 | return true; |
||
65 | } |
||
66 | |||
67 | throw new getid3_exception('There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or [email protected]'); |
||
68 | } |
||
69 | |||
70 | $getid3->info['real']['chunks'][$chunk_counter] = []; |
||
71 | $info_real_chunks_current_chunk = &$getid3->info['real']['chunks'][$chunk_counter]; |
||
72 | |||
73 | $info_real_chunks_current_chunk['name'] = $chunk_name; |
||
74 | $info_real_chunks_current_chunk['offset'] = ftell($getid3->fp) - 8; |
||
75 | $info_real_chunks_current_chunk['length'] = $chunk_size; |
||
76 | |||
77 | if (($info_real_chunks_current_chunk['offset'] + $info_real_chunks_current_chunk['length']) > $getid3->info['avdataend']) { |
||
78 | $getid3->warning('Chunk "' . $info_real_chunks_current_chunk['name'] . '" at offset ' . $info_real_chunks_current_chunk['offset'] . ' claims to be ' . $info_real_chunks_current_chunk['length'] . ' bytes long, which is beyond end of file'); |
||
79 | return false; |
||
80 | } |
||
81 | |||
82 | if ($chunk_size > (getid3::FREAD_BUFFER_SIZE + 8)) { |
||
83 | $chunk_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE - 8); |
||
84 | fseek($getid3->fp, $info_real_chunks_current_chunk['offset'] + $chunk_size, SEEK_SET); |
||
85 | } elseif (($chunk_size - 8) > 0) { |
||
86 | $chunk_data .= fread($getid3->fp, $chunk_size - 8); |
||
87 | } |
||
88 | $offset = 8; |
||
89 | |||
90 | switch ($chunk_name) { |
||
91 | case '.RMF': // RealMedia File Header |
||
92 | |||
93 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
94 | $offset += 2; |
||
95 | |||
96 | switch ($info_real_chunks_current_chunk['object_version']) { |
||
97 | case 0: |
||
98 | $info_real_chunks_current_chunk['file_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
||
99 | $offset += 4; |
||
100 | |||
101 | $info_real_chunks_current_chunk['headers_count'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
||
102 | $offset += 4; |
||
103 | break; |
||
104 | |||
105 | default: |
||
106 | //$getid3->warning('Expected .RMF-object_version to be "0", actual value is "'.$info_real_chunks_current_chunk['object_version'].'" (should not be a problem)'; |
||
107 | break; |
||
108 | } |
||
109 | break; |
||
110 | |||
111 | case 'PROP': // Properties Header |
||
112 | |||
113 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
114 | $offset += 2; |
||
115 | |||
116 | if (0 == $info_real_chunks_current_chunk['object_version']) { |
||
117 | getid3_lib::ReadSequence( |
||
118 | 'BigEndian2Int', |
||
119 | $info_real_chunks_current_chunk, |
||
120 | $chunk_data, |
||
121 | $offset, |
||
122 | [ |
||
123 | 'max_bit_rate' => 4, |
||
124 | 'avg_bit_rate' => 4, |
||
125 | 'max_packet_size' => 4, |
||
126 | 'avg_packet_size' => 4, |
||
127 | 'num_packets' => 4, |
||
128 | 'duration' => 4, |
||
129 | 'preroll' => 4, |
||
130 | 'index_offset' => 4, |
||
131 | 'data_offset' => 4, |
||
132 | 'num_streams' => 2, |
||
133 | 'flags_raw' => 2 |
||
134 | ] |
||
135 | ); |
||
136 | $offset += 40; |
||
137 | |||
138 | $getid3->info['playtime_seconds'] = $info_real_chunks_current_chunk['duration'] / 1000; |
||
139 | if ($info_real_chunks_current_chunk['duration'] > 0) { |
||
140 | $getid3->info['bitrate'] += $info_real_chunks_current_chunk['avg_bit_rate']; |
||
141 | } |
||
142 | |||
143 | $info_real_chunks_current_chunk['flags']['save_enabled'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0001); |
||
144 | $info_real_chunks_current_chunk['flags']['perfect_play'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0002); |
||
145 | $info_real_chunks_current_chunk['flags']['live_broadcast'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0004); |
||
146 | } |
||
147 | break; |
||
148 | |||
149 | case 'MDPR': // Media Properties Header |
||
150 | |||
151 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
152 | $offset += 2; |
||
153 | |||
154 | if (0 == $info_real_chunks_current_chunk['object_version']) { |
||
155 | getid3_lib::ReadSequence( |
||
156 | 'BigEndian2Int', |
||
157 | $info_real_chunks_current_chunk, |
||
158 | $chunk_data, |
||
159 | $offset, |
||
160 | [ |
||
161 | 'stream_number' => 2, |
||
162 | 'max_bit_rate' => 4, |
||
163 | 'avg_bit_rate' => 4, |
||
164 | 'max_packet_size' => 4, |
||
165 | 'avg_packet_size' => 4, |
||
166 | 'start_time' => 4, |
||
167 | 'preroll' => 4, |
||
168 | 'duration' => 4, |
||
169 | 'stream_name_size' => 1 |
||
170 | ] |
||
171 | ); |
||
172 | $offset += 31; |
||
173 | |||
174 | $info_real_chunks_current_chunk['stream_name'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['stream_name_size']); |
||
175 | $offset += $info_real_chunks_current_chunk['stream_name_size']; |
||
176 | |||
177 | $info_real_chunks_current_chunk['mime_type_size'] = getid3_lib::BigEndian2Int($chunk_data{$offset++}); |
||
178 | |||
179 | $info_real_chunks_current_chunk['mime_type'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['mime_type_size']); |
||
180 | $offset += $info_real_chunks_current_chunk['mime_type_size']; |
||
181 | |||
182 | $info_real_chunks_current_chunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
||
183 | $offset += 4; |
||
184 | |||
185 | $info_real_chunks_current_chunk['type_specific_data'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['type_specific_len']); |
||
186 | $offset += $info_real_chunks_current_chunk['type_specific_len']; |
||
187 | |||
188 | $info_real_chunks_current_chunk_typespecificdata = &$info_real_chunks_current_chunk['type_specific_data']; |
||
189 | |||
190 | switch ($info_real_chunks_current_chunk['mime_type']) { |
||
191 | case 'video/x-pn-realvideo': |
||
192 | case 'video/x-pn-multirate-realvideo': |
||
193 | // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html |
||
194 | |||
195 | $info_real_chunks_current_chunk['video_info'] = []; |
||
196 | $info_real_chunks_current_chunk_video_info = &$info_real_chunks_current_chunk['video_info']; |
||
197 | |||
198 | getid3_lib::ReadSequence( |
||
199 | 'BigEndian2Int', |
||
200 | $info_real_chunks_current_chunk_video_info, |
||
201 | $info_real_chunks_current_chunk_typespecificdata, |
||
202 | 0, |
||
203 | [ |
||
204 | 'dwSize' => 4, |
||
205 | 'fourcc1' => -4, |
||
206 | 'fourcc2' => -4, |
||
207 | 'width' => 2, |
||
208 | 'height' => 2, |
||
209 | 'bits_per_sample' => 2, |
||
210 | 'IGNORE-unknown1' => 2, |
||
211 | 'IGNORE-unknown2' => 2, |
||
212 | 'frames_per_second' => 2, |
||
213 | 'IGNORE-unknown3' => 2, |
||
214 | 'IGNORE-unknown4' => 2, |
||
215 | 'IGNORE-unknown5' => 2, |
||
216 | 'IGNORE-unknown6' => 2, |
||
217 | 'IGNORE-unknown7' => 2, |
||
218 | 'IGNORE-unknown8' => 2, |
||
219 | 'IGNORE-unknown9' => 2 |
||
220 | ] |
||
221 | ); |
||
222 | |||
223 | $info_real_chunks_current_chunk_video_info['codec'] = getid3_riff::RIFFfourccLookup($info_real_chunks_current_chunk_video_info['fourcc2']); |
||
224 | |||
225 | $getid3->info['video']['resolution_x'] = $info_real_chunks_current_chunk_video_info['width']; |
||
226 | $getid3->info['video']['resolution_y'] = $info_real_chunks_current_chunk_video_info['height']; |
||
227 | $getid3->info['video']['frame_rate'] = (float)$info_real_chunks_current_chunk_video_info['frames_per_second']; |
||
228 | $getid3->info['video']['codec'] = $info_real_chunks_current_chunk_video_info['codec']; |
||
229 | $getid3->info['video']['bits_per_sample'] = $info_real_chunks_current_chunk_video_info['bits_per_sample']; |
||
230 | break; |
||
231 | |||
232 | case 'audio/x-pn-realaudio': |
||
233 | case 'audio/x-pn-multirate-realaudio': |
||
234 | |||
235 | $this->ParseOldRAheader($info_real_chunks_current_chunk_typespecificdata, $info_real_chunks_current_chunk['parsed_audio_data']); |
||
236 | |||
237 | $getid3->info['audio']['sample_rate'] = $info_real_chunks_current_chunk['parsed_audio_data']['sample_rate']; |
||
238 | $getid3->info['audio']['bits_per_sample'] = $info_real_chunks_current_chunk['parsed_audio_data']['bits_per_sample']; |
||
239 | $getid3->info['audio']['channels'] = $info_real_chunks_current_chunk['parsed_audio_data']['channels']; |
||
240 | |||
241 | if (!empty($getid3->info['audio']['dataformat'])) { |
||
242 | foreach ($getid3->info['audio'] as $key => $value) { |
||
243 | if ('streams' != $key) { |
||
244 | $getid3->info['audio']['streams'][$info_real_chunks_current_chunk['stream_number']][$key] = $value; |
||
245 | } |
||
246 | } |
||
247 | } |
||
248 | break; |
||
249 | |||
250 | case 'logical-fileinfo': |
||
251 | |||
252 | $info_real_chunks_current_chunk['logical_fileinfo']['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 0, 4)); |
||
253 | // $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown1'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 4, 4)); |
||
254 | $info_real_chunks_current_chunk['logical_fileinfo']['num_tags'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 8, 4)); |
||
255 | // $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown2'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 12, 4)); |
||
256 | break; |
||
257 | } |
||
258 | |||
259 | if (empty($getid3->info['playtime_seconds'])) { |
||
260 | $getid3->info['playtime_seconds'] = max($getid3->info['playtime_seconds'], ($info_real_chunks_current_chunk['duration'] + $info_real_chunks_current_chunk['start_time']) / 1000); |
||
261 | } |
||
262 | |||
263 | if ($info_real_chunks_current_chunk['duration'] > 0) { |
||
264 | switch ($info_real_chunks_current_chunk['mime_type']) { |
||
265 | case 'audio/x-pn-realaudio': |
||
266 | case 'audio/x-pn-multirate-realaudio': |
||
267 | |||
268 | $getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
||
269 | $getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info_real_chunks_current_chunk['parsed_audio_data']['fourcc'], $getid3->info['audio']['bitrate']); |
||
270 | $getid3->info['audio']['dataformat'] = 'real'; |
||
271 | $getid3->info['audio']['lossless'] = false; |
||
272 | break; |
||
273 | |||
274 | case 'video/x-pn-realvideo': |
||
275 | case 'video/x-pn-multirate-realvideo': |
||
276 | |||
277 | $getid3->info['video']['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
||
278 | $getid3->info['video']['bitrate_mode'] = 'cbr'; |
||
279 | $getid3->info['video']['dataformat'] = 'real'; |
||
280 | $getid3->info['video']['lossless'] = false; |
||
281 | $getid3->info['video']['pixel_aspect_ratio'] = (float)1; |
||
282 | break; |
||
283 | |||
284 | case 'audio/x-ralf-mpeg4-generic': |
||
285 | |||
286 | $getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
||
287 | $getid3->info['audio']['codec'] = 'RealAudio Lossless'; |
||
288 | $getid3->info['audio']['dataformat'] = 'real'; |
||
289 | $getid3->info['audio']['lossless'] = true; |
||
290 | break; |
||
291 | } |
||
292 | |||
293 | $getid3->info['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0); |
||
294 | } |
||
295 | } |
||
296 | break; |
||
297 | |||
298 | case 'CONT': // Content Description Header (text comments) |
||
299 | |||
300 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
301 | $offset += 2; |
||
302 | |||
303 | if (0 == $info_real_chunks_current_chunk['object_version']) { |
||
304 | $info_real_chunks_current_chunk['title_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
305 | $offset += 2; |
||
306 | |||
307 | $info_real_chunks_current_chunk['title'] = (string)substr($chunk_data, $offset, $info_real_chunks_current_chunk['title_len']); |
||
308 | $offset += $info_real_chunks_current_chunk['title_len']; |
||
309 | |||
310 | $info_real_chunks_current_chunk['artist_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
311 | $offset += 2; |
||
312 | |||
313 | $info_real_chunks_current_chunk['artist'] = (string)substr($chunk_data, $offset, $info_real_chunks_current_chunk['artist_len']); |
||
314 | $offset += $info_real_chunks_current_chunk['artist_len']; |
||
315 | |||
316 | $info_real_chunks_current_chunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
317 | $offset += 2; |
||
318 | |||
319 | $info_real_chunks_current_chunk['copyright'] = (string)substr($chunk_data, $offset, $info_real_chunks_current_chunk['copyright_len']); |
||
320 | $offset += $info_real_chunks_current_chunk['copyright_len']; |
||
321 | |||
322 | $info_real_chunks_current_chunk['comment_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
323 | $offset += 2; |
||
324 | |||
325 | $info_real_chunks_current_chunk['comment'] = (string)substr($chunk_data, $offset, $info_real_chunks_current_chunk['comment_len']); |
||
326 | $offset += $info_real_chunks_current_chunk['comment_len']; |
||
327 | |||
328 | foreach (['title' => 'title', 'artist' => 'artist', 'copyright' => 'copyright', 'comment' => 'comment'] as $key => $val) { |
||
329 | if ($info_real_chunks_current_chunk[$key]) { |
||
330 | $getid3->info['real']['comments'][$val][] = trim($info_real_chunks_current_chunk[$key]); |
||
331 | } |
||
332 | } |
||
333 | } |
||
334 | break; |
||
335 | |||
336 | case 'DATA': // Data Chunk Header |
||
337 | |||
338 | // do nothing |
||
339 | break; |
||
340 | |||
341 | case 'INDX': // Index Section Header |
||
342 | |||
343 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
344 | $offset += 2; |
||
345 | |||
346 | if (0 == $info_real_chunks_current_chunk['object_version']) { |
||
347 | getid3_lib::ReadSequence( |
||
348 | 'BigEndian2Int', |
||
349 | $info_real_chunks_current_chunk, |
||
350 | $chunk_data, |
||
351 | $offset, |
||
352 | [ |
||
353 | 'num_indices' => 4, |
||
354 | 'stream_number' => 2, |
||
355 | 'next_index_header' => 4 |
||
356 | ] |
||
357 | ); |
||
358 | $offset += 10; |
||
359 | |||
360 | if (0 == $info_real_chunks_current_chunk['next_index_header']) { |
||
361 | // last index chunk found, ignore rest of file |
||
362 | break 2; |
||
363 | } else { |
||
364 | // non-last index chunk, seek to next index chunk (skipping actual index data) |
||
365 | fseek($getid3->fp, $info_real_chunks_current_chunk['next_index_header'], SEEK_SET); |
||
366 | } |
||
367 | } |
||
368 | break; |
||
369 | |||
370 | default: |
||
371 | $getid3->warning('Unhandled RealMedia chunk "' . $chunk_name . '" at offset ' . $info_real_chunks_current_chunk['offset']); |
||
372 | break; |
||
373 | } |
||
374 | $chunk_counter++; |
||
375 | } |
||
376 | |||
377 | if (!empty($getid3->info['audio']['streams'])) { |
||
378 | $getid3->info['audio']['bitrate'] = 0; |
||
379 | |||
380 | foreach ($getid3->info['audio']['streams'] as $key => $value_array) { |
||
381 | $getid3->info['audio']['bitrate'] += $value_array['bitrate']; |
||
382 | } |
||
383 | } |
||
384 | |||
385 | return true; |
||
386 | } |
||
579 |