[ PHPXref.com ] [ Generated: Sun Jul 20 17:49:56 2008 ] [ FileBrowser-NG 0.3 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/lib/getid3/ -> getid3.php (source)

   1  <?php
   2  /////////////////////////////////////////////////////////////////
   3  /// getID3() by James Heinrich <info@getid3.org>               //
   4  //  available at http://getid3.sourceforge.net                 //
   5  //            or http://www.getid3.org                         //
   6  /////////////////////////////////////////////////////////////////
   7  //                                                             //
   8  // Please see readme.txt for more information                  //
   9  //                                                            ///
  10  /////////////////////////////////////////////////////////////////
  11  
  12  // Defines
  13  define('GETID3_VERSION', '1.7.5-200512251515');
  14  define('GETID3_FREAD_BUFFER_SIZE', 16384); // read buffer size in bytes
  15  
  16  
  17  
  18  class getID3
  19  {
  20      // public: Settings
  21      var $encoding                 = 'ISO-8859-1';     // CASE SENSITIVE! - i.e. (must be supported by iconv())
  22                                                        // Examples:  ISO-8859-1  UTF-8  UTF-16  UTF-16BE
  23  
  24      var $encoding_id3v1           = 'ISO-8859-1';     // Should always be 'ISO-8859-1', but some tags may be written
  25                                                        // in other encodings such as 'EUC-CN'
  26  
  27      // public: Optional tag checks - disable for speed.
  28      var $option_tag_id3v1         = true;             // Read and process ID3v1 tags
  29      var $option_tag_id3v2         = true;             // Read and process ID3v2 tags
  30      var $option_tag_lyrics3       = true;             // Read and process Lyrics3 tags
  31      var $option_tag_apetag        = true;             // Read and process APE tags
  32      var $option_tags_process      = true;             // Copy tags to root key 'tags' and encode to $this->encoding
  33      var $option_tags_html         = true;             // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
  34  
  35      // public: Optional tag/comment calucations
  36      var $option_extra_info        = true;             // Calculate additional info such as bitrate, channelmode etc
  37  
  38      // public: Optional calculations
  39      var $option_md5_data          = false;            // Get MD5 sum of data part - slow
  40      var $option_md5_data_source   = false;            // Use MD5 of source file if availble - only FLAC and OptimFROG
  41      var $option_sha1_data         = false;            // Get SHA1 sum of data part - slow
  42      var $option_max_2gb_check     = true;             // Check whether file is larger than 2 Gb and thus not supported by PHP
  43  
  44      // private
  45      var $filename;
  46  
  47  
  48      // public: constructor
  49  	function getID3()
  50      {
  51  
  52          $this->startup_error   = '';
  53          $this->startup_warning = '';
  54  
  55          // Check for PHP version >= 4.1.0
  56          if (phpversion() < '4.1.0') {
  57              $this->startup_error .= 'getID3() requires PHP v4.1.0 or higher - you are running v'.phpversion();
  58          }
  59  
  60          // Check memory
  61          $memory_limit = ini_get('memory_limit');
  62          if (eregi('([0-9]+)M', $memory_limit, $matches)) {
  63              // could be stored as "16M" rather than 16777216 for example
  64              $memory_limit = $matches[1] * 1048576;
  65          }
  66          if ($memory_limit <= 0) {
  67              // memory limits probably disabled
  68          } elseif ($memory_limit <= 3145728) {
  69              $this->startup_error .= 'PHP has less than 3MB available memory and will very likely run out. Increase memory_limit in php.ini';
  70          } elseif ($memory_limit <= 12582912) {
  71              $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';
  72          }
  73  
  74          // Check safe_mode off
  75          if ((bool) ini_get('safe_mode')) {
  76              $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
  77          }
  78  
  79  
  80          // define a constant rather than looking up every time it is needed
  81          if (!defined('GETID3_OS_ISWINDOWS')) {
  82              if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
  83                  define('GETID3_OS_ISWINDOWS', true);
  84              } else {
  85                  define('GETID3_OS_ISWINDOWS', false);
  86              }
  87          }
  88  
  89          // Get base path of getID3() - ONCE
  90          if (!defined('GETID3_INCLUDEPATH')) {
  91              define('GETID3_OS_DIRSLASH', (GETID3_OS_ISWINDOWS ? '\\' : '/'));
  92  
  93              foreach (get_included_files() as $key => $val) {
  94                  if (basename($val) == 'getid3.php') {
  95                      define('GETID3_INCLUDEPATH', dirname($val).GETID3_OS_DIRSLASH);
  96                      break;
  97                  }
  98              }
  99          }
 100  
 101          // Load support library
 102          if (!include_once (GETID3_INCLUDEPATH.'getid3.lib.php')) {
 103              $this->startup_error .= 'getid3.lib.php is missing or corrupt';
 104          }
 105  
 106  
 107          // Needed for Windows only:
 108          // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
 109          //   as well as other helper functions such as head, tail, md5sum, etc
 110          // IMPORTANT: This path cannot have spaces in it. If neccesary, use the 8dot3 equivalent
 111          //   ie for "C:/Program Files/Apache/" put "C:/PROGRA~1/APACHE/"
 112          // IMPORTANT: This path must include the trailing slash
 113          if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
 114              $helperappsdir = GETID3_INCLUDEPATH.'..'.GETID3_OS_DIRSLASH.'helperapps'; // must not have any space in this path
 115  
 116              if (!is_dir($helperappsdir)) {
 117  
 118                  $this->startup_error .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist';
 119  
 120              } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
 121  
 122                  $DirPieces = explode(GETID3_OS_DIRSLASH, realpath($helperappsdir));
 123                  $DirPieces8 = $DirPieces;
 124                  
 125                  $CLIdir = $DirPieces[0].' && cd \\';
 126                  for ($i = 1; $i < count($DirPieces); $i++) {
 127                    if (strpos($DirPieces[$i], ' ') === false) {
 128                      $CLIdir .= ' && cd '.$DirPieces[$i];
 129                    } else {
 130                      ob_start();
 131                      system($CLIdir.' && dir /ad /x');
 132                      $subdirsraw = explode("\n", ob_get_contents());
 133                      ob_end_clean();
 134                      foreach ($subdirsraw as $line) {
 135                        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)) {
 136                          $CLIdir .= ' && cd '.$matches[1];
 137                          break;
 138                        }
 139                      }
 140                      $DirPieces8[$i] = $matches[1];
 141                    }
 142                  }
 143                  $helperappsdir = implode(GETID3_OS_DIRSLASH, $DirPieces8);
 144  
 145              }
 146              define('GETID3_HELPERAPPSDIR', realpath($helperappsdir).GETID3_OS_DIRSLASH);
 147  
 148          }
 149  
 150      }
 151  
 152  
 153  
 154      // public: analyze file - replaces GetAllFileInfo() and GetTagOnly()
 155  	function analyze($filename) {
 156  
 157          if (!empty($this->startup_error)) {
 158              return $this->error($this->startup_error);
 159          }
 160          if (!empty($this->startup_warning)) {
 161              $this->warning($this->startup_warning);
 162          }
 163  
 164          // init result array and set parameters
 165          $this->info = array();
 166          $this->info['GETID3_VERSION'] = GETID3_VERSION;
 167  
 168          // Check encoding/iconv support
 169          if (!function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
 170              $errormessage = 'iconv() support is needed for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
 171              if (GETID3_OS_ISWINDOWS) {
 172                  $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';
 173              } else {
 174                  $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch';
 175              }
 176              return $this->error($errormessage);
 177          }
 178  
 179          // Disable magic_quotes_runtime, if neccesary
 180          $old_magic_quotes_runtime = get_magic_quotes_runtime(); // store current setting of magic_quotes_runtime
 181          if ($old_magic_quotes_runtime) {
 182              set_magic_quotes_runtime(0);                        // turn off magic_quotes_runtime
 183              if (get_magic_quotes_runtime()) {
 184                  return $this->error('Could not disable magic_quotes_runtime - getID3() cannot work properly with this setting enabled');
 185              }
 186          }
 187  
 188          // remote files not supported
 189          if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
 190              return $this->error('Remote files are not supported in this version of getID3() - please copy the file locally first');
 191          }
 192  
 193          // open local file
 194          if (!$fp = @fopen($filename, 'rb')) {
 195              return $this->error('Could not open file "'.$filename.'"');
 196          }
 197  
 198          // set parameters
 199          $this->info['filesize'] = filesize($filename);
 200  
 201          // option_max_2gb_check
 202          if ($this->option_max_2gb_check) {
 203              // PHP doesn't support integers larger than 31-bit (~2GB)
 204              // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
 205              // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
 206              fseek($fp, 0, SEEK_END);
 207              if ((($this->info['filesize'] != 0) && (ftell($fp) == 0)) ||
 208                  ($this->info['filesize'] < 0) ||
 209                  (ftell($fp) < 0)) {
 210                      unset($this->info['filesize']);
 211                      fclose($fp);
 212                      return $this->error('File is most likely larger than 2GB and is not supported by PHP');
 213              }
 214          }
 215  
 216          // set more parameters
 217          $this->info['avdataoffset']        = 0;
 218          $this->info['avdataend']           = $this->info['filesize'];
 219          $this->info['fileformat']          = '';                // filled in later
 220          $this->info['audio']['dataformat'] = '';                // filled in later, unset if not used
 221          $this->info['video']['dataformat'] = '';                // filled in later, unset if not used
 222          $this->info['tags']                = array();           // filled in later, unset if not used
 223          $this->info['error']               = array();           // filled in later, unset if not used
 224          $this->info['warning']             = array();           // filled in later, unset if not used
 225          $this->info['comments']            = array();           // filled in later, unset if not used
 226          $this->info['encoding']            = $this->encoding;   // required by id3v2 and iso modules - can be unset at the end if desired
 227  
 228          // set redundant parameters - might be needed in some include file
 229          $this->info['filename']            = basename($filename);
 230          $this->info['filepath']            = str_replace('\\', '/', realpath(dirname($filename)));
 231          $this->info['filenamepath']        = $this->info['filepath'].'/'.$this->info['filename'];
 232  
 233  
 234          // handle ID3v2 tag - done first - already at beginning of file
 235          // ID3v2 detection (even if not parsing) is always done otherwise fileformat is much harder to detect
 236          if ($this->option_tag_id3v2) {
 237  
 238              $GETID3_ERRORARRAY = &$this->info['warning'];
 239              if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, false)) {
 240                  $tag = new getid3_id3v2($fp, $this->info);
 241              }
 242  
 243          } else {
 244  
 245              fseek($fp, 0, SEEK_SET);
 246              $header = fread($fp, 10);
 247              if (substr($header, 0, 3) == 'ID3') {
 248                  $this->info['id3v2']['header']           = true;
 249                  $this->info['id3v2']['majorversion']     = ord($header{3});
 250                  $this->info['id3v2']['minorversion']     = ord($header{4});
 251                  $this->info['id3v2']['headerlength']     = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length
 252  
 253                  $this->info['id3v2']['tag_offset_start'] = 0;
 254                  $this->info['id3v2']['tag_offset_end']   = $this->info['id3v2']['tag_offset_start'] + $this->info['id3v2']['headerlength'];
 255                  $this->info['avdataoffset']              = $this->info['id3v2']['tag_offset_end'];
 256              }
 257  
 258          }
 259  
 260  
 261          // handle ID3v1 tag
 262          if ($this->option_tag_id3v1) {
 263              if (!@include_once (GETID3_INCLUDEPATH.'module.tag.id3v1.php')) {
 264                  return $this->error('module.tag.id3v1.php is missing - you may disable option_tag_id3v1.');
 265              }
 266              $tag = new getid3_id3v1($fp, $this->info);
 267          }
 268  
 269          // handle APE tag
 270          if ($this->option_tag_apetag) {
 271              if (!@include_once (GETID3_INCLUDEPATH.'module.tag.apetag.php')) {
 272                  return $this->error('module.tag.apetag.php is missing - you may disable option_tag_apetag.');
 273              }
 274              $tag = new getid3_apetag($fp, $this->info);
 275          }
 276  
 277          // handle lyrics3 tag
 278          if ($this->option_tag_lyrics3) {
 279              if (!@include_once (GETID3_INCLUDEPATH.'module.tag.lyrics3.php')) {
 280                  return $this->error('module.tag.lyrics3.php is missing - you may disable option_tag_lyrics3.');
 281              }
 282              $tag = new getid3_lyrics3($fp, $this->info);
 283          }
 284  
 285          // read 32 kb file data
 286          fseek($fp, $this->info['avdataoffset'], SEEK_SET);
 287          $formattest = fread($fp, 32774);
 288  
 289          // determine format
 290          $determined_format = $this->GetFileFormat($formattest, $filename);
 291  
 292          // unable to determine file format
 293          if (!$determined_format) {
 294              fclose($fp);
 295              return $this->error('unable to determine file format');
 296          }
 297  
 298          // check for illegal ID3 tags
 299          if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) {
 300              if ($determined_format['fail_id3'] === 'ERROR') {
 301                  fclose($fp);
 302                  return $this->error('ID3 tags not allowed on this file type.');
 303              } elseif ($determined_format['fail_id3'] === 'WARNING') {
 304                  $this->info['warning'][] = 'ID3 tags not allowed on this file type.';
 305              }
 306          }
 307  
 308          // check for illegal APE tags
 309          if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) {
 310              if ($determined_format['fail_ape'] === 'ERROR') {
 311                  fclose($fp);
 312                  return $this->error('APE tags not allowed on this file type.');
 313              } elseif ($determined_format['fail_ape'] === 'WARNING') {
 314                  $this->info['warning'][] = 'APE tags not allowed on this file type.';
 315              }
 316          }
 317  
 318          // set mime type
 319          $this->info['mime_type'] = $determined_format['mime_type'];
 320  
 321          // supported format signature pattern detected, but module deleted
 322          if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) {
 323              fclose($fp);
 324              return $this->error('Format not supported, module, '.$determined_format['include'].', was removed.');
 325          }
 326  
 327          // module requires iconv support
 328          if (!function_exists('iconv') && @$determined_format['iconv_req']) {
 329              return $this->error('iconv support is required for this module ('.$determined_format['include'].').');
 330          }
 331  
 332          // include module
 333          include_once(GETID3_INCLUDEPATH.$determined_format['include']);
 334  
 335          // instantiate module class
 336          $class_name = 'getid3_'.$determined_format['module'];
 337          if (!class_exists($class_name)) {
 338              return $this->error('Format not supported, module, '.$determined_format['include'].', is corrupt.');
 339          }
 340          if (isset($determined_format['option'])) {
 341              $class = new $class_name($fp, $this->info, $determined_format['option']);
 342          } else {
 343              $class = new $class_name($fp, $this->info);
 344          }
 345  
 346          // close file
 347          fclose($fp);
 348  
 349          // process all tags - copy to 'tags' and convert charsets
 350          if ($this->option_tags_process) {
 351              $this->HandleAllTags();
 352          }
 353  
 354          // perform more calculations
 355          if ($this->option_extra_info) {
 356              $this->ChannelsBitratePlaytimeCalculations();
 357              $this->CalculateCompressionRatioVideo();
 358              $this->CalculateCompressionRatioAudio();
 359              $this->CalculateReplayGain();
 360              $this->ProcessAudioStreams();
 361          }
 362  
 363          // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
 364          if ($this->option_md5_data) {
 365              // do not cald md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too
 366              if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) {
 367                  $this->getHashdata('md5');
 368              }
 369          }
 370  
 371          // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
 372          if ($this->option_sha1_data) {
 373              $this->getHashdata('sha1');
 374          }
 375  
 376          // remove undesired keys
 377          $this->CleanUp();
 378  
 379          // restore magic_quotes_runtime setting
 380          set_magic_quotes_runtime($old_magic_quotes_runtime);
 381  
 382          // return info array
 383          return $this->info;
 384      }
 385  
 386  
 387      // private: error handling
 388  	function error($message) {
 389  
 390          $this->CleanUp();
 391  
 392          $this->info['error'][] = $message;
 393          return $this->info;
 394      }
 395  
 396  
 397      // private: warning handling
 398  	function warning($message) {
 399          $this->info['warning'][] = $message;
 400          return true;
 401      }
 402  
 403  
 404      // private: CleanUp
 405  	function CleanUp() {
 406  
 407          // remove possible empty keys
 408          $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams');
 409          foreach ($AVpossibleEmptyKeys as $key) {
 410              if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) {
 411                  unset($this->info['audio'][$key]);
 412              }
 413              if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) {
 414                  unset($this->info['video'][$key]);
 415              }
 416          }
 417  
 418          // remove empty root keys
 419          if (!empty($this->info)) {
 420              foreach ($this->info as $key => $value) {
 421                  if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) {
 422                      unset($this->info[$key]);
 423                  }
 424              }
 425          }
 426  
 427          // remove meaningless entries from unknown-format files
 428          if (empty($this->info['fileformat'])) {
 429              if (isset($this->info['avdataoffset'])) {
 430                  unset($this->info['avdataoffset']);
 431              }
 432              if (isset($this->info['avdataend'])) {
 433                  unset($this->info['avdataend']);
 434              }
 435          }
 436      }
 437  
 438  
 439      // return array containing information about all supported formats
 440  	function GetFileFormatArray() {
 441          static $format_info = array();
 442          if (empty($format_info)) {
 443              $format_info = array(
 444  
 445                  // Audio formats
 446  
 447                  // AC-3   - audio      - Dolby AC-3 / Dolby Digital
 448                  'ac3'  => array(
 449                              'pattern'   => '^\x0B\x77',
 450                              'group'     => 'audio',
 451                              'module'    => 'ac3',
 452                              'mime_type' => 'audio/ac3',
 453                          ),
 454  
 455                  // AAC  - audio       - Advanced Audio Coding (AAC) - ADIF format
 456                  'adif' => array(
 457                              'pattern'   => '^ADIF',
 458                              'group'     => 'audio',
 459                              'module'    => 'aac',
 460                              'option'    => 'adif',
 461                              'mime_type' => 'application/octet-stream',
 462                              'fail_ape'  => 'WARNING',
 463                          ),
 464  
 465  
 466                  // AAC  - audio       - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
 467                  'adts' => array(
 468                              'pattern'   => '^\xFF[\xF0-\xF1\xF8-\xF9]',
 469                              'group'     => 'audio',
 470                              'module'    => 'aac',
 471                              'option'    => 'adts',
 472                              'mime_type' => 'application/octet-stream',
 473                              'fail_ape'  => 'WARNING',
 474                          ),
 475  
 476  
 477                  // AU   - audio       - NeXT/Sun AUdio (AU)
 478                  'au'   => array(
 479                              'pattern'   => '^\.snd',
 480                              'group'     => 'audio',
 481                              'module'    => 'au',
 482                              'mime_type' => 'audio/basic',
 483                          ),
 484  
 485                  // AVR  - audio       - Audio Visual Research
 486                  'avr'  => array(
 487                              'pattern'   => '^2BIT',
 488                              'group'     => 'audio',
 489                              'module'    => 'avr',
 490                              'mime_type' => 'application/octet-stream',
 491                          ),
 492  
 493                  // BONK - audio       - Bonk v0.9+
 494                  'bonk' => array(
 495                              'pattern'   => '^\x00(BONK|INFO|META| ID3)',
 496                              'group'     => 'audio',
 497                              'module'    => 'bonk',
 498                              'mime_type' => 'audio/xmms-bonk',
 499                          ),
 500  
 501                  // FLAC - audio       - Free Lossless Audio Codec
 502                  'flac' => array(
 503                              'pattern'   => '^fLaC',
 504                              'group'     => 'audio',
 505                              'module'    => 'flac',
 506                              'mime_type' => 'audio/x-flac',
 507                          ),
 508  
 509                  // LA   - audio       - Lossless Audio (LA)
 510                  'la'   => array(
 511                              'pattern'   => '^LA0[2-4]',
 512                              'group'     => 'audio',
 513                              'module'    => 'la',
 514                              'mime_type' => 'application/octet-stream',
 515                          ),
 516  
 517                  // LPAC - audio       - Lossless Predictive Audio Compression (LPAC)
 518                  'lpac' => array(
 519                              'pattern'   => '^LPAC',
 520                              'group'     => 'audio',
 521                              'module'    => 'lpac',
 522                              'mime_type' => 'application/octet-stream',
 523                          ),
 524  
 525                  // MIDI - audio       - MIDI (Musical Instrument Digital Interface)
 526                  'midi' => array(
 527                              'pattern'   => '^MThd',
 528                              'group'     => 'audio',
 529                              'module'    => 'midi',
 530                              'mime_type' => 'audio/midi',
 531                          ),
 532  
 533                  // MAC  - audio       - Monkey's Audio Compressor
 534                  'mac'  => array(
 535                              'pattern'   => '^MAC ',
 536                              'group'     => 'audio',
 537                              'module'    => 'monkey',
 538                              'mime_type' => 'application/octet-stream',
 539                          ),
 540  
 541                  // MOD  - audio       - MODule (assorted sub-formats)
 542                  'mod'  => array(
 543                              'pattern'   => '^.{1080}(M.K.|[5-9]CHN|[1-3][0-9]CH)',
 544                              'group'     => 'audio',
 545                              'module'    => 'mod',
 546                              'option'    => 'mod',
 547                              'mime_type' => 'audio/mod',
 548                          ),
 549  
 550                  // MOD  - audio       - MODule (Impulse Tracker)
 551                  'it'   => array(
 552                              'pattern'   => '^IMPM',
 553                              'group'     => 'audio',
 554                              'module'    => 'mod',
 555                              'option'    => 'it',
 556                              'mime_type' => 'audio/it',
 557                          ),
 558  
 559                  // MOD  - audio       - MODule (eXtended Module, various sub-formats)
 560                  'xm'   => array(
 561                              'pattern'   => '^Extended Module',
 562                              'group'     => 'audio',
 563                              'module'    => 'mod',
 564                              'option'    => 'xm',
 565                              'mime_type' => 'audio/xm',
 566                          ),
 567  
 568                  // MOD  - audio       - MODule (ScreamTracker)
 569                  's3m'  => array(
 570                              'pattern'   => '^.{44}SCRM',
 571                              'group'     => 'audio',
 572                              'module'    => 'mod',
 573                              'option'    => 's3m',
 574                              'mime_type' => 'audio/s3m',
 575                          ),
 576  
 577                  // MPC  - audio       - Musepack / MPEGplus
 578                  'mpc'  => array(
 579                              '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])',
 580                              'group'     => 'audio',
 581                              'module'    => 'mpc',
 582                              'mime_type' => 'application/octet-stream',
 583                          ),
 584  
 585                  // MP3  - audio       - MPEG-audio Layer 3 (very similar to AAC-ADTS)
 586                  'mp3'  => array(
 587                              'pattern'   => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]',
 588                              'group'     => 'audio',
 589                              'module'    => 'mp3',
 590                              'mime_type' => 'audio/mpeg',
 591                          ),
 592  
 593                  // OFR  - audio       - OptimFROG
 594                  'ofr'  => array(
 595                              'pattern'   => '^(\*RIFF|OFR)',
 596                              'group'     => 'audio',
 597                              'module'    => 'optimfrog',
 598                              'mime_type' => 'application/octet-stream',
 599                          ),
 600  
 601                  // RKAU - audio       - RKive AUdio compressor
 602                  'rkau' => array(
 603                              'pattern'   => '^RKA',
 604                              'group'     => 'audio',
 605                              'module'    => 'rkau',
 606                              'mime_type' => 'application/octet-stream',
 607                          ),
 608  
 609                  // SHN  - audio       - Shorten
 610                  'shn'  => array(
 611                              'pattern'   => '^ajkg',
 612                              'group'     => 'audio',
 613                              'module'    => 'shorten',
 614                              'mime_type' => 'audio/xmms-shn',
 615                              'fail_id3'  => 'ERROR',
 616                              'fail_ape'  => 'ERROR',
 617                          ),
 618  
 619                  // TTA  - audio       - TTA Lossless Audio Compressor (http://tta.corecodec.org)
 620                  'tta'  => array(
 621                              'pattern'   => '^TTA',  // could also be '^TTA(\x01|\x02|\x03|2|1)'
 622                              'group'     => 'audio',
 623                              'module'    => 'tta',
 624                              'mime_type' => 'application/octet-stream',
 625                          ),
 626  
 627                  // VOC  - audio       - Creative Voice (VOC)
 628                  'voc'  => array(
 629                              'pattern'   => '^Creative Voice File',
 630                              'group'     => 'audio',
 631                              'module'    => 'voc',
 632                              'mime_type' => 'audio/voc',
 633                          ),
 634  
 635                  // VQF  - audio       - transform-domain weighted interleave Vector Quantization Format (VQF)
 636                  'vqf'  => array(
 637                              'pattern'   => '^TWIN',
 638                              'group'     => 'audio',
 639                              'module'    => 'vqf',
 640                              'mime_type' => 'application/octet-stream',
 641                          ),
 642  
 643                  // WV  - audio        - WavPack (v4.0+)
 644                  'wv'   => array(
 645                              'pattern'   => '^wvpk',
 646                              'group'     => 'audio',
 647                              'module'    => 'wavpack',
 648                              'mime_type' => 'application/octet-stream',
 649                          ),
 650  
 651  
 652                  // Audio-Video formats
 653  
 654                  // ASF  - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio
 655                  'asf'  => array(
 656                              'pattern'   => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C',
 657                              'group'     => 'audio-video',
 658                              'module'    => 'asf',
 659                              'mime_type' => 'video/x-ms-asf',
 660                              'iconv_req' => false,
 661                          ),
 662  
 663                  // BINK - audio/video - Bink / Smacker
 664                  'bink' => array(
 665                              'pattern'   => '^(BIK|SMK)',
 666                              'group'     => 'audio-video',
 667                              'module'    => 'bink',
 668                              'mime_type' => 'application/octet-stream',
 669                          ),
 670  
 671                  // FLV  - audio/video - FLash Video
 672                  'flv' => array(
 673                              'pattern'   => '^FLV\x01',
 674                              'group'     => 'audio-video',
 675                              'module'    => 'flv',
 676                              'mime_type' => 'video/x-flv',
 677                          ),
 678  
 679                  // MKAV - audio/video - Mastroka
 680                  'matroska' => array(
 681                              'pattern'   => '^\x1A\x45\xDF\xA3',
 682                              'group'     => 'audio-video',
 683                              'module'    => 'matroska',
 684                              'mime_type' => 'application/octet-stream',
 685                          ),
 686  
 687                  // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
 688                  'mpeg' => array(
 689                              'pattern'   => '^\x00\x00\x01(\xBA|\xB3)',
 690                              'group'     => 'audio-video',
 691                              'module'    => 'mpeg',
 692                              'mime_type' => 'video/mpeg',
 693                          ),
 694  
 695                  // NSV  - audio/video - Nullsoft Streaming Video (NSV)
 696                  'nsv'  => array(
 697                              'pattern'   => '^NSV[sf]',
 698                              'group'     => 'audio-video',
 699                              'module'    => 'nsv',
 700                              'mime_type' => 'application/octet-stream',
 701                          ),
 702  
 703                  // Ogg  - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*))
 704                  'ogg'  => array(
 705                              'pattern'   => '^OggS',
 706                              'group'     => 'audio',
 707                              'module'    => 'ogg',
 708                              'mime_type' => 'application/ogg',
 709                              'fail_id3'  => 'WARNING',
 710                              'fail_ape'  => 'WARNING',
 711                          ),
 712  
 713                  // QT   - audio/video - Quicktime
 714                  'quicktime' => array(
 715                              'pattern'   => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
 716                              'group'     => 'audio-video',
 717                              'module'    => 'quicktime',
 718                              'mime_type' => 'video/quicktime',
 719                          ),
 720  
 721                  // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF)
 722                  'riff' => array(
 723                              'pattern'   => '^(RIFF|SDSS|FORM)',
 724                              'group'     => 'audio-video',
 725                              'module'    => 'riff',
 726                              'mime_type' => 'audio/x-wave',
 727                              'fail_ape'  => 'WARNING',
 728                          ),
 729  
 730                  // Real - audio/video - RealAudio, RealVideo
 731                  'real' => array(
 732                              'pattern'   => '^(\.RMF|.ra)',
 733                              'group'     => 'audio-video',
 734                              'module'    => 'real',
 735                              'mime_type' => 'audio/x-realaudio',
 736                          ),
 737  
 738                  // SWF - audio/video - ShockWave Flash
 739                  'swf' => array(
 740                              'pattern'   => '^(F|C)WS',
 741                              'group'     => 'audio-video',
 742                              'module'    => 'swf',
 743                              'mime_type' => 'application/x-shockwave-flash',
 744                          ),
 745  
 746  
 747                  // Still-Image formats
 748  
 749                  // BMP  - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4)
 750                  'bmp'  => array(
 751                              'pattern'   => '^BM',
 752                              'group'     => 'graphic',
 753                              'module'    => 'bmp',
 754                              'mime_type' => 'image/bmp',
 755                              'fail_id3'  => 'ERROR',
 756                              'fail_ape'  => 'ERROR',
 757                          ),
 758  
 759                  // GIF  - still image - Graphics Interchange Format
 760                  'gif'  => array(
 761                              'pattern'   => '^GIF',
 762                              'group'     => 'graphic',
 763                              'module'    => 'gif',
 764                              'mime_type' => 'image/gif',
 765                              'fail_id3'  => 'ERROR',
 766                              'fail_ape'  => 'ERROR',
 767                          ),
 768  
 769                  // JPEG - still image - Joint Photographic Experts Group (JPEG)
 770                  'jpg'  => array(
 771                              'pattern'   => '^\xFF\xD8\xFF',
 772                              'group'     => 'graphic',
 773                              'module'    => 'jpg',
 774                              'mime_type' => 'image/jpeg',
 775                              'fail_id3'  => 'ERROR',
 776                              'fail_ape'  => 'ERROR',
 777                          ),
 778  
 779                  // PCD  - still image - Kodak Photo CD
 780                  'pcd'  => array(
 781                              'pattern'   => '^.{2048}PCD_IPI\x00',
 782                              'group'     => 'graphic',
 783                              'module'    => 'pcd',
 784                              'mime_type' => 'image/x-photo-cd',
 785                              'fail_id3'  => 'ERROR',
 786                              'fail_ape'  => 'ERROR',
 787                          ),
 788  
 789  
 790                  // PNG  - still image - Portable Network Graphics (PNG)
 791                  'png'  => array(
 792                              'pattern'   => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A',
 793                              'group'     => 'graphic',
 794                              'module'    => 'png',
 795                              'mime_type' => 'image/png',
 796                              'fail_id3'  => 'ERROR',
 797                              'fail_ape'  => 'ERROR',
 798                          ),
 799  
 800  
 801                  // TIFF  - still image - Tagged Information File Format (TIFF)
 802                  'tiff' => array(
 803                              'pattern'   => '^(II\x2A\x00|MM\x00\x2A)',
 804                              'group'     => 'graphic',
 805                              'module'    => 'tiff',
 806                              'mime_type' => 'image/tiff',
 807                              'fail_id3'  => 'ERROR',
 808                              'fail_ape'  => 'ERROR',
 809                          ),
 810  
 811  
 812                  // Data formats
 813  
 814                  // ISO  - data        - International Standards Organization (ISO) CD-ROM Image
 815                  'iso'  => array(
 816                              'pattern'   => '^.{32769}CD001',
 817                              'group'     => 'misc',
 818                              'module'    => 'iso',
 819                              'mime_type' => 'application/octet-stream',
 820                              'fail_id3'  => 'ERROR',
 821                              'fail_ape'  => 'ERROR',
 822                              'iconv_req' => false,
 823                          ),
 824  
 825                  // RAR  - data        - RAR compressed data
 826                  'rar'  => array(
 827                              'pattern'   => '^Rar\!',
 828                              'group'     => 'archive',
 829                              'module'    => 'rar',
 830                              'mime_type' => 'application/octet-stream',
 831                              'fail_id3'  => 'ERROR',
 832                              'fail_ape'  => 'ERROR',
 833                          ),
 834  
 835                  // SZIP - audio       - SZIP compressed data
 836                  'szip' => array(
 837                              'pattern'   => '^SZ\x0A\x04',
 838                              'group'     => 'archive',
 839                              'module'    => 'szip',
 840                              'mime_type' => 'application/octet-stream',
 841                              'fail_id3'  => 'ERROR',
 842                              'fail_ape'  => 'ERROR',
 843                          ),
 844  
 845                  // TAR  - data        - TAR compressed data
 846                  'tar'  => array(
 847                              '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}',
 848                              'group'     => 'archive',
 849                              'module'    => 'tar',
 850                              'mime_type' => 'application/x-tar',
 851                              'fail_id3'  => 'ERROR',
 852                              'fail_ape'  => 'ERROR',
 853                          ),
 854  
 855                  // GZIP  - data        - GZIP compressed data
 856                  'gz'  => array(
 857                              'pattern'   => '^\x1F\x8B\x08',
 858                              'group'     => 'archive',
 859                              'module'    => 'gzip',
 860                              'mime_type' => 'application/x-gzip',
 861                              'fail_id3'  => 'ERROR',
 862                              'fail_ape'  => 'ERROR',
 863                          ),
 864  
 865                  // ZIP  - data        - ZIP compressed data
 866                  'zip'  => array(
 867                              'pattern'   => '^PK\x03\x04',
 868                              'group'     => 'archive',
 869                              'module'    => 'zip',
 870                              'mime_type' => 'application/zip',
 871                              'fail_id3'  => 'ERROR',
 872                              'fail_ape'  => 'ERROR',
 873                            )
 874              );
 875          }
 876  
 877          return $format_info;
 878      }
 879  
 880  
 881  
 882  	function GetFileFormat(&$filedata, $filename='') {
 883          // this function will determine the format of a file based on usually
 884          // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,
 885          // and in the case of ISO CD image, 6 bytes offset 32kb from the start
 886          // of the file).
 887  
 888          // Identify file format - loop through $format_info and detect with reg expr
 889          foreach ($this->GetFileFormatArray() as $format_name => $info) {
 890              // Using preg_match() instead of ereg() - much faster
 891              // The /s switch on preg_match() forces preg_match() NOT to treat
 892              // newline (0x0A) characters as special chars but do a binary match
 893              if (preg_match('/'.$info['pattern'].'/s', $filedata)) {
 894                  $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
 895                  return $info;
 896              }
 897          }
 898  
 899  
 900          if (preg_match('/\.mp[123a]$/i', $filename)) {
 901  
 902              // Too many mp3 encoders on the market put gabage in front of mpeg files
 903              // use assume format on these if format detection failed
 904              $GetFileFormatArray = $this->GetFileFormatArray();
 905              $info = $GetFileFormatArray['mp3'];
 906              $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
 907              return $info;
 908  
 909          //} elseif (preg_match('/\.tar$/i', $filename)) {
 910          //
 911          //    // TAR files don't have any useful header to work from
 912          //    // TAR  - data        - TAR compressed data
 913          //    $info = array(
 914          //        'pattern'   => '^.{512}',
 915          //        'group'     => 'archive',
 916          //        'module'    => 'tar',
 917          //        'mime_type' => 'application/octet-stream',
 918          //        'fail_id3'  => 'ERROR',
 919          //        'fail_ape'  => 'ERROR',
 920          //    );
 921          //    $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
 922          //    return $info;
 923  
 924          }
 925  
 926          return false;
 927      }
 928  
 929  
 930      // converts array to $encoding charset from $this->encoding
 931  	function CharConvert(&$array, $encoding) {
 932  
 933          // identical encoding - end here
 934          if ($encoding == $this->encoding) {
 935              return;
 936          }
 937  
 938          // loop thru array
 939          foreach ($array as $key => $value) {
 940  
 941              // go recursive
 942              if (is_array($value)) {
 943                  $this->CharConvert($array[$key], $encoding);
 944              }
 945  
 946              // convert string
 947              elseif (is_string($value)) {
 948                  $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value));
 949              }
 950          }
 951      }
 952  
 953  
 954  	function HandleAllTags() {
 955  
 956          // key name => array (tag name, character encoding)
 957          static $tags;
 958          if (empty($tags)) {
 959              $tags = array(
 960                  'asf'       => array('asf'           , 'UTF-16LE'),
 961                  'midi'      => array('midi'          , 'ISO-8859-1'),
 962                  'nsv'       => array('nsv'           , 'ISO-8859-1'),
 963                  'ogg'       => array('vorbiscomment' , 'UTF-8'),
 964                  'png'       => array('png'           , 'UTF-8'),
 965                  'tiff'      => array('tiff'          , 'ISO-8859-1'),
 966                  'quicktime' => array('quicktime'     , 'ISO-8859-1'),
 967                  'real'      => array('real'          , 'ISO-8859-1'),
 968                  'vqf'       => array('vqf'           , 'ISO-8859-1'),
 969                  'zip'       => array('zip'           , 'ISO-8859-1'),
 970                  'riff'      => array('riff'          , 'ISO-8859-1'),
 971                  'lyrics3'   => array('lyrics3'       , 'ISO-8859-1'),
 972                  'id3v1'     => array('id3v1'         , $this->encoding_id3v1),
 973                  'id3v2'     => array('id3v2'         , 'UTF-8'), // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8
 974                  'ape'       => array('ape'           , 'UTF-8')
 975              );
 976          }
 977  
 978          // loop thru comments array
 979          foreach ($tags as $comment_name => $tagname_encoding_array) {
 980              list($tag_name, $encoding) = $tagname_encoding_array;
 981  
 982              // fill in default encoding type if not already present
 983              if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
 984                  $this->info[$comment_name]['encoding'] = $encoding;
 985              }
 986  
 987              // copy comments if key name set
 988              if (!empty($this->info[$comment_name]['comments'])) {
 989  
 990                  foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
 991                      foreach ($valuearray as $key => $value) {
 992                          if (strlen(trim($value)) > 0) {
 993                              $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value; // do not trim!! Unicode characters will get mangled if trailing nulls are removed!
 994                          }
 995                      }
 996                  }
 997  
 998                  if (!isset($this->info['tags'][$tag_name])) {
 999                      // comments are set but contain nothing but empty strings, so skip
1000                      continue;
1001                  }
1002  
1003                  if ($this->option_tags_html) {
1004                      foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
1005                          foreach ($valuearray as $key => $value) {
1006                              if (is_string($value)) {
1007                                  //$this->info['tags_html'][$tag_name][$tag_key][$key] = getid3_lib::MultiByteCharString2HTML($value, $encoding);
1008                                  $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('&#0;', '', getid3_lib::MultiByteCharString2HTML($value, $encoding));
1009                              } else {
1010                                  $this->info['tags_html'][$tag_name][$tag_key][$key] = $value;
1011                              }
1012                          }
1013                      }
1014                  }
1015  
1016                  $this->CharConvert($this->info['tags'][$tag_name], $encoding);           // only copy gets converted!
1017              }
1018  
1019          }
1020          return true;
1021      }
1022  
1023  
1024  	function getHashdata($algorithm) {
1025          switch ($algorithm) {
1026              case 'md5':
1027              case 'sha1':
1028                  break;
1029  
1030              default:
1031                  return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
1032                  break;
1033          }
1034  
1035          if ((@$this->info['fileformat'] == 'ogg') && (@$this->info['audio']['dataformat'] == 'vorbis')) {
1036  
1037              // We cannot get an identical md5_data value for Ogg files where the comments
1038              // span more than 1 Ogg page (compared to the same audio data with smaller
1039              // comments) using the normal getID3() method of MD5'ing the data between the
1040              // end of the comments and the end of the file (minus any trailing tags),
1041              // because the page sequence numbers of the pages that the audio data is on
1042              // do not match. Under normal circumstances, where comments are smaller than
1043              // the nominal 4-8kB page size, then this is not a problem, but if there are
1044              // very large comments, the only way around it is to strip off the comment
1045              // tags with vorbiscomment and MD5 that file.
1046              // This procedure must be applied to ALL Ogg files, not just the ones with
1047              // comments larger than 1 page, because the below method simply MD5's the
1048              // whole file with the comments stripped, not just the portion after the
1049              // comments block (which is the standard getID3() method.
1050  
1051              // The above-mentioned problem of comments spanning multiple pages and changing
1052              // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
1053              // currently vorbiscomment only works on OggVorbis files.
1054  
1055              if ((bool) ini_get('safe_mode')) {
1056  
1057                  $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)';
1058                  $this->info[$algorithm.'_data']  = false;
1059  
1060              } else {
1061  
1062                  // Prevent user from aborting script
1063                  $old_abort = ignore_user_abort(true);
1064  
1065                  // Create empty file
1066                  $empty = tempnam('*', 'getID3');
1067                  touch($empty);
1068  
1069  
1070                  // Use vorbiscomment to make temp file without comments
1071                  $temp = tempnam('*', 'getID3');
1072                  $file = $this->info['filenamepath'];
1073  
1074                  if (GETID3_OS_ISWINDOWS) {
1075  
1076                      if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
1077  
1078                          $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
1079                          $VorbisCommentError = `$commandline`;
1080  
1081                      } else {
1082  
1083                          $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR;
1084  
1085                      }
1086  
1087                  } else {
1088  
1089                      $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1';
1090                      $VorbisCommentError = `$commandline`;
1091  
1092                  }
1093  
1094                  if (!empty($VorbisCommentError)) {
1095  
1096                      $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;
1097                      $this->info[$algorithm.'_data']  = false;
1098  
1099                  } else {
1100  
1101                      // Get hash of newly created file
1102                      switch ($algorithm) {
1103                          case 'md5':
1104                              $this->info[$algorithm.'_data'] = getid3_lib::md5_file($temp);
1105                              break;
1106  
1107                          case 'sha1':
1108                              $this->info[$algorithm.'_data'] = getid3_lib::sha1_file($temp);
1109                              break;
1110                      }
1111                  }
1112  
1113                  // Clean up
1114                  unlink($empty);
1115                  unlink($temp);
1116  
1117                  // Reset abort setting
1118                  ignore_user_abort($old_abort);
1119  
1120              }
1121  
1122          } else {
1123  
1124              if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
1125  
1126                  // get hash from part of file
1127                  $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
1128  
1129              } else {
1130  
1131                  // get hash from whole file
1132                  switch ($algorithm) {
1133                      case 'md5':
1134                          $this->info[$algorithm.'_data'] = getid3_lib::md5_file($this->info['filenamepath']);
1135                          break;
1136  
1137                      case 'sha1':
1138                          $this->info[$algorithm.'_data'] = getid3_lib::sha1_file($this->info['filenamepath']);
1139                          break;
1140                  }
1141              }
1142  
1143          }
1144          return true;
1145      }
1146  
1147  
1148  	function ChannelsBitratePlaytimeCalculations() {
1149  
1150          // set channelmode on audio
1151          if (@$this->info['audio']['channels'] == '1') {
1152              $this->info['audio']['channelmode'] = 'mono';
1153          } elseif (@$this->info['audio']['channels'] == '2') {
1154              $this->info['audio']['channelmode'] = 'stereo';
1155          }
1156  
1157          // Calculate combined bitrate - audio + video
1158          $CombinedBitrate  = 0;
1159          $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0);
1160          $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
1161          if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) {
1162              $this->info['bitrate'] = $CombinedBitrate;
1163          }
1164          //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) {
1165          //    // for example, VBR MPEG video files cannot determine video bitrate:
1166          //    // should not set overall bitrate and playtime from audio bitrate only
1167          //    unset($this->info['bitrate']);
1168          //}
1169  
1170          if (!isset($this->info['playtime_seconds']) && !empty($this->info['bitrate'])) {
1171              $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate'];
1172          }
1173  
1174          // Set playtime string
1175          if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) {
1176              $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']);
1177          }
1178      }
1179  
1180  
1181  	function CalculateCompressionRatioVideo() {
1182          if (empty($this->info['video'])) {
1183              return false;
1184          }
1185          if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) {
1186              return false;
1187          }
1188          if (empty($this->info['video']['bits_per_sample'])) {
1189              return false;
1190          }
1191  
1192          switch ($this->info['video']['dataformat']) {
1193              case 'bmp':
1194              case 'gif':
1195              case 'jpeg':
1196              case 'jpg':
1197              case 'png':
1198              case 'tiff':
1199                  $FrameRate = 1;
1200                  $PlaytimeSeconds = 1;
1201                  $BitrateCompressed = $this->info['filesize'] * 8;
1202                  break;
1203  
1204              default:
1205                  if (!empty($this->info['video']['frame_rate'])) {
1206                      $FrameRate = $this->info['video']['frame_rate'];
1207                  } else {
1208                      return false;
1209                  }
1210                  if (!empty($this->info['playtime_seconds'])) {
1211                      $PlaytimeSeconds = $this->info['playtime_seconds'];
1212                  } else {
1213                      return false;
1214                  }
1215                  if (!empty($this->info['video']['bitrate'])) {
1216                      $BitrateCompressed = $this->info['video']['bitrate'];
1217                  } else {
1218                      return false;
1219                  }
1220                  break;
1221          }
1222          $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate;
1223  
1224          $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed;
1225          return true;
1226      }
1227  
1228  
1229  	function CalculateCompressionRatioAudio() {
1230          if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate'])) {
1231              return false;
1232          }
1233          $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));
1234  
1235          if (!empty($this->info['audio']['streams'])) {
1236              foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {
1237                  if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) {
1238                      $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16));
1239                  }
1240              }
1241          }
1242          return true;
1243      }
1244  
1245  
1246  	function CalculateReplayGain() {
1247          if (isset($this->info['replay_gain'])) {
1248              $this->info['replay_gain']['reference_volume'] = 89;
1249              if (isset($this->info['replay_gain']['track']['adjustment'])) {
1250                  $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
1251              }
1252              if (isset($this->info['replay_gain']['album']['adjustment'])) {
1253                  $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
1254              }
1255  
1256              if (isset($this->info['replay_gain']['track']['peak'])) {
1257                  $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
1258              }
1259              if (isset($this->info['replay_gain']['album']['peak'])) {
1260                  $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
1261              }
1262          }
1263          return true;
1264      }
1265  
1266  	function ProcessAudioStreams() {
1267          if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
1268              if (!isset($this->info['audio']['streams'])) {
1269                  foreach ($this->info['audio'] as $key => $value) {
1270                      if ($key != 'streams') {
1271                          $this->info['audio']['streams'][0][$key] = $value;
1272                      }
1273                  }
1274              }
1275          }
1276          return true;
1277      }
1278  
1279  }
1280  
1281  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]