00001 <?php
00004
00005
00007
00008
00009
00011
00012
00013 define('GETID3_VERSION', '1.7.7');
00014 define('GETID3_FREAD_BUFFER_SIZE', 16384);
00015
00016
00017
00018 class getID3
00019 {
00020
00021 var $encoding = 'ISO-8859-1';
00022
00023
00024 var $encoding_id3v1 = 'ISO-8859-1';
00025
00026 var $tempdir = '*';
00027
00028
00029 var $option_tag_id3v1 = true;
00030 var $option_tag_id3v2 = true;
00031 var $option_tag_lyrics3 = true;
00032 var $option_tag_apetag = true;
00033 var $option_tags_process = true;
00034 var $option_tags_html = true;
00035
00036
00037 var $option_extra_info = true;
00038
00039
00040 var $option_md5_data = false;
00041 var $option_md5_data_source = false;
00042 var $option_sha1_data = false;
00043 var $option_max_2gb_check = true;
00044
00045
00046 var $filename;
00047
00048
00049
00050 function getID3()
00051 {
00052
00053 $this->startup_error = '';
00054 $this->startup_warning = '';
00055
00056
00057 if (phpversion() < '4.1.0') {
00058 $this->startup_error .= 'getID3() requires PHP v4.1.0 or higher - you are running v'.phpversion();
00059 }
00060
00061
00062 $memory_limit = ini_get('memory_limit');
00063 if (eregi('([0-9]+)M', $memory_limit, $matches)) {
00064
00065 $memory_limit = $matches[1] * 1048576;
00066 }
00067 if ($memory_limit <= 0) {
00068
00069 } elseif ($memory_limit <= 3145728) {
00070 $this->startup_error .= 'PHP has less than 3MB available memory and will very likely run out. Increase memory_limit in php.ini';
00071 } elseif ($memory_limit <= 12582912) {
00072 $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini';
00073 }
00074
00075
00076 if ((bool) ini_get('safe_mode')) {
00077 $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
00078 }
00079
00080
00081
00082 if (!defined('GETID3_OS_ISWINDOWS')) {
00083 if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
00084 define('GETID3_OS_ISWINDOWS', true);
00085 } else {
00086 define('GETID3_OS_ISWINDOWS', false);
00087 }
00088 }
00089
00090
00091 if (!defined('GETID3_INCLUDEPATH')) {
00092 foreach (get_included_files() as $key => $val) {
00093 if (basename($val) == 'getid3.php') {
00094 define('GETID3_INCLUDEPATH', dirname($val).DIRECTORY_SEPARATOR);
00095 break;
00096 }
00097 }
00098 }
00099
00100
00101 if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
00102 $this->startup_error .= 'getid3.lib.php is missing or corrupt';
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112 if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
00113 $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps';
00114
00115 if (!is_dir($helperappsdir)) {
00116
00117 $this->startup_error .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist';
00118
00119 } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
00120
00121 $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
00122 $DirPieces8 = $DirPieces;
00123
00124 $CLIdir = $DirPieces[0].' && cd \\';
00125 for ($i = 1; $i < count($DirPieces); $i++) {
00126 if (strpos($DirPieces[$i], ' ') === false) {
00127 $CLIdir .= ' && cd '.$DirPieces[$i];
00128 } else {
00129 ob_start();
00130 system($CLIdir.' && dir /ad /x');
00131 $subdirsraw = explode("\n", ob_get_contents());
00132 ob_end_clean();
00133 foreach ($subdirsraw as $dummy => $line) {
00134 if (eregi('^[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2} [AP]M <DIR> ([^ ]{8}) '.preg_quote($DirPieces[$i]).'$', trim($line), $matches)) {
00135 $CLIdir .= ' && cd '.$matches[1];
00136 break;
00137 }
00138 }
00139 $DirPieces8[$i] = $matches[1];
00140 }
00141 }
00142 $helperappsdir = implode(DIRECTORY_SEPARATOR, $DirPieces8);
00143
00144 }
00145 define('GETID3_HELPERAPPSDIR', realpath($helperappsdir).DIRECTORY_SEPARATOR);
00146
00147 }
00148
00149 }
00150
00151
00152
00153 function setOption($optArray) {
00154 if (!is_array($optArray) || empty($optArray)) {
00155 return false;
00156 }
00157 foreach ($optArray as $opt => $val) {
00158 if (isset($this, $opt) === false) {
00159 continue;
00160 }
00161 $this->$opt = $val;
00162 }
00163 return true;
00164 }
00165
00166
00167
00168 function analyze($filename) {
00169
00170 if (!empty($this->startup_error)) {
00171 return $this->error($this->startup_error);
00172 }
00173 if (!empty($this->startup_warning)) {
00174 $this->warning($this->startup_warning);
00175 }
00176
00177
00178 $this->info = array();
00179 $this->info['GETID3_VERSION'] = GETID3_VERSION;
00180
00181
00182 if (!function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
00183 $errormessage = 'iconv() support is needed for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
00184 if (GETID3_OS_ISWINDOWS) {
00185 $errormessage .= 'PHP does not have iconv() support. Please enable php_iconv.dll in php.ini, and copy iconv.dll from c:/php/dlls to c:/windows/system32';
00186 } else {
00187 $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch';
00188 }
00189 return $this->error($errormessage);
00190 }
00191
00192
00193 $old_magic_quotes_runtime = get_magic_quotes_runtime();
00194 if ($old_magic_quotes_runtime) {
00195 set_magic_quotes_runtime(0);
00196 if (get_magic_quotes_runtime()) {
00197 return $this->error('Could not disable magic_quotes_runtime - getID3() cannot work properly with this setting enabled');
00198 }
00199 }
00200
00201
00202 if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
00203 return $this->error('Remote files are not supported in this version of getID3() - please copy the file locally first');
00204 }
00205
00206
00207 if (!$fp = @fopen($filename, 'rb')) {
00208 return $this->error('Could not open file "'.$filename.'"');
00209 }
00210
00211
00212 $this->info['filesize'] = filesize($filename);
00213
00214
00215 if ($this->option_max_2gb_check) {
00216
00217
00218
00219 fseek($fp, 0, SEEK_END);
00220 if ((($this->info['filesize'] != 0) && (ftell($fp) == 0)) ||
00221 ($this->info['filesize'] < 0) ||
00222 (ftell($fp) < 0)) {
00223 unset($this->info['filesize']);
00224 fclose($fp);
00225 return $this->error('File is most likely larger than 2GB and is not supported by PHP');
00226 }
00227 }
00228
00229
00230 $this->info['avdataoffset'] = 0;
00231 $this->info['avdataend'] = $this->info['filesize'];
00232 $this->info['fileformat'] = '';
00233 $this->info['audio']['dataformat'] = '';
00234 $this->info['video']['dataformat'] = '';
00235 $this->info['tags'] = array();
00236 $this->info['error'] = array();
00237 $this->info['warning'] = array();
00238 $this->info['comments'] = array();
00239 $this->info['encoding'] = $this->encoding;
00240
00241
00242 $this->info['filename'] = basename($filename);
00243 $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
00244 $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
00245
00246
00247
00248
00249 if ($this->option_tag_id3v2) {
00250
00251 $GETID3_ERRORARRAY = &$this->info['warning'];
00252 if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, false)) {
00253 $tag = new getid3_id3v2($fp, $this->info);
00254 }
00255
00256 } else {
00257
00258 fseek($fp, 0, SEEK_SET);
00259 $header = fread($fp, 10);
00260 if (substr($header, 0, 3) == 'ID3') {
00261 $this->info['id3v2']['header'] = true;
00262 $this->info['id3v2']['majorversion'] = ord($header{3});
00263 $this->info['id3v2']['minorversion'] = ord($header{4});
00264 $this->info['id3v2']['headerlength'] = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10;
00265
00266 $this->info['id3v2']['tag_offset_start'] = 0;
00267 $this->info['id3v2']['tag_offset_end'] = $this->info['id3v2']['tag_offset_start'] + $this->info['id3v2']['headerlength'];
00268 $this->info['avdataoffset'] = $this->info['id3v2']['tag_offset_end'];
00269 }
00270
00271 }
00272
00273
00274
00275 if ($this->option_tag_id3v1) {
00276 if (!@include_once(GETID3_INCLUDEPATH.'module.tag.id3v1.php')) {
00277 return $this->error('module.tag.id3v1.php is missing - you may disable option_tag_id3v1.');
00278 }
00279 $tag = new getid3_id3v1($fp, $this->info);
00280 }
00281
00282
00283 if ($this->option_tag_apetag) {
00284 if (!@include_once(GETID3_INCLUDEPATH.'module.tag.apetag.php')) {
00285 return $this->error('module.tag.apetag.php is missing - you may disable option_tag_apetag.');
00286 }
00287 $tag = new getid3_apetag($fp, $this->info);
00288 }
00289
00290
00291 if ($this->option_tag_lyrics3) {
00292 if (!@include_once(GETID3_INCLUDEPATH.'module.tag.lyrics3.php')) {
00293 return $this->error('module.tag.lyrics3.php is missing - you may disable option_tag_lyrics3.');
00294 }
00295 $tag = new getid3_lyrics3($fp, $this->info);
00296 }
00297
00298
00299 fseek($fp, $this->info['avdataoffset'], SEEK_SET);
00300 $formattest = fread($fp, 32774);
00301
00302
00303 $determined_format = $this->GetFileFormat($formattest, $filename);
00304
00305
00306 if (!$determined_format) {
00307 fclose($fp);
00308 return $this->error('unable to determine file format');
00309 }
00310
00311
00312 if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) {
00313 if ($determined_format['fail_id3'] === 'ERROR') {
00314 fclose($fp);
00315 return $this->error('ID3 tags not allowed on this file type.');
00316 } elseif ($determined_format['fail_id3'] === 'WARNING') {
00317 $this->info['warning'][] = 'ID3 tags not allowed on this file type.';
00318 }
00319 }
00320
00321
00322 if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) {
00323 if ($determined_format['fail_ape'] === 'ERROR') {
00324 fclose($fp);
00325 return $this->error('APE tags not allowed on this file type.');
00326 } elseif ($determined_format['fail_ape'] === 'WARNING') {
00327 $this->info['warning'][] = 'APE tags not allowed on this file type.';
00328 }
00329 }
00330
00331
00332 $this->info['mime_type'] = $determined_format['mime_type'];
00333
00334
00335 if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) {
00336 fclose($fp);
00337 return $this->error('Format not supported, module, '.$determined_format['include'].', was removed.');
00338 }
00339
00340
00341 if (!function_exists('iconv') && @$determined_format['iconv_req']) {
00342 return $this->error('iconv support is required for this module ('.$determined_format['include'].').');
00343 }
00344
00345
00346 include_once(GETID3_INCLUDEPATH.$determined_format['include']);
00347
00348
00349 $class_name = 'getid3_'.$determined_format['module'];
00350 if (!class_exists($class_name)) {
00351 return $this->error('Format not supported, module, '.$determined_format['include'].', is corrupt.');
00352 }
00353 if (isset($determined_format['option'])) {
00354 $class = new $class_name($fp, $this->info, $determined_format['option']);
00355 } else {
00356 $class = new $class_name($fp, $this->info);
00357 }
00358
00359
00360 fclose($fp);
00361
00362
00363 if ($this->option_tags_process) {
00364 $this->HandleAllTags();
00365 }
00366
00367
00368 if ($this->option_extra_info) {
00369 $this->ChannelsBitratePlaytimeCalculations();
00370 $this->CalculateCompressionRatioVideo();
00371 $this->CalculateCompressionRatioAudio();
00372 $this->CalculateReplayGain();
00373 $this->ProcessAudioStreams();
00374 }
00375
00376
00377 if ($this->option_md5_data) {
00378
00379 if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) {
00380 $this->getHashdata('md5');
00381 }
00382 }
00383
00384
00385 if ($this->option_sha1_data) {
00386 $this->getHashdata('sha1');
00387 }
00388
00389
00390 $this->CleanUp();
00391
00392
00393 set_magic_quotes_runtime($old_magic_quotes_runtime);
00394
00395
00396 return $this->info;
00397 }
00398
00399
00400
00401 function error($message) {
00402
00403 $this->CleanUp();
00404
00405 $this->info['error'][] = $message;
00406 return $this->info;
00407 }
00408
00409
00410
00411 function warning($message) {
00412 $this->info['warning'][] = $message;
00413 return true;
00414 }
00415
00416
00417
00418 function CleanUp() {
00419
00420
00421 $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams');
00422 foreach ($AVpossibleEmptyKeys as $dummy => $key) {
00423 if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) {
00424 unset($this->info['audio'][$key]);
00425 }
00426 if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) {
00427 unset($this->info['video'][$key]);
00428 }
00429 }
00430
00431
00432 if (!empty($this->info)) {
00433 foreach ($this->info as $key => $value) {
00434 if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) {
00435 unset($this->info[$key]);
00436 }
00437 }
00438 }
00439
00440
00441 if (empty($this->info['fileformat'])) {
00442 if (isset($this->info['avdataoffset'])) {
00443 unset($this->info['avdataoffset']);
00444 }
00445 if (isset($this->info['avdataend'])) {
00446 unset($this->info['avdataend']);
00447 }
00448 }
00449 }
00450
00451
00452
00453 function GetFileFormatArray() {
00454 static $format_info = array();
00455 if (empty($format_info)) {
00456 $format_info = array(
00457
00458
00459
00460
00461 'ac3' => array(
00462 'pattern' => '^\x0B\x77',
00463 'group' => 'audio',
00464 'module' => 'ac3',
00465 'mime_type' => 'audio/ac3',
00466 ),
00467
00468
00469 'adif' => array(
00470 'pattern' => '^ADIF',
00471 'group' => 'audio',
00472 'module' => 'aac',
00473 'option' => 'adif',
00474 'mime_type' => 'application/octet-stream',
00475 'fail_ape' => 'WARNING',
00476 ),
00477
00478
00479
00480 'adts' => array(
00481 'pattern' => '^\xFF[\xF0-\xF1\xF8-\xF9]',
00482 'group' => 'audio',
00483 'module' => 'aac',
00484 'option' => 'adts',
00485 'mime_type' => 'application/octet-stream',
00486 'fail_ape' => 'WARNING',
00487 ),
00488
00489
00490
00491 'au' => array(
00492 'pattern' => '^\.snd',
00493 'group' => 'audio',
00494 'module' => 'au',
00495 'mime_type' => 'audio/basic',
00496 ),
00497
00498
00499 'avr' => array(
00500 'pattern' => '^2BIT',
00501 'group' => 'audio',
00502 'module' => 'avr',
00503 'mime_type' => 'application/octet-stream',
00504 ),
00505
00506
00507 'bonk' => array(
00508 'pattern' => '^\x00(BONK|INFO|META| ID3)',
00509 'group' => 'audio',
00510 'module' => 'bonk',
00511 'mime_type' => 'audio/xmms-bonk',
00512 ),
00513
00514
00515 'flac' => array(
00516 'pattern' => '^fLaC',
00517 'group' => 'audio',
00518 'module' => 'flac',
00519 'mime_type' => 'audio/x-flac',
00520 ),
00521
00522
00523 'la' => array(
00524 'pattern' => '^LA0[2-4]',
00525 'group' => 'audio',
00526 'module' => 'la',
00527 'mime_type' => 'application/octet-stream',
00528 ),
00529
00530
00531 'lpac' => array(
00532 'pattern' => '^LPAC',
00533 'group' => 'audio',
00534 'module' => 'lpac',
00535 'mime_type' => 'application/octet-stream',
00536 ),
00537
00538
00539 'midi' => array(
00540 'pattern' => '^MThd',
00541 'group' => 'audio',
00542 'module' => 'midi',
00543 'mime_type' => 'audio/midi',
00544 ),
00545
00546
00547 'mac' => array(
00548 'pattern' => '^MAC ',
00549 'group' => 'audio',
00550 'module' => 'monkey',
00551 'mime_type' => 'application/octet-stream',
00552 ),
00553
00554
00555 'mod' => array(
00556 'pattern' => '^.{1080}(M.K.|[5-9]CHN|[1-3][0-9]CH)',
00557 'group' => 'audio',
00558 'module' => 'mod',
00559 'option' => 'mod',
00560 'mime_type' => 'audio/mod',
00561 ),
00562
00563
00564 'it' => array(
00565 'pattern' => '^IMPM',
00566 'group' => 'audio',
00567 'module' => 'mod',
00568 'option' => 'it',
00569 'mime_type' => 'audio/it',
00570 ),
00571
00572
00573 'xm' => array(
00574 'pattern' => '^Extended Module',
00575 'group' => 'audio',
00576 'module' => 'mod',
00577 'option' => 'xm',
00578 'mime_type' => 'audio/xm',
00579 ),
00580
00581
00582 's3m' => array(
00583 'pattern' => '^.{44}SCRM',
00584 'group' => 'audio',
00585 'module' => 'mod',
00586 'option' => 's3m',
00587 'mime_type' => 'audio/s3m',
00588 ),
00589
00590
00591 'mpc' => array(
00592 'pattern' => '^(MP\+|[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0])',
00593 'group' => 'audio',
00594 'module' => 'mpc',
00595 'mime_type' => 'application/octet-stream',
00596 ),
00597
00598
00599 'mp3' => array(
00600 'pattern' => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]',
00601 'group' => 'audio',
00602 'module' => 'mp3',
00603 'mime_type' => 'audio/mpeg',
00604 ),
00605
00606
00607 'ofr' => array(
00608 'pattern' => '^(\*RIFF|OFR)',
00609 'group' => 'audio',
00610 'module' => 'optimfrog',
00611 'mime_type' => 'application/octet-stream',
00612 ),
00613
00614
00615 'rkau' => array(
00616 'pattern' => '^RKA',
00617 'group' => 'audio',
00618 'module' => 'rkau',
00619 'mime_type' => 'application/octet-stream',
00620 ),
00621
00622
00623 'shn' => array(
00624 'pattern' => '^ajkg',
00625 'group' => 'audio',
00626 'module' => 'shorten',
00627 'mime_type' => 'audio/xmms-shn',
00628 'fail_id3' => 'ERROR',
00629 'fail_ape' => 'ERROR',
00630 ),
00631
00632
00633 'tta' => array(
00634 'pattern' => '^TTA',
00635 'group' => 'audio',
00636 'module' => 'tta',
00637 'mime_type' => 'application/octet-stream',
00638 ),
00639
00640
00641 'voc' => array(
00642 'pattern' => '^Creative Voice File',
00643 'group' => 'audio',
00644 'module' => 'voc',
00645 'mime_type' => 'audio/voc',
00646 ),
00647
00648
00649 'vqf' => array(
00650 'pattern' => '^TWIN',
00651 'group' => 'audio',
00652 'module' => 'vqf',
00653 'mime_type' => 'application/octet-stream',
00654 ),
00655
00656
00657 'wv' => array(
00658 'pattern' => '^wvpk',
00659 'group' => 'audio',
00660 'module' => 'wavpack',
00661 'mime_type' => 'application/octet-stream',
00662 ),
00663
00664
00665
00666
00667
00668 'asf' => array(
00669 'pattern' => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C',
00670 'group' => 'audio-video',
00671 'module' => 'asf',
00672 'mime_type' => 'video/x-ms-asf',
00673 'iconv_req' => false,
00674 ),
00675
00676
00677 'bink' => array(
00678 'pattern' => '^(BIK|SMK)',
00679 'group' => 'audio-video',
00680 'module' => 'bink',
00681 'mime_type' => 'application/octet-stream',
00682 ),
00683
00684
00685 'flv' => array(
00686 'pattern' => '^FLV\x01',
00687 'group' => 'audio-video',
00688 'module' => 'flv',
00689 'mime_type' => 'video/x-flv',
00690 ),
00691
00692
00693 'matroska' => array(
00694 'pattern' => '^\x1A\x45\xDF\xA3',
00695 'group' => 'audio-video',
00696 'module' => 'matroska',
00697 'mime_type' => 'application/octet-stream',
00698 ),
00699
00700
00701 'mpeg' => array(
00702 'pattern' => '^\x00\x00\x01(\xBA|\xB3)',
00703 'group' => 'audio-video',
00704 'module' => 'mpeg',
00705 'mime_type' => 'video/mpeg',
00706 ),
00707
00708
00709 'nsv' => array(
00710 'pattern' => '^NSV[sf]',
00711 'group' => 'audio-video',
00712 'module' => 'nsv',
00713 'mime_type' => 'application/octet-stream',
00714 ),
00715
00716
00717 'ogg' => array(
00718 'pattern' => '^OggS',
00719 'group' => 'audio',
00720 'module' => 'ogg',
00721 'mime_type' => 'application/ogg',
00722 'fail_id3' => 'WARNING',
00723 'fail_ape' => 'WARNING',
00724 ),
00725
00726
00727 'quicktime' => array(
00728 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
00729 'group' => 'audio-video',
00730 'module' => 'quicktime',
00731 'mime_type' => 'video/quicktime',
00732 ),
00733
00734
00735 'riff' => array(
00736 'pattern' => '^(RIFF|SDSS|FORM)',
00737 'group' => 'audio-video',
00738 'module' => 'riff',
00739 'mime_type' => 'audio/x-wave',
00740 'fail_ape' => 'WARNING',
00741 ),
00742
00743
00744 'real' => array(
00745 'pattern' => '^(\.RMF|.ra)',
00746 'group' => 'audio-video',
00747 'module' => 'real',
00748 'mime_type' => 'audio/x-realaudio',
00749 ),
00750
00751
00752 'swf' => array(
00753 'pattern' => '^(F|C)WS',
00754 'group' => 'audio-video',
00755 'module' => 'swf',
00756 'mime_type' => 'application/x-shockwave-flash',
00757 ),
00758
00759
00760
00761
00762
00763 'bmp' => array(
00764 'pattern' => '^BM',
00765 'group' => 'graphic',
00766 'module' => 'bmp',
00767 'mime_type' => 'image/bmp',
00768 'fail_id3' => 'ERROR',
00769 'fail_ape' => 'ERROR',
00770 ),
00771
00772
00773 'gif' => array(
00774 'pattern' => '^GIF',
00775 'group' => 'graphic',
00776 'module' => 'gif',
00777 'mime_type' => 'image/gif',
00778 'fail_id3' => 'ERROR',
00779 'fail_ape' => 'ERROR',
00780 ),
00781
00782
00783 'jpg' => array(
00784 'pattern' => '^\xFF\xD8\xFF',
00785 'group' => 'graphic',
00786 'module' => 'jpg',
00787 'mime_type' => 'image/jpeg',
00788 'fail_id3' => 'ERROR',
00789 'fail_ape' => 'ERROR',
00790 ),
00791
00792
00793 'pcd' => array(
00794 'pattern' => '^.{2048}PCD_IPI\x00',
00795 'group' => 'graphic',
00796 'module' => 'pcd',
00797 'mime_type' => 'image/x-photo-cd',
00798 'fail_id3' => 'ERROR',
00799 'fail_ape' => 'ERROR',
00800 ),
00801
00802
00803
00804 'png' => array(
00805 'pattern' => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A',
00806 'group' => 'graphic',
00807 'module' => 'png',
00808 'mime_type' => 'image/png',
00809 'fail_id3' => 'ERROR',
00810 'fail_ape' => 'ERROR',
00811 ),
00812
00813
00814
00815 'tiff' => array(
00816 'pattern' => '^(II\x2A\x00|MM\x00\x2A)',
00817 'group' => 'graphic',
00818 'module' => 'tiff',
00819 'mime_type' => 'image/tiff',
00820 'fail_id3' => 'ERROR',
00821 'fail_ape' => 'ERROR',
00822 ),
00823
00824
00825
00826
00827
00828 'iso' => array(
00829 'pattern' => '^.{32769}CD001',
00830 'group' => 'misc',
00831 'module' => 'iso',
00832 'mime_type' => 'application/octet-stream',
00833 'fail_id3' => 'ERROR',
00834 'fail_ape' => 'ERROR',
00835 'iconv_req' => false,
00836 ),
00837
00838
00839 'rar' => array(
00840 'pattern' => '^Rar\!',
00841 'group' => 'archive',
00842 'module' => 'rar',
00843 'mime_type' => 'application/octet-stream',
00844 'fail_id3' => 'ERROR',
00845 'fail_ape' => 'ERROR',
00846 ),
00847
00848
00849 'szip' => array(
00850 'pattern' => '^SZ\x0A\x04',
00851 'group' => 'archive',
00852 'module' => 'szip',
00853 'mime_type' => 'application/octet-stream',
00854 'fail_id3' => 'ERROR',
00855 'fail_ape' => 'ERROR',
00856 ),
00857
00858
00859 'tar' => array(
00860 'pattern' => '^.{100}[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20\x00]{12}[0-9\x20\x00]{12}',
00861 'group' => 'archive',
00862 'module' => 'tar',
00863 'mime_type' => 'application/x-tar',
00864 'fail_id3' => 'ERROR',
00865 'fail_ape' => 'ERROR',
00866 ),
00867
00868
00869 'gz' => array(
00870 'pattern' => '^\x1F\x8B\x08',
00871 'group' => 'archive',
00872 'module' => 'gzip',
00873 'mime_type' => 'application/x-gzip',
00874 'fail_id3' => 'ERROR',
00875 'fail_ape' => 'ERROR',
00876 ),
00877
00878
00879 'zip' => array(
00880 'pattern' => '^PK\x03\x04',
00881 'group' => 'archive',
00882 'module' => 'zip',
00883 'mime_type' => 'application/zip',
00884 'fail_id3' => 'ERROR',
00885 'fail_ape' => 'ERROR',
00886 ),
00887
00888
00889
00890
00891
00892 'pdf' => array(
00893 'pattern' => '^\x25PDF',
00894 'group' => 'misc',
00895 'module' => 'pdf',
00896 'mime_type' => 'application/pdf',
00897 'fail_id3' => 'ERROR',
00898 'fail_ape' => 'ERROR',
00899 ),
00900
00901
00902 'msoffice' => array(
00903 'pattern' => '^\xD0\xCF\x11\xE0',
00904 'group' => 'misc',
00905 'module' => 'msoffice',
00906 'mime_type' => 'application/octet-stream',
00907 'fail_id3' => 'ERROR',
00908 'fail_ape' => 'ERROR',
00909 ),
00910 );
00911 }
00912
00913 return $format_info;
00914 }
00915
00916
00917
00918 function GetFileFormat(&$filedata, $filename='') {
00919
00920
00921
00922
00923
00924
00925 foreach ($this->GetFileFormatArray() as $format_name => $info) {
00926
00927
00928
00929 if (preg_match('/'.$info['pattern'].'/s', $filedata)) {
00930 $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
00931 return $info;
00932 }
00933 }
00934
00935
00936 if (preg_match('/\.mp[123a]$/i', $filename)) {
00937
00938
00939 $GetFileFormatArray = $this->GetFileFormatArray();
00940 $info = $GetFileFormatArray['mp3'];
00941 $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
00942 return $info;
00943 }
00944
00945 return false;
00946 }
00947
00948
00949
00950 function CharConvert(&$array, $encoding) {
00951
00952
00953 if ($encoding == $this->encoding) {
00954 return;
00955 }
00956
00957
00958 foreach ($array as $key => $value) {
00959
00960
00961 if (is_array($value)) {
00962 $this->CharConvert($array[$key], $encoding);
00963 }
00964
00965
00966 elseif (is_string($value)) {
00967 $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value));
00968 }
00969 }
00970 }
00971
00972
00973 function HandleAllTags() {
00974
00975
00976 static $tags;
00977 if (empty($tags)) {
00978 $tags = array(
00979 'asf' => array('asf' , 'UTF-16LE'),
00980 'midi' => array('midi' , 'ISO-8859-1'),
00981 'nsv' => array('nsv' , 'ISO-8859-1'),
00982 'ogg' => array('vorbiscomment' , 'UTF-8'),
00983 'png' => array('png' , 'UTF-8'),
00984 'tiff' => array('tiff' , 'ISO-8859-1'),
00985 'quicktime' => array('quicktime' , 'ISO-8859-1'),
00986 'real' => array('real' , 'ISO-8859-1'),
00987 'vqf' => array('vqf' , 'ISO-8859-1'),
00988 'zip' => array('zip' , 'ISO-8859-1'),
00989 'riff' => array('riff' , 'ISO-8859-1'),
00990 'lyrics3' => array('lyrics3' , 'ISO-8859-1'),
00991 'id3v1' => array('id3v1' , $this->encoding_id3v1),
00992 'id3v2' => array('id3v2' , 'UTF-8'),
00993 'ape' => array('ape' , 'UTF-8')
00994 );
00995 }
00996
00997
00998 foreach ($tags as $comment_name => $tagname_encoding_array) {
00999 list($tag_name, $encoding) = $tagname_encoding_array;
01000
01001
01002 if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
01003 $this->info[$comment_name]['encoding'] = $encoding;
01004 }
01005
01006
01007 if (!empty($this->info[$comment_name]['comments'])) {
01008
01009 foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
01010 foreach ($valuearray as $key => $value) {
01011 if (strlen(trim($value)) > 0) {
01012 $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
01013 }
01014 }
01015 }
01016
01017 if (!isset($this->info['tags'][$tag_name])) {
01018
01019 continue;
01020 }
01021
01022 if ($this->option_tags_html) {
01023 foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
01024 foreach ($valuearray as $key => $value) {
01025 if (is_string($value)) {
01026
01027 $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('�', '', getid3_lib::MultiByteCharString2HTML($value, $encoding));
01028 } else {
01029 $this->info['tags_html'][$tag_name][$tag_key][$key] = $value;
01030 }
01031 }
01032 }
01033 }
01034
01035 $this->CharConvert($this->info['tags'][$tag_name], $encoding);
01036 }
01037
01038 }
01039 return true;
01040 }
01041
01042
01043 function getHashdata($algorithm) {
01044 switch ($algorithm) {
01045 case 'md5':
01046 case 'sha1':
01047 break;
01048
01049 default:
01050 return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
01051 break;
01052 }
01053
01054 if ((@$this->info['fileformat'] == 'ogg') && (@$this->info['audio']['dataformat'] == 'vorbis')) {
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074 if ((bool) ini_get('safe_mode')) {
01075
01076 $this->info['warning'][] = 'Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)';
01077 $this->info[$algorithm.'_data'] = false;
01078
01079 } else {
01080
01081
01082 $old_abort = ignore_user_abort(true);
01083
01084
01085 $empty = tempnam('*', 'getID3');
01086 touch($empty);
01087
01088
01089
01090 $temp = tempnam('*', 'getID3');
01091 $file = $this->info['filenamepath'];
01092
01093 if (GETID3_OS_ISWINDOWS) {
01094
01095 if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
01096
01097 $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
01098 $VorbisCommentError = `$commandline`;
01099
01100 } else {
01101
01102 $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR;
01103
01104 }
01105
01106 } else {
01107
01108 $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1';
01109 $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
01110 $VorbisCommentError = `$commandline`;
01111
01112 }
01113
01114 if (!empty($VorbisCommentError)) {
01115
01116 $this->info['warning'][] = 'Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError;
01117 $this->info[$algorithm.'_data'] = false;
01118
01119 } else {
01120
01121
01122 switch ($algorithm) {
01123 case 'md5':
01124 $this->info[$algorithm.'_data'] = getid3_lib::md5_file($temp);
01125 break;
01126
01127 case 'sha1':
01128 $this->info[$algorithm.'_data'] = getid3_lib::sha1_file($temp);
01129 break;
01130 }
01131 }
01132
01133
01134 unlink($empty);
01135 unlink($temp);
01136
01137
01138 ignore_user_abort($old_abort);
01139
01140 }
01141
01142 } else {
01143
01144 if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
01145
01146
01147 $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
01148
01149 } else {
01150
01151
01152 switch ($algorithm) {
01153 case 'md5':
01154 $this->info[$algorithm.'_data'] = getid3_lib::md5_file($this->info['filenamepath']);
01155 break;
01156
01157 case 'sha1':
01158 $this->info[$algorithm.'_data'] = getid3_lib::sha1_file($this->info['filenamepath']);
01159 break;
01160 }
01161 }
01162
01163 }
01164 return true;
01165 }
01166
01167
01168 function ChannelsBitratePlaytimeCalculations() {
01169
01170
01171 if (@$this->info['audio']['channels'] == '1') {
01172 $this->info['audio']['channelmode'] = 'mono';
01173 } elseif (@$this->info['audio']['channels'] == '2') {
01174 $this->info['audio']['channelmode'] = 'stereo';
01175 }
01176
01177
01178 $CombinedBitrate = 0;
01179 $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0);
01180 $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
01181 if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) {
01182 $this->info['bitrate'] = $CombinedBitrate;
01183 }
01184
01185
01186
01187
01188
01189
01190 if (!isset($this->info['playtime_seconds']) && !empty($this->info['bitrate'])) {
01191 $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate'];
01192 }
01193
01194
01195 if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) {
01196 $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']);
01197 }
01198 }
01199
01200
01201 function CalculateCompressionRatioVideo() {
01202 if (empty($this->info['video'])) {
01203 return false;
01204 }
01205 if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) {
01206 return false;
01207 }
01208 if (empty($this->info['video']['bits_per_sample'])) {
01209 return false;
01210 }
01211
01212 switch ($this->info['video']['dataformat']) {
01213 case 'bmp':
01214 case 'gif':
01215 case 'jpeg':
01216 case 'jpg':
01217 case 'png':
01218 case 'tiff':
01219 $FrameRate = 1;
01220 $PlaytimeSeconds = 1;
01221 $BitrateCompressed = $this->info['filesize'] * 8;
01222 break;
01223
01224 default:
01225 if (!empty($this->info['video']['frame_rate'])) {
01226 $FrameRate = $this->info['video']['frame_rate'];
01227 } else {
01228 return false;
01229 }
01230 if (!empty($this->info['playtime_seconds'])) {
01231 $PlaytimeSeconds = $this->info['playtime_seconds'];
01232 } else {
01233 return false;
01234 }
01235 if (!empty($this->info['video']['bitrate'])) {
01236 $BitrateCompressed = $this->info['video']['bitrate'];
01237 } else {
01238 return false;
01239 }
01240 break;
01241 }
01242 $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate;
01243
01244 $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed;
01245 return true;
01246 }
01247
01248
01249 function CalculateCompressionRatioAudio() {
01250 if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate'])) {
01251 return false;
01252 }
01253 $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16));
01254
01255 if (!empty($this->info['audio']['streams'])) {
01256 foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {
01257 if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) {
01258 $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16));
01259 }
01260 }
01261 }
01262 return true;
01263 }
01264
01265
01266 function CalculateReplayGain() {
01267 if (isset($this->info['replay_gain'])) {
01268 $this->info['replay_gain']['reference_volume'] = 89;
01269 if (isset($this->info['replay_gain']['track']['adjustment'])) {
01270 $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
01271 }
01272 if (isset($this->info['replay_gain']['album']['adjustment'])) {
01273 $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
01274 }
01275
01276 if (isset($this->info['replay_gain']['track']['peak'])) {
01277 $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
01278 }
01279 if (isset($this->info['replay_gain']['album']['peak'])) {
01280 $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
01281 }
01282 }
01283 return true;
01284 }
01285
01286 function ProcessAudioStreams() {
01287 if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
01288 if (!isset($this->info['audio']['streams'])) {
01289 foreach ($this->info['audio'] as $key => $value) {
01290 if ($key != 'streams') {
01291 $this->info['audio']['streams'][0][$key] = $value;
01292 }
01293 }
01294 }
01295 }
01296 return true;
01297 }
01298
01299 function getid3_tempnam() {
01300 return tempnam($this->tempdir, 'gI3');
01301 }
01302
01303 }
01304
01305 ?>