Make WordPress Core

Changeset 29734


Ignore:
Timestamp:
09/11/2014 07:06:33 PM (12 years ago)
Author:
wonderboymusic
Message:

Update getID3 library to 1.9.8.

Changes:
​https://github.com/JamesHeinrich/getID3/compare/1.9.7...v1.9.8

Fixes #29627.

Location:
trunk/src/wp-includes/ID3
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ID3/getid3.lib.php

    r29378 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78//                                                             //
    … …  
    283284                        } else {
    284285                                throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()');
    285                                 break;
    286286                        }
    287287                }
    … …  
    636636                if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) {
    637637                        if (($fp_dest = fopen($filename_dest, 'wb'))) {
    638                                 if (fseek($fp_src, $offset, SEEK_SET) == 0) {
     638                                if (fseek($fp_src, $offset) == 0) {
    639639                                        $byteslefttowrite = $length;
    640640                                        while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
    … …  
    987987        }
    988988
     989        public static function recursiveMultiByteCharString2HTML($data, $charset='ISO-8859-1') {
     990                if (is_string($data)) {
     991                        return self::MultiByteCharString2HTML($data, $charset);
     992                } elseif (is_array($data)) {
     993                        $return_data = array();
     994                        foreach ($data as $key => $value) {
     995                                $return_data[$key] = self::recursiveMultiByteCharString2HTML($value, $charset);
     996                        }
     997                        return $return_data;
     998                }
     999                // integer, float, objects, resources, etc
     1000                return $data;
     1001        }
    9891002
    9901003        public static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
    … …  
    12111224                                                                foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
    12121225                                                                        $oldvaluelength = strlen(trim($existingvalue));
    1213                                                                         if (($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
     1226                                                                        if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
    12141227                                                                                $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
    1215                                                                                 break 2;
     1228                                                                                //break 2;
     1229                                                                                break;
    12161230                                                                        }
    12171231                                                                }
    … …  
    12201234                                                        if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
    12211235                                                                $value = (is_string($value) ? trim($value) : $value);
    1222                                                                 $ThisFileInfo['comments'][$tagname][] = $value;
     1236                                                                if (!is_numeric($key)) {
     1237                                                                        $ThisFileInfo['comments'][$tagname][$key] = $value;
     1238                                                                } else {
     1239                                                                        $ThisFileInfo['comments'][$tagname][]     = $value;
     1240                                                                }
    12231241                                                        }
    12241242                                                }
    … …  
    12281246
    12291247                        // Copy to ['comments_html']
    1230                         foreach ($ThisFileInfo['comments'] as $field => $values) {
    1231                                 if ($field == 'picture') {
    1232                                         // pictures can take up a lot of space, and we don't need multiple copies of them
    1233                                         // let there be a single copy in [comments][picture], and not elsewhere
    1234                                         continue;
    1235                                 }
    1236                                 foreach ($values as $index => $value) {
    1237                                         if (is_array($value)) {
    1238                                                 $ThisFileInfo['comments_html'][$field][$index] = $value;
    1239                                         } else {
    1240                                                 $ThisFileInfo['comments_html'][$field][$index] = str_replace('�', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
     1248                        if (!empty($ThisFileInfo['comments'])) {
     1249                                foreach ($ThisFileInfo['comments'] as $field => $values) {
     1250                                        if ($field == 'picture') {
     1251                                                // pictures can take up a lot of space, and we don't need multiple copies of them
     1252                                                // let there be a single copy in [comments][picture], and not elsewhere
     1253                                                continue;
     1254                                        }
     1255                                        foreach ($values as $index => $value) {
     1256                                                if (is_array($value)) {
     1257                                                        $ThisFileInfo['comments_html'][$field][$index] = $value;
     1258                                                } else {
     1259                                                        $ThisFileInfo['comments_html'][$field][$index] = str_replace('�', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
     1260                                                }
    12411261                                        }
    12421262                                }
    12431263                        }
     1264
    12441265                }
    12451266                return true;
    … …  
    13401361                return $filesize;
    13411362        }
     1363
     1364
     1365        /**
     1366        * Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268)
     1367        * @param string $path A path.
     1368        * @param string $suffix If the name component ends in suffix this will also be cut off.
     1369        * @return string
     1370        */
     1371        public static function mb_basename($path, $suffix = null) {
     1372                $splited = preg_split('#/#', rtrim($path, '/ '));
     1373                return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1);
     1374        }
     1375
    13421376}
  • trunk/src/wp-includes/ID3/getid3.php

    r24696 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78//                                                             //
    … …  
    1819        define('GETID3_INCLUDEPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
    1920}
     21// Workaround Bug #39923 (https://bugs.php.net/bug.php?id=39923)
     22if (!defined('IMG_JPG') && defined('IMAGETYPE_JPEG')) {
     23        define('IMG_JPG', IMAGETYPE_JPEG);
     24}
    2025
    2126// attempt to define temp dir as something flexible but reliable
    … …  
    2429        $temp_dir = '';
    2530}
    26 if (!$temp_dir && function_exists('sys_get_temp_dir')) {
    27         // PHP v5.2.1+
     31if (!$temp_dir) {
    2832        // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts
    2933        $temp_dir = sys_get_temp_dir();
    3034}
    31 $temp_dir = realpath($temp_dir);
     35$temp_dir = @realpath($temp_dir); // see https://github.com/JamesHeinrich/getID3/pull/10
    3236$open_basedir = ini_get('open_basedir');
    3337if ($open_basedir) {
    … …  
    5862}
    5963// $temp_dir = '/something/else/';  // feel free to override temp dir here if it works better for your system
    60 define('GETID3_TEMP_DIR', $temp_dir);
     64if (!defined('GETID3_TEMP_DIR')) {
     65        define('GETID3_TEMP_DIR', $temp_dir);
     66}
    6167unset($open_basedir, $temp_dir);
    6268
    … …  
    98104        public $info;                             // Result array.
    99105        public $tempdir = GETID3_TEMP_DIR;
     106        public $memory_limit = 0;
    100107
    101108        // Protected variables
    102109        protected $startup_error   = '';
    103110        protected $startup_warning = '';
    104         protected $memory_limit    = 0;
    105 
    106         const VERSION           = '1.9.7-20130705';
     111
     112        const VERSION           = '1.9.8-20140511';
    107113        const FREAD_BUFFER_SIZE = 32768;
    108114
    … …  
    112118        // public: constructor
    113119        public function __construct() {
    114 
    115                 // Check for PHP version
    116                 $required_php_version = '5.0.5';
    117                 if (version_compare(PHP_VERSION, $required_php_version, '<')) {
    118                         $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION;
    119                         return false;
    120                 }
    121120
    122121                // Check memory
    … …  
    262261
    263262                        // open local file
    264                         if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
     263                        //if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see http://www.getid3.org/phpBB3/viewtopic.php?t=1720
     264                        if ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
    265265                                // great
    266266                        } else {
    267                                 throw new getid3_exception('Could not open "'.$filename.'" (does not exist, or is not a file)');
     267                                $errormessagelist = array();
     268                                if (!is_readable($filename)) {
     269                                        $errormessagelist[] = '!is_readable';
     270                                }
     271                                if (!is_file($filename)) {
     272                                        $errormessagelist[] = '!is_file';
     273                                }
     274                                if (!file_exists($filename)) {
     275                                        $errormessagelist[] = '!file_exists';
     276                                }
     277                                if (empty($errormessagelist)) {
     278                                        $errormessagelist[] = 'fopen failed';
     279                                }
     280                                throw new getid3_exception('Could not open "'.$filename.'" ('.implode('; ', $errormessagelist).')');
    268281                        }
    269282
    270283                        $this->info['filesize'] = filesize($filename);
    271284                        // set redundant parameters - might be needed in some include file
    272                         $this->info['filename']     = basename($filename);
     285                        // filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion
     286                        $filename = str_replace('\\', '/', $filename);
    273287                        $this->info['filepath']     = str_replace('\\', '/', realpath(dirname($filename)));
     288                        $this->info['filename']     = getid3_lib::mb_basename($filename);
    274289                        $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
    275290
    … …  
    353368                        // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier
    354369                        if (!$this->option_tag_id3v2) {
    355                                 fseek($this->fp, 0, SEEK_SET);
     370                                fseek($this->fp, 0);
    356371                                $header = fread($this->fp, 10);
    357372                                if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) {
    … …  
    364379
    365380                        // read 32 kb file data
    366                         fseek($this->fp, $this->info['avdataoffset'], SEEK_SET);
     381                        fseek($this->fp, $this->info['avdataoffset']);
    367382                        $formattest = fread($this->fp, 32774);
    368383
    … …  
    587602                                                        'module'    => 'au',
    588603                                                        'mime_type' => 'audio/basic',
     604                                                ),
     605
     606                                // AMR  - audio       - Adaptive Multi Rate
     607                                'amr'  => array(
     608                                                        'pattern'   => '^\x23\x21AMR\x0A', // #!AMR[0A]
     609                                                        'group'     => 'audio',
     610                                                        'module'    => 'amr',
     611                                                        'mime_type' => 'audio/amr',
    589612                                                ),
    590613
    … …  
    11621185                                'flac'      => array('vorbiscomment' , 'UTF-8'),
    11631186                                'divxtag'   => array('divx'          , 'ISO-8859-1'),
     1187                                'iptc'      => array('iptc'          , 'ISO-8859-1'),
    11641188                        );
    11651189                }
    … …  
    11821206                                                }
    11831207                                                if ($value) {
    1184                                                         $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
     1208                                                        if (!is_numeric($key)) {
     1209                                                                $this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value;
     1210                                                        } else {
     1211                                                                $this->info['tags'][trim($tag_name)][trim($tag_key)][]     = $value;
     1212                                                        }
    11851213                                                }
    11861214                                        }
    … …  
    11971225                                if ($this->option_tags_html) {
    11981226                                        foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
    1199                                                 foreach ($valuearray as $key => $value) {
    1200                                                         if (is_string($value)) {
    1201                                                                 //$this->info['tags_html'][$tag_name][$tag_key][$key] = getid3_lib::MultiByteCharString2HTML($value, $encoding);
    1202                                                                 $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('&#0;', '', trim(getid3_lib::MultiByteCharString2HTML($value, $encoding)));
    1203                                                         } else {
    1204                                                                 $this->info['tags_html'][$tag_name][$tag_key][$key] = $value;
    1205                                                         }
    1206                                                 }
     1227                                                $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $encoding);
    12071228                                        }
    12081229                                }
    … …  
    12601281        }
    12611282
    1262 
    12631283        public function getHashdata($algorithm) {
    12641284                switch ($algorithm) {
    … …  
    15661586
    15671587
    1568 abstract class getid3_handler
    1569 {
     1588abstract class getid3_handler {
     1589
     1590        /**
     1591        * @var getID3
     1592        */
    15701593        protected $getid3;                       // pointer
    15711594
    … …  
    15941617        public function AnalyzeString($string) {
    15951618                // Enter string mode
    1596             $this->setStringMode($string);
     1619                $this->setStringMode($string);
    15971620
    15981621                // Save info
    … …  
    16351658                        return substr($this->data_string, $this->data_string_position - $bytes, $bytes);
    16361659                }
    1637             $pos = $this->ftell() + $bytes;
    1638             if (!getid3_lib::intValueSupported($pos)) {
     1660                $pos = $this->ftell() + $bytes;
     1661                if (!getid3_lib::intValueSupported($pos)) {
    16391662                        throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10);
    1640             }
     1663                }
    16411664                return fread($this->getid3->fp, $bytes);
    16421665        }
    … …  
    16581681                        }
    16591682                        return 0;
    1660             } else {
    1661                 $pos = $bytes;
    1662                 if ($whence == SEEK_CUR) {
     1683                } else {
     1684                        $pos = $bytes;
     1685                        if ($whence == SEEK_CUR) {
    16631686                                $pos = $this->ftell() + $bytes;
    1664                 } elseif ($whence == SEEK_END) {
    1665                                 $pos = $this->info['filesize'] + $bytes;
    1666                 }
    1667                 if (!getid3_lib::intValueSupported($pos)) {
     1687                        } elseif ($whence == SEEK_END) {
     1688                                $pos = $this->getid3->info['filesize'] + $bytes;
     1689                        }
     1690                        if (!getid3_lib::intValueSupported($pos)) {
    16681691                                throw new getid3_exception('cannot fseek('.$pos.') because beyond PHP filesystem limit', 10);
    16691692                        }
    … …  
    16831706        }
    16841707
    1685         protected function error($text)
    1686         {
     1708        protected function error($text) {
    16871709                $this->getid3->info['error'][] = $text;
    16881710
    … …  
    16901712        }
    16911713
    1692         protected function warning($text)
    1693         {
     1714        protected function warning($text) {
    16941715                return $this->getid3->warning($text);
    16951716        }
    16961717
    1697         protected function notice($text)
    1698         {
     1718        protected function notice($text) {
    16991719                // does nothing for now
    17001720        }
  • trunk/src/wp-includes/ID3/license.txt

    r24696 r29734  
    33//  available at http://getid3.sourceforge.net                 //
    44//            or http://www.getid3.org                         //
     5//          also https://github.com/JamesHeinrich/getID3       //
    56/////////////////////////////////////////////////////////////////
    67
  • trunk/src/wp-includes/ID3/module.audio-video.asf.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    1617getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
    1718
    18 class getid3_asf extends getid3_handler
    19 {
     19class getid3_asf extends getid3_handler {
    2020
    2121        public function __construct(getID3 $getid3) {
    … …  
    6767                $info['fileformat'] = 'asf';
    6868
    69                 fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
    70                 $HeaderObjectData = fread($this->getid3->fp, 30);
     69                $this->fseek($info['avdataoffset']);
     70                $HeaderObjectData = $this->fread(30);
    7171
    7272                $thisfile_asf_headerobject['objectid']      = substr($HeaderObjectData, 0, 16);
    7373                $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']);
    7474                if ($thisfile_asf_headerobject['objectid'] != GETID3_ASF_Header_Object) {
    75                         $info['warning'][] = 'ASF header GUID {'.$this->BytestringToGUID($thisfile_asf_headerobject['objectid']).'} does not match expected "GETID3_ASF_Header_Object" GUID {'.$this->BytestringToGUID(GETID3_ASF_Header_Object).'}';
    76                         unset($info['fileformat']);
    77                         unset($info['asf']);
    78                         return false;
    79                         break;
     75                        unset($info['fileformat'], $info['asf']);
     76                        return $this->error('ASF header GUID {'.$this->BytestringToGUID($thisfile_asf_headerobject['objectid']).'} does not match expected "GETID3_ASF_Header_Object" GUID {'.$this->BytestringToGUID(GETID3_ASF_Header_Object).'}');
    8077                }
    8178                $thisfile_asf_headerobject['objectsize']    = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8));
    … …  
    8481                $thisfile_asf_headerobject['reserved2']     = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1));
    8582
    86                 $NextObjectOffset = ftell($this->getid3->fp);
    87                 $ASFHeaderData = fread($this->getid3->fp, $thisfile_asf_headerobject['objectsize'] - 30);
     83                $NextObjectOffset = $this->ftell();
     84                $ASFHeaderData = $this->fread($thisfile_asf_headerobject['objectsize'] - 30);
    8885                $offset = 0;
    8986
    … …  
    285282                                        $thisfile_asf_headerextensionobject['extension_data']      =                              substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']);
    286283                                        $unhandled_sections = 0;
    287                                         $thisfile_asf_headerextensionobject['extension_data_parsed'] = $this->ASF_HeaderExtensionObjectDataParse($thisfile_asf_headerextensionobject['extension_data'], $unhandled_sections);
     284                                        $thisfile_asf_headerextensionobject['extension_data_parsed'] = $this->HeaderExtensionObjectDataParse($thisfile_asf_headerextensionobject['extension_data'], $unhandled_sections);
    288285                                        if ($unhandled_sections === 0) {
    289286                                                unset($thisfile_asf_headerextensionobject['extension_data']);
    … …  
    333330                                                $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
    334331                                                $offset += 2;
    335                                                 $thisfile_asf_codeclistobject_codecentries_current['type'] = $this->ASFCodecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']);
     332                                                $thisfile_asf_codeclistobject_codecentries_current['type'] = self::codecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']);
    336333
    337334                                                $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
    … …  
    827824
    828825                                                        case 'id3':
    829                                                                 // id3v2 module might not be loaded
    830                                                                 if (class_exists('getid3_id3v2')) {
    831                                                                         $tempfile         = tempnam(GETID3_TEMP_DIR, 'getID3');
    832                                                                         $tempfilehandle   = fopen($tempfile, 'wb');
    833                                                                         $tempThisfileInfo = array('encoding'=>$info['encoding']);
    834                                                                         fwrite($tempfilehandle, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
    835                                                                         fclose($tempfilehandle);
    836 
    837                                                                         $getid3_temp = new getID3();
    838                                                                         $getid3_temp->openfile($tempfile);
    839                                                                         $getid3_id3v2 = new getid3_id3v2($getid3_temp);
    840                                                                         $getid3_id3v2->Analyze();
    841                                                                         $info['id3v2'] = $getid3_temp->info['id3v2'];
    842                                                                         unset($getid3_temp, $getid3_id3v2);
    843 
    844                                                                         unlink($tempfile);
     826                                                                $this->getid3->include_module('tag.id3v2');
     827
     828                                                                $getid3_id3v2 = new getid3_id3v2($this->getid3);
     829                                                                $getid3_id3v2->AnalyzeString($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
     830                                                                unset($getid3_id3v2);
     831
     832                                                                if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] > 1024) {
     833                                                                        $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = '<value too large to display>';
    845834                                                                }
    846835                                                                break;
    … …  
    861850                                                                $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1));
    862851                                                                $wm_picture_offset += 1;
    863                                                                 $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type']    = $this->WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']);
     852                                                                $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type']    = self::WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']);
    864853                                                                $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size']    = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4));
    865854                                                                $wm_picture_offset += 4;
    … …  
    11571146                }
    11581147
    1159                 while (ftell($this->getid3->fp) < $info['avdataend']) {
    1160                         $NextObjectDataHeader = fread($this->getid3->fp, 24);
     1148                while ($this->ftell() < $info['avdataend']) {
     1149                        $NextObjectDataHeader = $this->fread(24);
    11611150                        $offset = 0;
    11621151                        $NextObjectGUID = substr($NextObjectDataHeader, 0, 16);
    … …  
    11801169                                        $thisfile_asf_dataobject     = &$thisfile_asf['data_object'];
    11811170
    1182                                         $DataObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 50 - 24);
     1171                                        $DataObjectData = $NextObjectDataHeader.$this->fread(50 - 24);
    11831172                                        $offset = 24;
    11841173
    … …  
    12081197                                        // * Error Correction Data
    12091198
    1210                                         $info['avdataoffset'] = ftell($this->getid3->fp);
    1211                                         fseek($this->getid3->fp, ($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data
    1212                                         $info['avdataend'] = ftell($this->getid3->fp);
     1199                                        $info['avdataoffset'] = $this->ftell();
     1200                                        $this->fseek(($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data
     1201                                        $info['avdataend'] = $this->ftell();
    12131202                                        break;
    12141203
    … …  
    12301219                                        $thisfile_asf_simpleindexobject      = &$thisfile_asf['simple_index_object'];
    12311220
    1232                                         $SimpleIndexObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 56 - 24);
     1221                                        $SimpleIndexObjectData = $NextObjectDataHeader.$this->fread(56 - 24);
    12331222                                        $offset = 24;
    12341223
    … …  
    12471236                                        $offset += 4;
    12481237
    1249                                         $IndexEntriesData = $SimpleIndexObjectData.fread($this->getid3->fp, 6 * $thisfile_asf_simpleindexobject['index_entries_count']);
     1238                                        $IndexEntriesData = $SimpleIndexObjectData.$this->fread(6 * $thisfile_asf_simpleindexobject['index_entries_count']);
    12501239                                        for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) {
    12511240                                                $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
    … …  
    12841273                                        $thisfile_asf_asfindexobject      = &$thisfile_asf['asf_index_object'];
    12851274
    1286                                         $ASFIndexObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 34 - 24);
     1275                                        $ASFIndexObjectData = $NextObjectDataHeader.$this->fread(34 - 24);
    12871276                                        $offset = 24;
    12881277
    … …  
    12981287                                        $offset += 4;
    12991288
    1300                                         $ASFIndexObjectData .= fread($this->getid3->fp, 4 * $thisfile_asf_asfindexobject['index_specifiers_count']);
     1289                                        $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count']);
    13011290                                        for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
    13021291                                                $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
    … …  
    13081297                                        }
    13091298
    1310                                         $ASFIndexObjectData .= fread($this->getid3->fp, 4);
     1299                                        $ASFIndexObjectData .= $this->fread(4);
    13111300                                        $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
    13121301                                        $offset += 4;
    13131302
    1314                                         $ASFIndexObjectData .= fread($this->getid3->fp, 8 * $thisfile_asf_asfindexobject['index_specifiers_count']);
     1303                                        $ASFIndexObjectData .= $this->fread(8 * $thisfile_asf_asfindexobject['index_specifiers_count']);
    13151304                                        for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
    13161305                                                $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8));
    … …  
    13181307                                        }
    13191308
    1320                                         $ASFIndexObjectData .= fread($this->getid3->fp, 4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']);
     1309                                        $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']);
    13211310                                        for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) {
    13221311                                                for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
    … …  
    13331322                                                $info['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8);
    13341323                                        } else {
    1335                                                 $info['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.(ftell($this->getid3->fp) - 16 - 8);
    1336                                         }
    1337                                         fseek($this->getid3->fp, ($NextObjectSize - 16 - 8), SEEK_CUR);
     1324                                                $info['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.($this->ftell() - 16 - 8);
     1325                                        }
     1326                                        $this->fseek(($NextObjectSize - 16 - 8), SEEK_CUR);
    13381327                                        break;
    13391328                        }
    … …  
    14341423                }
    14351424                if (!empty($thisfile_video['streams'])) {
    1436                         $thisfile_video['streams']['resolution_x'] = 0;
    1437                         $thisfile_video['streams']['resolution_y'] = 0;
     1425                        $thisfile_video['resolution_x'] = 0;
     1426                        $thisfile_video['resolution_y'] = 0;
    14381427                        foreach ($thisfile_video['streams'] as $key => $valuearray) {
    1439                                 if (($valuearray['resolution_x'] > $thisfile_video['streams']['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['streams']['resolution_y'])) {
     1428                                if (($valuearray['resolution_x'] > $thisfile_video['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['resolution_y'])) {
    14401429                                        $thisfile_video['resolution_x'] = $valuearray['resolution_x'];
    14411430                                        $thisfile_video['resolution_y'] = $valuearray['resolution_y'];
    … …  
    14521441        }
    14531442
    1454         public static function ASFCodecListObjectTypeLookup($CodecListType) {
    1455                 static $ASFCodecListObjectTypeLookup = array();
    1456                 if (empty($ASFCodecListObjectTypeLookup)) {
    1457                         $ASFCodecListObjectTypeLookup[0x0001] = 'Video Codec';
    1458                         $ASFCodecListObjectTypeLookup[0x0002] = 'Audio Codec';
    1459                         $ASFCodecListObjectTypeLookup[0xFFFF] = 'Unknown Codec';
    1460                 }
    1461 
    1462                 return (isset($ASFCodecListObjectTypeLookup[$CodecListType]) ? $ASFCodecListObjectTypeLookup[$CodecListType] : 'Invalid Codec Type');
     1443        public static function codecListObjectTypeLookup($CodecListType) {
     1444                static $lookup = array(
     1445                        0x0001 => 'Video Codec',
     1446                        0x0002 => 'Audio Codec',
     1447                        0xFFFF => 'Unknown Codec'
     1448                );
     1449
     1450                return (isset($lookup[$CodecListType]) ? $lookup[$CodecListType] : 'Invalid Codec Type');
    14631451        }
    14641452
    … …  
    16671655
    16681656        public static function WMpictureTypeLookup($WMpictureType) {
    1669                 static $WMpictureTypeLookup = array();
    1670                 if (empty($WMpictureTypeLookup)) {
    1671                         $WMpictureTypeLookup[0x03] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Front Cover');
    1672                         $WMpictureTypeLookup[0x04] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Back Cover');
    1673                         $WMpictureTypeLookup[0x00] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'User Defined');
    1674                         $WMpictureTypeLookup[0x05] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Leaflet Page');
    1675                         $WMpictureTypeLookup[0x06] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Media Label');
    1676                         $WMpictureTypeLookup[0x07] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lead Artist');
    1677                         $WMpictureTypeLookup[0x08] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Artist');
    1678                         $WMpictureTypeLookup[0x09] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Conductor');
    1679                         $WMpictureTypeLookup[0x0A] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band');
    1680                         $WMpictureTypeLookup[0x0B] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Composer');
    1681                         $WMpictureTypeLookup[0x0C] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lyricist');
    1682                         $WMpictureTypeLookup[0x0D] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Recording Location');
    1683                         $WMpictureTypeLookup[0x0E] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Recording');
    1684                         $WMpictureTypeLookup[0x0F] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Performance');
    1685                         $WMpictureTypeLookup[0x10] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Video Screen Capture');
    1686                         $WMpictureTypeLookup[0x12] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Illustration');
    1687                         $WMpictureTypeLookup[0x13] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band Logotype');
    1688                         $WMpictureTypeLookup[0x14] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Publisher Logotype');
     1657                static $lookup = null;
     1658                if ($lookup === null) {
     1659                        $lookup = array(
     1660                                0x03 => 'Front Cover',
     1661                                0x04 => 'Back Cover',
     1662                                0x00 => 'User Defined',
     1663                                0x05 => 'Leaflet Page',
     1664                                0x06 => 'Media Label',
     1665                                0x07 => 'Lead Artist',
     1666                                0x08 => 'Artist',
     1667                                0x09 => 'Conductor',
     1668                                0x0A => 'Band',
     1669                                0x0B => 'Composer',
     1670                                0x0C => 'Lyricist',
     1671                                0x0D => 'Recording Location',
     1672                                0x0E => 'During Recording',
     1673                                0x0F => 'During Performance',
     1674                                0x10 => 'Video Screen Capture',
     1675                                0x12 => 'Illustration',
     1676                                0x13 => 'Band Logotype',
     1677                                0x14 => 'Publisher Logotype'
     1678                        );
     1679                        $lookup = array_map(function($str) {
     1680                                return getid3_lib::iconv_fallback('UTF-8', 'UTF-16LE', $str);
     1681                        }, $lookup);
    16891682                }
    1690                 return (isset($WMpictureTypeLookup[$WMpictureType]) ? $WMpictureTypeLookup[$WMpictureType] : '');
     1683
     1684                return (isset($lookup[$WMpictureType]) ? $lookup[$WMpictureType] : '');
    16911685        }
    16921686
    1693         public function ASF_HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) {
     1687        public function HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) {
    16941688                // http://msdn.microsoft.com/en-us/library/bb643323.aspx
    16951689
    … …  
    18261820                                                $descriptionRecord['data_type']          = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset,  2));
    18271821                                                $offset += 2;
    1828                                                 $descriptionRecord['data_type_text'] = $this->ASFmetadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']);
     1822                                                $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']);
    18291823
    18301824                                                $descriptionRecord['data_length']        = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset,  4));
    … …  
    18981892                                                $descriptionRecord['data_type']           = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset,  2));
    18991893                                                $offset += 2;
    1900                                                 $descriptionRecord['data_type_text'] = $this->ASFmetadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']);
     1894                                                $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']);
    19011895
    19021896                                                $descriptionRecord['data_length']         = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset,  4));
    … …  
    19381932
    19391933
    1940         public static function ASFmetadataLibraryObjectDataTypeLookup($id) {
    1941                 static $ASFmetadataLibraryObjectDataTypeLookup = array(
     1934        public static function metadataLibraryObjectDataTypeLookup($id) {
     1935                static $lookup = array(
    19421936                        0x0000 => 'Unicode string', // The data consists of a sequence of Unicode characters
    19431937                        0x0001 => 'BYTE array',     // The type of the data is implementation-specific
    … …  
    19481942                        0x0006 => 'GUID',           // The data is 16 bytes long and should be interpreted as a 128-bit GUID
    19491943                );
    1950                 return (isset($ASFmetadataLibraryObjectDataTypeLookup[$id]) ? $ASFmetadataLibraryObjectDataTypeLookup[$id] : 'invalid');
     1944                return (isset($lookup[$id]) ? $lookup[$id] : 'invalid');
    19511945        }
    19521946
    … …  
    19651959                $WMpicture['image_type_id'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 1));
    19661960                $offset += 1;
    1967                 $WMpicture['image_type']    = $this->WMpictureTypeLookup($WMpicture['image_type_id']);
     1961                $WMpicture['image_type']    = self::WMpictureTypeLookup($WMpicture['image_type_id']);
    19681962                $WMpicture['image_size']    = getid3_lib::LittleEndian2Int(substr($data, $offset, 4));
    19691963                $offset += 4;
  • trunk/src/wp-includes/ID3/module.audio-video.flv.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67//                                                             //
    78//  FLV module by Seth Kaufman <sethØwhirl-i-gig*com>          //
    … …  
    3839//  * version 0.6.1 (30 May 2011)                              //
    3940//    prevent infinite loops in expGolombUe()                  //
     41//                                                             //
     42//  * version 0.7.0 (16 Jul 2013)                              //
     43//  handle GETID3_FLV_VIDEO_VP6FLV_ALPHA                       //
     44//  improved AVCSequenceParameterSetReader::readData()         //
     45//    by Xander Schouwerwou <schouwerwouØgmail*com>            //
    4046//                                                             //
    4147/////////////////////////////////////////////////////////////////
    … …  
    6874define('H264_PROFILE_HIGH444_PREDICTIVE', 244);
    6975
    70 class getid3_flv extends getid3_handler
    71 {
     76class getid3_flv extends getid3_handler {
     77
     78        const magic = 'FLV';
     79
    7280        public $max_frames = 100000; // break out of the loop if too many frames have been scanned; only scan this many if meta frame does not contain useful duration
    7381
    … …  
    7583                $info = &$this->getid3->info;
    7684
    77                 fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
     85                $this->fseek($info['avdataoffset']);
    7886
    7987                $FLVdataLength = $info['avdataend'] - $info['avdataoffset'];
    80                 $FLVheader = fread($this->getid3->fp, 5);
     88                $FLVheader = $this->fread(5);
    8189
    8290                $info['fileformat'] = 'flv';
    … …  
    8593                $TypeFlags                          = getid3_lib::BigEndian2Int(substr($FLVheader, 4, 1));
    8694
    87                 $magic = 'FLV';
    88                 if ($info['flv']['header']['signature'] != $magic) {
    89                         $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['flv']['header']['signature']).'"';
    90                         unset($info['flv']);
    91                         unset($info['fileformat']);
     95                if ($info['flv']['header']['signature'] != self::magic) {
     96                        $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes(self::magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['flv']['header']['signature']).'"';
     97                        unset($info['flv'], $info['fileformat']);
    9298                        return false;
    9399                }
    … …  
    96102                $info['flv']['header']['hasVideo'] = (bool) ($TypeFlags & 0x01);
    97103
    98                 $FrameSizeDataLength = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4));
     104                $FrameSizeDataLength = getid3_lib::BigEndian2Int($this->fread(4));
    99105                $FLVheaderFrameLength = 9;
    100106                if ($FrameSizeDataLength > $FLVheaderFrameLength) {
    101                         fseek($this->getid3->fp, $FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR);
     107                        $this->fseek($FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR);
    102108                }
    103109                $Duration = 0;
    … …  
    109115                $info['flv']['framecount'] = array('total'=>0, 'audio'=>0, 'video'=>0);
    110116                $flv_framecount = &$info['flv']['framecount'];
    111                 while (((ftell($this->getid3->fp) + 16) < $info['avdataend']) && (($tagParseCount++ <= $this->max_frames) || !$found_valid_meta_playtime))  {
    112                         $ThisTagHeader = fread($this->getid3->fp, 16);
     117                while ((($this->ftell() + 16) < $info['avdataend']) && (($tagParseCount++ <= $this->max_frames) || !$found_valid_meta_playtime))  {
     118                        $ThisTagHeader = $this->fread(16);
    113119
    114120                        $PreviousTagLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader,  0, 4));
    … …  
    117123                        $Timestamp         = getid3_lib::BigEndian2Int(substr($ThisTagHeader,  8, 3));
    118124                        $LastHeaderByte    = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 15, 1));
    119                         $NextOffset = ftell($this->getid3->fp) - 1 + $DataLength;
     125                        $NextOffset = $this->ftell() - 1 + $DataLength;
    120126                        if ($Timestamp > $Duration) {
    121127                                $Duration = $Timestamp;
    … …  
    141147                                                $info['flv']['video']['videoCodec'] = $LastHeaderByte & 0x07;
    142148
    143                                                 $FLVvideoHeader = fread($this->getid3->fp, 11);
     149                                                $FLVvideoHeader = $this->fread(11);
    144150
    145151                                                if ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H264) {
    … …  
    161167                                                                        $spsSize = getid3_lib::LittleEndian2Int(substr($FLVvideoHeader, 9, 2));
    162168                                                                        //      read the first SequenceParameterSet
    163                                                                         $sps = fread($this->getid3->fp, $spsSize);
     169                                                                        $sps = $this->fread($spsSize);
    164170                                                                        if (strlen($sps) == $spsSize) { //      make sure that whole SequenceParameterSet was red
    165171                                                                                $spsReader = new AVCSequenceParameterSetReader($sps);
    … …  
    186192                                                                        //$info['video']['resolution_y'] = ($PictureSizeEnc & 0xFF00) >> 8;
    187193
    188                                                                         $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 2));
    189                                                                         $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2));
    190                                                                         $PictureSizeEnc['x'] >>= 7;
    191                                                                         $PictureSizeEnc['y'] >>= 7;
     194                                                                        $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 2)) >> 7;
     195                                                                        $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)) >> 7;
    192196                                                                        $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFF;
    193197                                                                        $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFF;
    … …  
    195199
    196200                                                                case 1:
    197                                                                         $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 3));
    198                                                                         $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3));
    199                                                                         $PictureSizeEnc['x'] >>= 7;
    200                                                                         $PictureSizeEnc['y'] >>= 7;
     201                                                                        $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 3)) >> 7;
     202                                                                        $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3)) >> 7;
    201203                                                                        $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFFFF;
    202204                                                                        $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFFFF;
    … …  
    234236
    235237                                                        }
     238
     239                                                } elseif ($info['flv']['video']['videoCodec'] ==  GETID3_FLV_VIDEO_VP6FLV_ALPHA) {
     240
     241                                                        /* contributed by schouwerwouØgmail*com */
     242                                                        if (!isset($info['video']['resolution_x'])) { // only when meta data isn't set
     243                                                                $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2));
     244                                                                $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 2));
     245                                                                $info['video']['resolution_x'] = ($PictureSizeEnc['x'] & 0xFF) << 3;
     246                                                                $info['video']['resolution_y'] = ($PictureSizeEnc['y'] & 0xFF) << 3;
     247                                                        }
     248                                                        /* end schouwerwouØgmail*com */
     249
    236250                                                }
    237                                                 $info['video']['pixel_aspect_ratio'] = $info['video']['resolution_x'] / $info['video']['resolution_y'];
     251                                                if (!empty($info['video']['resolution_x']) && !empty($info['video']['resolution_y'])) {
     252                                                        $info['video']['pixel_aspect_ratio'] = $info['video']['resolution_x'] / $info['video']['resolution_y'];
     253                                                }
    238254                                        }
    239255                                        break;
    … …  
    243259                                        if (!$found_meta) {
    244260                                                $found_meta = true;
    245                                                 fseek($this->getid3->fp, -1, SEEK_CUR);
    246                                                 $datachunk = fread($this->getid3->fp, $DataLength);
     261                                                $this->fseek(-1, SEEK_CUR);
     262                                                $datachunk = $this->fread($DataLength);
    247263                                                $AMFstream = new AMFStream($datachunk);
    248264                                                $reader = new AMFReader($AMFstream);
    … …  
    280296                                        break;
    281297                        }
    282                         fseek($this->getid3->fp, $NextOffset, SEEK_SET);
     298                        $this->fseek($NextOffset);
    283299                }
    284300
    … …  
    289305
    290306                if ($info['flv']['header']['hasAudio']) {
    291                         $info['audio']['codec']           =   $this->FLVaudioFormat($info['flv']['audio']['audioFormat']);
    292                         $info['audio']['sample_rate']     =     $this->FLVaudioRate($info['flv']['audio']['audioRate']);
    293                         $info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info['flv']['audio']['audioSampleSize']);
     307                        $info['audio']['codec']           =   self::audioFormatLookup($info['flv']['audio']['audioFormat']);
     308                        $info['audio']['sample_rate']     =     self::audioRateLookup($info['flv']['audio']['audioRate']);
     309                        $info['audio']['bits_per_sample'] = self::audioBitDepthLookup($info['flv']['audio']['audioSampleSize']);
    294310
    295311                        $info['audio']['channels']   =  $info['flv']['audio']['audioType'] + 1; // 0=mono,1=stereo
    … …  
    298314                }
    299315                if (!empty($info['flv']['header']['hasVideo'])) {
    300                         $info['video']['codec']      = $this->FLVvideoCodec($info['flv']['video']['videoCodec']);
     316                        $info['video']['codec']      = self::videoCodecLookup($info['flv']['video']['videoCodec']);
    301317                        $info['video']['dataformat'] = 'flv';
    302318                        $info['video']['lossless']   = false;
    … …  
    309325                }
    310326                if (isset($info['flv']['meta']['onMetaData']['audiocodecid'])) {
    311                         $info['audio']['codec'] = $this->FLVaudioFormat($info['flv']['meta']['onMetaData']['audiocodecid']);
     327                        $info['audio']['codec'] = self::audioFormatLookup($info['flv']['meta']['onMetaData']['audiocodecid']);
    312328                }
    313329                if (isset($info['flv']['meta']['onMetaData']['videocodecid'])) {
    314                         $info['video']['codec'] = $this->FLVvideoCodec($info['flv']['meta']['onMetaData']['videocodecid']);
     330                        $info['video']['codec'] = self::videoCodecLookup($info['flv']['meta']['onMetaData']['videocodecid']);
    315331                }
    316332                return true;
    … …  
    318334
    319335
    320         public function FLVaudioFormat($id) {
    321                 $FLVaudioFormat = array(
     336        public static function audioFormatLookup($id) {
     337                static $lookup = array(
    322338                        0  => 'Linear PCM, platform endian',
    323339                        1  => 'ADPCM',
    … …  
    331347                        9  => 'reserved',
    332348                        10 => 'AAC',
    333                         11 => false, // unknown?
     349                        11 => 'Speex',
    334350                        12 => false, // unknown?
    335351                        13 => false, // unknown?
    … …  
    337353                        15 => 'Device-specific sound',
    338354                );
    339                 return (isset($FLVaudioFormat[$id]) ? $FLVaudioFormat[$id] : false);
    340         }
    341 
    342         public function FLVaudioRate($id) {
    343                 $FLVaudioRate = array(
     355                return (isset($lookup[$id]) ? $lookup[$id] : false);
     356        }
     357
     358        public static function audioRateLookup($id) {
     359                static $lookup = array(
    344360                        0 =>  5500,
    345361                        1 => 11025,
    … …  
    347363                        3 => 44100,
    348364                );
    349                 return (isset($FLVaudioRate[$id]) ? $FLVaudioRate[$id] : false);
    350         }
    351 
    352         public function FLVaudioBitDepth($id) {
    353                 $FLVaudioBitDepth = array(
     365                return (isset($lookup[$id]) ? $lookup[$id] : false);
     366        }
     367
     368        public static function audioBitDepthLookup($id) {
     369                static $lookup = array(
    354370                        0 =>  8,
    355371                        1 => 16,
    356372                );
    357                 return (isset($FLVaudioBitDepth[$id]) ? $FLVaudioBitDepth[$id] : false);
    358         }
    359 
    360         public function FLVvideoCodec($id) {
    361                 $FLVvideoCodec = array(
     373                return (isset($lookup[$id]) ? $lookup[$id] : false);
     374        }
     375
     376        public static function videoCodecLookup($id) {
     377                static $lookup = array(
    362378                        GETID3_FLV_VIDEO_H263         => 'Sorenson H.263',
    363379                        GETID3_FLV_VIDEO_SCREEN       => 'Screen video',
    … …  
    367383                        GETID3_FLV_VIDEO_H264         => 'Sorenson H.264',
    368384                );
    369                 return (isset($FLVvideoCodec[$id]) ? $FLVvideoCodec[$id] : false);
     385                return (isset($lookup[$id]) ? $lookup[$id] : false);
    370386        }
    371387}
    … …  
    375391        public $pos;
    376392
    377         public function AMFStream(&$bytes) {
     393        public function __construct(&$bytes) {
    378394                $this->bytes =& $bytes;
    379395                $this->pos = 0;
    … …  
    458474        public $stream;
    459475
    460         public function AMFReader(&$stream) {
     476        public function __construct(&$stream) {
    461477                $this->stream =& $stream;
    462478        }
    … …  
    620636        public $height;
    621637
    622         public function AVCSequenceParameterSetReader($sps) {
     638        public function __construct($sps) {
    623639                $this->sps = $sps;
    624640        }
    … …  
    627643                $this->skipBits(8);
    628644                $this->skipBits(8);
    629                 $profile = $this->getBits(8);   //      read profile
    630                 $this->skipBits(16);
    631                 $this->expGolombUe();   //      read sps id
    632                 if (in_array($profile, array(H264_PROFILE_HIGH, H264_PROFILE_HIGH10, H264_PROFILE_HIGH422, H264_PROFILE_HIGH444, H264_PROFILE_HIGH444_PREDICTIVE))) {
    633                         if ($this->expGolombUe() == 3) {
    634                                 $this->skipBits(1);
    635                         }
    636                         $this->expGolombUe();
    637                         $this->expGolombUe();
    638                         $this->skipBits(1);
    639                         if ($this->getBit()) {
    640                                 for ($i = 0; $i < 8; $i++) {
    641                                         if ($this->getBit()) {
    642                                                 $size = $i < 6 ? 16 : 64;
    643                                                 $lastScale = 8;
    644                                                 $nextScale = 8;
    645                                                 for ($j = 0; $j < $size; $j++) {
    646                                                         if ($nextScale != 0) {
    647                                                                 $deltaScale = $this->expGolombUe();
    648                                                                 $nextScale = ($lastScale + $deltaScale + 256) % 256;
    649                                                         }
    650                                                         if ($nextScale != 0) {
    651                                                                 $lastScale = $nextScale;
    652                                                         }
    653                                                 }
    654                                         }
     645                $profile = $this->getBits(8);                               // read profile
     646                if ($profile > 0) {
     647                        $this->skipBits(8);
     648                        $level_idc = $this->getBits(8);                         // level_idc
     649                        $this->expGolombUe();                                   // seq_parameter_set_id // sps
     650                        $this->expGolombUe();                                   // log2_max_frame_num_minus4
     651                        $picOrderType = $this->expGolombUe();                   // pic_order_cnt_type
     652                        if ($picOrderType == 0) {
     653                                $this->expGolombUe();                               // log2_max_pic_order_cnt_lsb_minus4
     654                        } elseif ($picOrderType == 1) {
     655                                $this->skipBits(1);                                 // delta_pic_order_always_zero_flag
     656                                $this->expGolombSe();                               // offset_for_non_ref_pic
     657                                $this->expGolombSe();                               // offset_for_top_to_bottom_field
     658                                $num_ref_frames_in_pic_order_cnt_cycle = $this->expGolombUe(); // num_ref_frames_in_pic_order_cnt_cycle
     659                                for ($i = 0; $i < $num_ref_frames_in_pic_order_cnt_cycle; $i++) {
     660                                        $this->expGolombSe();                           // offset_for_ref_frame[ i ]
    655661                                }
    656662                        }
    657                 }
    658                 $this->expGolombUe();
    659                 $pocType = $this->expGolombUe();
    660                 if ($pocType == 0) {
    661                         $this->expGolombUe();
    662                 } elseif ($pocType == 1) {
    663                         $this->skipBits(1);
    664                         $this->expGolombSe();
    665                         $this->expGolombSe();
    666                         $pocCycleLength = $this->expGolombUe();
    667                         for ($i = 0; $i < $pocCycleLength; $i++) {
    668                                 $this->expGolombSe();
     663                        $this->expGolombUe();                                   // num_ref_frames
     664                        $this->skipBits(1);                                     // gaps_in_frame_num_value_allowed_flag
     665                        $pic_width_in_mbs_minus1 = $this->expGolombUe();        // pic_width_in_mbs_minus1
     666                        $pic_height_in_map_units_minus1 = $this->expGolombUe(); // pic_height_in_map_units_minus1
     667
     668                        $frame_mbs_only_flag = $this->getBits(1);               // frame_mbs_only_flag
     669                        if ($frame_mbs_only_flag == 0) {
     670                                $this->skipBits(1);                                 // mb_adaptive_frame_field_flag
    669671                        }
    670                 }
    671                 $this->expGolombUe();
    672                 $this->skipBits(1);
    673                 $this->width = ($this->expGolombUe() + 1) * 16;
    674                 $heightMap = $this->expGolombUe() + 1;
    675                 $this->height = (2 - $this->getBit()) * $heightMap * 16;
     672                        $this->skipBits(1);                                     // direct_8x8_inference_flag
     673                        $frame_cropping_flag = $this->getBits(1);               // frame_cropping_flag
     674
     675                        $frame_crop_left_offset   = 0;
     676                        $frame_crop_right_offset  = 0;
     677                        $frame_crop_top_offset    = 0;
     678                        $frame_crop_bottom_offset = 0;
     679
     680                        if ($frame_cropping_flag) {
     681                                $frame_crop_left_offset   = $this->expGolombUe();   // frame_crop_left_offset
     682                                $frame_crop_right_offset  = $this->expGolombUe();   // frame_crop_right_offset
     683                                $frame_crop_top_offset    = $this->expGolombUe();   // frame_crop_top_offset
     684                                $frame_crop_bottom_offset = $this->expGolombUe();   // frame_crop_bottom_offset
     685                        }
     686                        $this->skipBits(1);                                     // vui_parameters_present_flag
     687                        // etc
     688
     689                        $this->width  = (($pic_width_in_mbs_minus1 + 1) * 16) - ($frame_crop_left_offset * 2) - ($frame_crop_right_offset * 2);
     690                        $this->height = ((2 - $frame_mbs_only_flag) * ($pic_height_in_map_units_minus1 + 1) * 16) - ($frame_crop_top_offset * 2) - ($frame_crop_bottom_offset * 2);
     691                }
    676692        }
    677693
  • trunk/src/wp-includes/ID3/module.audio-video.matroska.php

    r24696 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    282283                                                switch ($trackarray['CodecID']) {
    283284                                                        case 'V_MS/VFW/FOURCC':
    284                                                                 if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
    285                                                                         $this->warning('Unable to parse codec private data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio-video.riff.php"');
    286                                                                         break;
    287                                                                 }
     285                                                                getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
     286
    288287                                                                $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']);
    289288                                                                $track_info['codec'] = getid3_riff::fourccLookup($parsed['fourcc']);
    … …  
    336335                                                        case 'A_MPEG/L2':
    337336                                                        case 'A_FLAC':
    338                                                                 if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']).'.php', __FILE__, false)) {
    339                                                                         $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.'.$track_info['dataformat'].'.php"');
    340                                                                         break;
    341                                                                 }
     337                                                                getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']).'.php', __FILE__, true);
    342338
    343339                                                                if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) {
    … …  
    386382                                                                if (!empty($getid3_temp->info['warning'])) {
    387383                                                                        foreach ($getid3_temp->info['warning'] as $newerror) {
    388                                                                                 if ($track_info['dataformat'] == 'mp3' && preg_match('/^Probable truncated file: expecting \d+ bytes of audio data, only found \d+ \(short by \d+ bytes\)$/', $newerror)) {
    389                                                                                         // LAME/Xing header is probably set, but audio data is chunked into Matroska file and near-impossible to verify if audio stream is complete, so ignore useless warning
    390                                                                                         continue;
    391                                                                                 }
    392384                                                                                $this->warning($class.'() says: ['.$newerror.']');
    393385                                                                        }
    … …  
    401393                                                        case 'A_AAC/MPEG4/LC':
    402394                                                        case 'A_AAC/MPEG4/LC/SBR':
    403                                                             $this->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated');
     395                                                                $this->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated');
    404396                                                                break;
    405397
    … …  
    416408                                                                $vorbis_offset -= 1;
    417409
    418                                                                 if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, false)) {
    419                                                                         $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.ogg.php"');
    420                                                                         break;
    421                                                                 }
     410                                                                getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true);
    422411
    423412                                                                // create temp instance
    … …  
    456445
    457446                                                        case 'A_MS/ACM':
    458                                                                 if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
    459                                                                         $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio-video.riff.php"');
    460                                                                         break;
    461                                                                 }
     447                                                                getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
    462448
    463449                                                                $parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']);
    … …  
    516502
    517503                                case EBML_ID_EBML:
    518                                         $info['fileformat'] = 'matroska';
    519504                                        $info['matroska']['header']['offset'] = $top_element['offset'];
    520505                                        $info['matroska']['header']['length'] = $top_element['length'];
    … …  
    535520                                                                $element_data['data'] = getid3_lib::trimNullByte($element_data['data']);
    536521                                                                $info['matroska']['doctype'] = $element_data['data'];
     522                                                                $info['fileformat'] = $element_data['data'];
    537523                                                                break;
    538524
    … …  
    15271513                        $CodecIDlist['V_MPEG4/ISO/SP']   = 'mpeg4';
    15281514                        $CodecIDlist['V_VP8']            = 'vp8';
    1529                         $CodecIDlist['V_MS/VFW/FOURCC']  = 'riff';
    1530                         $CodecIDlist['A_MS/ACM']         = 'riff';
     1515                        $CodecIDlist['V_MS/VFW/FOURCC']  = 'vcm'; // Microsoft (TM) Video Codec Manager (VCM)
     1516                        $CodecIDlist['A_MS/ACM']         = 'acm'; // Microsoft (TM) Audio Codec Manager (ACM)
    15311517                }
    15321518                return (isset($CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid);
  • trunk/src/wp-includes/ID3/module.audio-video.quicktime.php

    r24696 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    3132                $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
    3233
    33                 fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
     34                $this->fseek($info['avdataoffset']);
    3435
    3536                $offset      = 0;
    … …  
    4142                                break;
    4243                        }
    43                         fseek($this->getid3->fp, $offset, SEEK_SET);
    44                         $AtomHeader = fread($this->getid3->fp, 8);
     44                        $this->fseek($offset);
     45                        $AtomHeader = $this->fread(8);
    4546
    4647                        $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
    … …  
    4950                        // 64-bit MOV patch by jlegateØktnc*com
    5051                        if ($atomsize == 1) {
    51                                 $atomsize = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 8));
     52                                $atomsize = getid3_lib::BigEndian2Int($this->fread(8));
    5253                        }
    5354
    … …  
    6768                                break;
    6869                        }
    69                         switch ($atomname) {
    70                                 case 'mdat': // Media DATa atom
    71                                         // 'mdat' contains the actual data for the audio/video
    72                                         if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
    73 
    74                                                 $info['avdataoffset'] = $info['quicktime'][$atomname]['offset'] + 8;
    75                                                 $OldAVDataEnd         = $info['avdataend'];
    76                                                 $info['avdataend']    = $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
    77 
    78                                                 $getid3_temp = new getID3();
    79                                                 $getid3_temp->openfile($this->getid3->filename);
    80                                                 $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
    81                                                 $getid3_temp->info['avdataend']    = $info['avdataend'];
    82                                                 $getid3_mp3 = new getid3_mp3($getid3_temp);
    83                                                 if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode(fread($this->getid3->fp, 4)))) {
    84                                                         $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
    85                                                         if (!empty($getid3_temp->info['warning'])) {
    86                                                                 foreach ($getid3_temp->info['warning'] as $value) {
    87                                                                         $info['warning'][] = $value;
    88                                                                 }
    89                                                         }
    90                                                         if (!empty($getid3_temp->info['mpeg'])) {
    91                                                                 $info['mpeg'] = $getid3_temp->info['mpeg'];
    92                                                                 if (isset($info['mpeg']['audio'])) {
    93                                                                         $info['audio']['dataformat']   = 'mp3';
    94                                                                         $info['audio']['codec']        = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3')));
    95                                                                         $info['audio']['sample_rate']  = $info['mpeg']['audio']['sample_rate'];
    96                                                                         $info['audio']['channels']     = $info['mpeg']['audio']['channels'];
    97                                                                         $info['audio']['bitrate']      = $info['mpeg']['audio']['bitrate'];
    98                                                                         $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
    99                                                                         $info['bitrate']               = $info['audio']['bitrate'];
    100                                                                 }
    101                                                         }
    102                                                 }
    103                                                 unset($getid3_mp3, $getid3_temp);
    104                                                 $info['avdataend'] = $OldAVDataEnd;
    105                                                 unset($OldAVDataEnd);
    106 
    107                                         }
    108                                         break;
    109 
    110                                 case 'free': // FREE space atom
    111                                 case 'skip': // SKIP atom
    112                                 case 'wide': // 64-bit expansion placeholder atom
    113                                         // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
    114                                         break;
    115 
    116                                 default:
    117                                         $atomHierarchy = array();
    118                                         $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, fread($this->getid3->fp, $atomsize), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
    119                                         break;
    120                         }
     70                        $atomHierarchy = array();
     71                        $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, round($this->getid3->memory_limit / 2))), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
    12172
    12273                        $offset += $atomsize;
    … …  
    173124                $info = &$this->getid3->info;
    174125
    175                 //$atom_parent = array_pop($atomHierarchy);
    176                 $atom_parent = end($atomHierarchy); // http://www.getid3.org/phpBB3/viewtopic.php?t=1717
     126                $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see http://www.getid3.org/phpBB3/viewtopic.php?t=1717
    177127                array_push($atomHierarchy, $atomname);
    178128                $atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
    … …  
    180130                $atom_structure['size']      = $atomsize;
    181131                $atom_structure['offset']    = $baseoffset;
    182 //echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8)).'<br>';
    183 //echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8), false).'<br><br>';
    184132                switch ($atomname) {
    185133                        case 'moov': // MOVie container atom
    … …  
    201149
    202150                        case 'ilst': // Item LiST container atom
    203                                 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
    204 
    205                                 // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted
    206                                 $allnumericnames = true;
    207                                 foreach ($atom_structure['subatoms'] as $subatomarray) {
    208                                         if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) {
    209                                                 $allnumericnames = false;
    210                                                 break;
    211                                         }
    212                                 }
    213                                 if ($allnumericnames) {
    214                                         $newData = array();
     151                                if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) {
     152                                        // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted
     153                                        $allnumericnames = true;
    215154                                        foreach ($atom_structure['subatoms'] as $subatomarray) {
    216                                                 foreach ($subatomarray['subatoms'] as $newData_subatomarray) {
    217                                                         unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']);
    218                                                         $newData[$subatomarray['name']] = $newData_subatomarray;
     155                                                if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) {
     156                                                        $allnumericnames = false;
    219157                                                        break;
    220158                                                }
    221159                                        }
    222                                         $atom_structure['data'] = $newData;
    223                                         unset($atom_structure['subatoms']);
     160                                        if ($allnumericnames) {
     161                                                $newData = array();
     162                                                foreach ($atom_structure['subatoms'] as $subatomarray) {
     163                                                        foreach ($subatomarray['subatoms'] as $newData_subatomarray) {
     164                                                                unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']);
     165                                                                $newData[$subatomarray['name']] = $newData_subatomarray;
     166                                                                break;
     167                                                        }
     168                                                }
     169                                                $atom_structure['data'] = $newData;
     170                                                unset($atom_structure['subatoms']);
     171                                        }
    224172                                }
    225173                                break;
    … …  
    309257                        case 'plID':
    310258                        case 'sfID': // iTunes store country
    311                         case '©alb': // ALBum
    312                         case '©art': // ARTist
    313                         case '©ART':
    314                         case '©aut':
    315                         case '©cmt': // CoMmenT
    316                         case '©com': // COMposer
    317                         case '©cpy':
    318                         case '©day': // content created year
    319                         case '©dir':
    320                         case '©ed1':
    321                         case '©ed2':
    322                         case '©ed3':
    323                         case '©ed4':
    324                         case '©ed5':
    325                         case '©ed6':
    326                         case '©ed7':
    327                         case '©ed8':
    328                         case '©ed9':
    329                         case '©enc':
    330                         case '©fmt':
    331                         case '©gen': // GENre
    332                         case '©grp': // GRouPing
    333                         case '©hst':
    334                         case '©inf':
    335                         case '©lyr': // LYRics
    336                         case '©mak':
    337                         case '©mod':
    338                         case '©nam': // full NAMe
    339                         case '©ope':
    340                         case '©PRD':
    341                         case '©prd':
    342                         case '©prf':
    343                         case '©req':
    344                         case '©src':
    345                         case '©swr':
    346                         case '©too': // encoder
    347                         case '©trk': // TRacK
    348                         case '©url':
    349                         case '©wrn':
    350                         case '©wrt': // WRiTer
     259                        case "\xA9".'alb': // ALBum
     260                        case "\xA9".'art': // ARTist
     261                        case "\xA9".'ART':
     262                        case "\xA9".'aut':
     263                        case "\xA9".'cmt': // CoMmenT
     264                        case "\xA9".'com': // COMposer
     265                        case "\xA9".'cpy':
     266                        case "\xA9".'day': // content created year
     267                        case "\xA9".'dir':
     268                        case "\xA9".'ed1':
     269                        case "\xA9".'ed2':
     270                        case "\xA9".'ed3':
     271                        case "\xA9".'ed4':
     272                        case "\xA9".'ed5':
     273                        case "\xA9".'ed6':
     274                        case "\xA9".'ed7':
     275                        case "\xA9".'ed8':
     276                        case "\xA9".'ed9':
     277                        case "\xA9".'enc':
     278                        case "\xA9".'fmt':
     279                        case "\xA9".'gen': // GENre
     280                        case "\xA9".'grp': // GRouPing
     281                        case "\xA9".'hst':
     282                        case "\xA9".'inf':
     283                        case "\xA9".'lyr': // LYRics
     284                        case "\xA9".'mak':
     285                        case "\xA9".'mod':
     286                        case "\xA9".'nam': // full NAMe
     287                        case "\xA9".'ope':
     288                        case "\xA9".'PRD':
     289                        case "\xA9".'prd':
     290                        case "\xA9".'prf':
     291                        case "\xA9".'req':
     292                        case "\xA9".'src':
     293                        case "\xA9".'swr':
     294                        case "\xA9".'too': // encoder
     295                        case "\xA9".'trk': // TRacK
     296                        case "\xA9".'url':
     297                        case "\xA9".'wrn':
     298                        case "\xA9".'wrt': // WRiTer
    351299                        case '----': // itunes specific
    352300                                if ($atom_parent == 'udta') {
    … …  
    371319                                                        $boxsmalldata =                           substr($atom_data, $atomoffset + 4, $boxsmallsize);
    372320                                                        if ($boxsmallsize <= 1) {
    373                                                                 $info['warning'][] = 'Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.$atomname.'" at offset: '.($atom_structure['offset'] + $atomoffset);
     321                                                                $info['warning'][] = 'Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset);
    374322                                                                $atom_structure['data'] = null;
    375323                                                                $atomoffset = strlen($atom_data);
    … …  
    381329                                                                        break;
    382330                                                                default:
    383                                                                         $info['warning'][] = 'Unknown QuickTime smallbox type: "'.getid3_lib::PrintHexBytes($boxsmalltype).'" at offset '.$baseoffset;
     331                                                                        $info['warning'][] = 'Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset;
    384332                                                                        $atom_structure['data'] = $atom_data;
    385333                                                                        break;
    … …  
    393341                                                        $boxdata =                           substr($atom_data, $atomoffset + 8, $boxsize - 8);
    394342                                                        if ($boxsize <= 1) {
    395                                                                 $info['warning'][] = 'Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.$atomname.'" at offset: '.($atom_structure['offset'] + $atomoffset);
     343                                                                $info['warning'][] = 'Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset);
    396344                                                                $atom_structure['data'] = null;
    397345                                                                $atomoffset = strlen($atom_data);
    … …  
    410358                                                                        $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata,  1, 3));
    411359                                                                        switch ($atom_structure['flags_raw']) {
    412                                                                                 case 0: // data flag
     360                                                                                case  0: // data flag
    413361                                                                                case 21: // tmpo/cpil flag
    414362                                                                                        switch ($atomname) {
    … …  
    461409                                                                                        break;
    462410
    463                                                                                 case 1: // text flag
     411                                                                                case  1: // text flag
    464412                                                                                case 13: // image flag
    465413                                                                                default:
    466414                                                                                        $atom_structure['data'] = substr($boxdata, 8);
     415                                                                                        if ($atomname == 'covr') {
     416                                                                                                // not a foolproof check, but better than nothing
     417                                                                                                if (preg_match('#^\xFF\xD8\xFF#', $atom_structure['data'])) {
     418                                                                                                        $atom_structure['image_mime'] = 'image/jpeg';
     419                                                                                                } elseif (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $atom_structure['data'])) {
     420                                                                                                        $atom_structure['image_mime'] = 'image/png';
     421                                                                                                } elseif (preg_match('#^GIF#', $atom_structure['data'])) {
     422                                                                                                        $atom_structure['image_mime'] = 'image/gif';
     423                                                                                                }
     424                                                                                        }
    467425                                                                                        break;
    468426
    … …  
    471429
    472430                                                                default:
    473                                                                         $info['warning'][] = 'Unknown QuickTime box type: "'.getid3_lib::PrintHexBytes($boxtype).'" at offset '.$baseoffset;
     431                                                                        $info['warning'][] = 'Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset;
    474432                                                                        $atom_structure['data'] = $atom_data;
    475433
    … …  
    841799                                //$FrameRateCalculatorArray = array();
    842800                                $frames_count = 0;
    843                                 for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
     801
     802                                $max_stts_entries_to_scan = min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']);
     803                                if ($max_stts_entries_to_scan < $atom_structure['number_entries']) {
     804                                        $info['warning'][] = 'QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($this->getid3->memory_limit / 1048576).'MB).';
     805                                }
     806                                for ($i = 0; $i < $max_stts_entries_to_scan; $i++) {
    844807                                        $atom_structure['time_to_sample_table'][$i]['sample_count']    = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
    845808                                        $sttsEntriesDataOffset += 4;
    … …  
    10871050                        case 'scpt': // tranSCriPT atom
    10881051                        case 'ssrc': // non-primary SouRCe atom
    1089                                 for ($i = 0; $i < (strlen($atom_data) % 4); $i++) {
    1090                                         $atom_structure['track_id'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $i * 4, 4));
     1052                                for ($i = 0; $i < strlen($atom_data); $i += 4) {
     1053                                        @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
    10911054                                }
    10921055                                break;
    … …  
    12611224
    12621225                        case 'mdat': // Media DATa atom
     1226                                // 'mdat' contains the actual data for the audio/video, possibly also subtitles
     1227
     1228/* due to lack of known documentation, this is a kludge implementation. If you know of documentation on how mdat is properly structed, please send it to info@getid3.org */
     1229
     1230                                // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?)
     1231                                $mdat_offset = 0;
     1232                                while (true) {
     1233                                        if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') {
     1234                                                $mdat_offset += 8;
     1235                                        } elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') {
     1236                                                $mdat_offset += 8;
     1237                                        } else {
     1238                                                break;
     1239                                        }
     1240                                }
     1241
     1242                                // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field
     1243                                while  (($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2)))
     1244                                        && ($chapter_string_length < 1000)
     1245                                        && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2))
     1246                                        && preg_match('#^[\x20-\xFF]+$#', substr($atom_data, $mdat_offset + 2, $chapter_string_length), $chapter_matches)) {
     1247                                                $mdat_offset += (2 + $chapter_string_length);
     1248                                                @$info['quicktime']['comments']['chapters'][] = $chapter_matches[0];
     1249                                }
     1250
     1251
     1252
     1253                                if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
     1254
     1255                                        $info['avdataoffset'] = $atom_structure['offset'] + 8;                       // $info['quicktime'][$atomname]['offset'] + 8;
     1256                                        $OldAVDataEnd         = $info['avdataend'];
     1257                                        $info['avdataend']    = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
     1258
     1259                                        $getid3_temp = new getID3();
     1260                                        $getid3_temp->openfile($this->getid3->filename);
     1261                                        $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
     1262                                        $getid3_temp->info['avdataend']    = $info['avdataend'];
     1263                                        $getid3_mp3 = new getid3_mp3($getid3_temp);
     1264                                        if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) {
     1265                                                $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
     1266                                                if (!empty($getid3_temp->info['warning'])) {
     1267                                                        foreach ($getid3_temp->info['warning'] as $value) {
     1268                                                                $info['warning'][] = $value;
     1269                                                        }
     1270                                                }
     1271                                                if (!empty($getid3_temp->info['mpeg'])) {
     1272                                                        $info['mpeg'] = $getid3_temp->info['mpeg'];
     1273                                                        if (isset($info['mpeg']['audio'])) {
     1274                                                                $info['audio']['dataformat']   = 'mp3';
     1275                                                                $info['audio']['codec']        = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3')));
     1276                                                                $info['audio']['sample_rate']  = $info['mpeg']['audio']['sample_rate'];
     1277                                                                $info['audio']['channels']     = $info['mpeg']['audio']['channels'];
     1278                                                                $info['audio']['bitrate']      = $info['mpeg']['audio']['bitrate'];
     1279                                                                $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
     1280                                                                $info['bitrate']               = $info['audio']['bitrate'];
     1281                                                        }
     1282                                                }
     1283                                        }
     1284                                        unset($getid3_mp3, $getid3_temp);
     1285                                        $info['avdataend'] = $OldAVDataEnd;
     1286                                        unset($OldAVDataEnd);
     1287
     1288                                }
     1289
     1290                                unset($mdat_offset, $chapter_string_length, $chapter_matches);
     1291                                break;
     1292
    12631293                        case 'free': // FREE space atom
    12641294                        case 'skip': // SKIP atom
    12651295                        case 'wide': // 64-bit expansion placeholder atom
    1266                                 // 'mdat' data is too big to deal with, contains no useful metadata
    12671296                                // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
    12681297
    … …  
    13301359                                break;
    13311360
    1332                         case '©xyz':  // GPS latitude+longitude+altitude
     1361                        case "\xA9".'xyz':  // GPS latitude+longitude+altitude
    13331362                                $atom_structure['data'] = $atom_data;
    13341363                                if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) {
    … …  
    13591388                                }
    13601389                                break;
    1361                         case 'NCHD': // MakerNoteVersion
    1362                                 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
    1363                                 $atom_structure['data'] = $atom_data;
    1364                                 break;
    1365                         case 'NCTG': // NikonTags
    1366                                 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
     1390                        case 'NCTG': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
    13671391                                $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data);
    13681392                                break;
    1369                         case 'NCDB': // NikonTags
    1370                                 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
     1393                        case 'NCHD': // Nikon:MakerNoteVersion  - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
     1394                        case 'NCDB': // Nikon                   - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
     1395                        case 'CNCV': // Canon:CompressorVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html
    13711396                                $atom_structure['data'] = $atom_data;
    13721397                                break;
    … …  
    13941419
    13951420                        default:
    1396                                 $info['warning'][] = 'Unknown QuickTime atom type: "'.$atomname.'" ('.trim(getid3_lib::PrintHexBytes($atomname)).') at offset '.$baseoffset;
     1421                                $info['warning'][] = 'Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).') at offset '.$baseoffset;
    13971422                                $atom_structure['data'] = $atom_data;
    13981423                                break;
    … …  
    20892114                static $handyatomtranslatorarray = array();
    20902115                if (empty($handyatomtranslatorarray)) {
    2091                         $handyatomtranslatorarray['©cpy'] = 'copyright';
    2092                         $handyatomtranslatorarray['©day'] = 'creation_date';    // iTunes 4.0
    2093                         $handyatomtranslatorarray['©dir'] = 'director';
    2094                         $handyatomtranslatorarray['©ed1'] = 'edit1';
    2095                         $handyatomtranslatorarray['©ed2'] = 'edit2';
    2096                         $handyatomtranslatorarray['©ed3'] = 'edit3';
    2097                         $handyatomtranslatorarray['©ed4'] = 'edit4';
    2098                         $handyatomtranslatorarray['©ed5'] = 'edit5';
    2099                         $handyatomtranslatorarray['©ed6'] = 'edit6';
    2100                         $handyatomtranslatorarray['©ed7'] = 'edit7';
    2101                         $handyatomtranslatorarray['©ed8'] = 'edit8';
    2102                         $handyatomtranslatorarray['©ed9'] = 'edit9';
    2103                         $handyatomtranslatorarray['©fmt'] = 'format';
    2104                         $handyatomtranslatorarray['©inf'] = 'information';
    2105                         $handyatomtranslatorarray['©prd'] = 'producer';
    2106                         $handyatomtranslatorarray['©prf'] = 'performers';
    2107                         $handyatomtranslatorarray['©req'] = 'system_requirements';
    2108                         $handyatomtranslatorarray['©src'] = 'source_credit';
    2109                         $handyatomtranslatorarray['©wrt'] = 'writer';
     2116                        $handyatomtranslatorarray["\xA9".'cpy'] = 'copyright';
     2117                        $handyatomtranslatorarray["\xA9".'day'] = 'creation_date';    // iTunes 4.0
     2118                        $handyatomtranslatorarray["\xA9".'dir'] = 'director';
     2119                        $handyatomtranslatorarray["\xA9".'ed1'] = 'edit1';
     2120                        $handyatomtranslatorarray["\xA9".'ed2'] = 'edit2';
     2121                        $handyatomtranslatorarray["\xA9".'ed3'] = 'edit3';
     2122                        $handyatomtranslatorarray["\xA9".'ed4'] = 'edit4';
     2123                        $handyatomtranslatorarray["\xA9".'ed5'] = 'edit5';
     2124                        $handyatomtranslatorarray["\xA9".'ed6'] = 'edit6';
     2125                        $handyatomtranslatorarray["\xA9".'ed7'] = 'edit7';
     2126                        $handyatomtranslatorarray["\xA9".'ed8'] = 'edit8';
     2127                        $handyatomtranslatorarray["\xA9".'ed9'] = 'edit9';
     2128                        $handyatomtranslatorarray["\xA9".'fmt'] = 'format';
     2129                        $handyatomtranslatorarray["\xA9".'inf'] = 'information';
     2130                        $handyatomtranslatorarray["\xA9".'prd'] = 'producer';
     2131                        $handyatomtranslatorarray["\xA9".'prf'] = 'performers';
     2132                        $handyatomtranslatorarray["\xA9".'req'] = 'system_requirements';
     2133                        $handyatomtranslatorarray["\xA9".'src'] = 'source_credit';
     2134                        $handyatomtranslatorarray["\xA9".'wrt'] = 'writer';
    21102135
    21112136                        // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
    2112                         $handyatomtranslatorarray['©nam'] = 'title';           // iTunes 4.0
    2113                         $handyatomtranslatorarray['©cmt'] = 'comment';         // iTunes 4.0
    2114                         $handyatomtranslatorarray['©wrn'] = 'warning';
    2115                         $handyatomtranslatorarray['©hst'] = 'host_computer';
    2116                         $handyatomtranslatorarray['©mak'] = 'make';
    2117                         $handyatomtranslatorarray['©mod'] = 'model';
    2118                         $handyatomtranslatorarray['©PRD'] = 'product';
    2119                         $handyatomtranslatorarray['©swr'] = 'software';
    2120                         $handyatomtranslatorarray['©aut'] = 'author';
    2121                         $handyatomtranslatorarray['©ART'] = 'artist';
    2122                         $handyatomtranslatorarray['©trk'] = 'track';
    2123                         $handyatomtranslatorarray['©alb'] = 'album';           // iTunes 4.0
    2124                         $handyatomtranslatorarray['©com'] = 'comment';
    2125                         $handyatomtranslatorarray['©gen'] = 'genre';           // iTunes 4.0
    2126                         $handyatomtranslatorarray['©ope'] = 'composer';
    2127                         $handyatomtranslatorarray['©url'] = 'url';
    2128                         $handyatomtranslatorarray['©enc'] = 'encoder';
     2137                        $handyatomtranslatorarray["\xA9".'nam'] = 'title';           // iTunes 4.0
     2138                        $handyatomtranslatorarray["\xA9".'cmt'] = 'comment';         // iTunes 4.0
     2139                        $handyatomtranslatorarray["\xA9".'wrn'] = 'warning';
     2140                        $handyatomtranslatorarray["\xA9".'hst'] = 'host_computer';
     2141                        $handyatomtranslatorarray["\xA9".'mak'] = 'make';
     2142                        $handyatomtranslatorarray["\xA9".'mod'] = 'model';
     2143                        $handyatomtranslatorarray["\xA9".'PRD'] = 'product';
     2144                        $handyatomtranslatorarray["\xA9".'swr'] = 'software';
     2145                        $handyatomtranslatorarray["\xA9".'aut'] = 'author';
     2146                        $handyatomtranslatorarray["\xA9".'ART'] = 'artist';
     2147                        $handyatomtranslatorarray["\xA9".'trk'] = 'track';
     2148                        $handyatomtranslatorarray["\xA9".'alb'] = 'album';           // iTunes 4.0
     2149                        $handyatomtranslatorarray["\xA9".'com'] = 'comment';
     2150                        $handyatomtranslatorarray["\xA9".'gen'] = 'genre';           // iTunes 4.0
     2151                        $handyatomtranslatorarray["\xA9".'ope'] = 'composer';
     2152                        $handyatomtranslatorarray["\xA9".'url'] = 'url';
     2153                        $handyatomtranslatorarray["\xA9".'enc'] = 'encoder';
    21292154
    21302155                        // http://atomicparsley.sourceforge.net/mpeg-4files.html
    2131                         $handyatomtranslatorarray['©art'] = 'artist';           // iTunes 4.0
     2156                        $handyatomtranslatorarray["\xA9".'art'] = 'artist';           // iTunes 4.0
    21322157                        $handyatomtranslatorarray['aART'] = 'album_artist';
    21332158                        $handyatomtranslatorarray['trkn'] = 'track_number';     // iTunes 4.0
    21342159                        $handyatomtranslatorarray['disk'] = 'disc_number';      // iTunes 4.0
    21352160                        $handyatomtranslatorarray['gnre'] = 'genre';            // iTunes 4.0
    2136                         $handyatomtranslatorarray['©too'] = 'encoder';          // iTunes 4.0
     2161                        $handyatomtranslatorarray["\xA9".'too'] = 'encoder';          // iTunes 4.0
    21372162                        $handyatomtranslatorarray['tmpo'] = 'bpm';              // iTunes 4.0
    21382163                        $handyatomtranslatorarray['cprt'] = 'copyright';        // iTunes 4.0?
    … …  
    21402165                        $handyatomtranslatorarray['covr'] = 'picture';          // iTunes 4.0
    21412166                        $handyatomtranslatorarray['rtng'] = 'rating';           // iTunes 4.0
    2142                         $handyatomtranslatorarray['©grp'] = 'grouping';         // iTunes 4.2
     2167                        $handyatomtranslatorarray["\xA9".'grp'] = 'grouping';         // iTunes 4.2
    21432168                        $handyatomtranslatorarray['stik'] = 'stik';             // iTunes 4.9
    21442169                        $handyatomtranslatorarray['pcst'] = 'podcast';          // iTunes 4.9
    … …  
    21482173                        $handyatomtranslatorarray['egid'] = 'episode_guid';     // iTunes 4.9
    21492174                        $handyatomtranslatorarray['desc'] = 'description';      // iTunes 5.0
    2150                         $handyatomtranslatorarray['©lyr'] = 'lyrics';           // iTunes 5.0
     2175                        $handyatomtranslatorarray["\xA9".'lyr'] = 'lyrics';           // iTunes 5.0
    21512176                        $handyatomtranslatorarray['tvnn'] = 'tv_network_name';  // iTunes 6.0
    21522177                        $handyatomtranslatorarray['tvsh'] = 'tv_show_name';     // iTunes 6.0
  • trunk/src/wp-includes/ID3/module.audio-video.riff.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    2728getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, true);
    2829
    29 class getid3_riff extends getid3_handler
    30 {
     30class getid3_riff extends getid3_handler {
     31
     32        protected $container = 'riff'; // default
    3133
    3234        public function Analyze() {
    … …  
    5961
    6062                        case 'FORM':  // AIFF, AIFC
    61                                 $info['fileformat']   = 'aiff';
     63                                //$info['fileformat']   = 'aiff';
     64                                $this->container = 'aiff';
    6265                                $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
    6366                                $thisfile_riff[$RIFFsubtype]  = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
    … …  
    6770                        case 'SDSS':  // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
    6871                        case 'RMP3':  // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
    69                                 $info['fileformat']   = 'riff';
     72                                //$info['fileformat']   = 'riff';
     73                                $this->container = 'riff';
    7074                                $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
    7175                                if ($RIFFsubtype == 'RMP3') {
    … …  
    7377                                        $RIFFsubtype = 'WAVE';
    7478                                }
    75                                 $thisfile_riff[$RIFFsubtype]  = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
     79                                if ($RIFFsubtype != 'AMV ') {
     80                                        // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
     81                                        // Handled separately in ParseRIFFAMV()
     82                                        $thisfile_riff[$RIFFsubtype]  = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
     83                                }
    7684                                if (($info['avdataend'] - $info['filesize']) == 1) {
    7785                                        // LiteWave appears to incorrectly *not* pad actual output file
    … …  
    111119
    112120                                        switch ($nextRIFFheaderID) {
    113 
    114121                                                case 'RIFF':
    115122                                                        $chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $nextRIFFoffset);
    116 
    117123                                                        if (!isset($thisfile_riff[$nextRIFFtype])) {
    118124                                                                $thisfile_riff[$nextRIFFtype] = array();
    119125                                                        }
    120126                                                        $thisfile_riff[$nextRIFFtype][] = $chunkdata;
     127                                                        break;
     128
     129                                                case 'AMV ':
     130                                                        unset($info['riff']);
     131                                                        $info['amv'] = $this->ParseRIFFAMV($chunkdata['offset'] + 4, $nextRIFFoffset);
    121132                                                        break;
    122133
    … …  
    153164                        default:
    154165                                $this->error('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead');
    155                                 unset($info['fileformat']);
     166                                //unset($info['fileformat']);
    156167                                return false;
    157168                }
    … …  
    159170                $streamindex = 0;
    160171                switch ($RIFFsubtype) {
     172
     173                        // http://en.wikipedia.org/wiki/Wav
    161174                        case 'WAVE':
     175                                $info['fileformat'] = 'wav';
     176
    162177                                if (empty($thisfile_audio['bitrate_mode'])) {
    163178                                        $thisfile_audio['bitrate_mode'] = 'cbr';
    … …  
    589604                                break;
    590605
     606                        // http://en.wikipedia.org/wiki/Audio_Video_Interleave
    591607                        case 'AVI ':
     608                                $info['fileformat'] = 'avi';
     609                                $info['mime_type']  = 'video/avi';
     610
    592611                                $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably
    593612                                $thisfile_video['dataformat']   = 'avi';
    594                                 $info['mime_type']      = 'video/avi';
    595613
    596614                                if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) {
    … …  
    826844                                                                                        switch ($strhfccType) {
    827845                                                                                                case 'vids':
    828                                                                                                         $thisfile_riff_raw_strf_strhfccType_streamindex = self::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($info['fileformat'] == 'riff'));
     846                                                                                                        $thisfile_riff_raw_strf_strhfccType_streamindex = self::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($this->container == 'riff'));
    829847                                                                                                        $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'];
    830848
    … …  
    876894                                break;
    877895
     896
     897                        case 'AMV ':
     898                                $info['fileformat'] = 'amv';
     899                                $info['mime_type']  = 'video/amv';
     900
     901                                $thisfile_video['bitrate_mode']    = 'vbr'; // it's MJPEG, presumably contant-quality encoding, thereby VBR
     902                                $thisfile_video['dataformat']      = 'mjpeg';
     903                                $thisfile_video['codec']           = 'mjpeg';
     904                                $thisfile_video['lossless']        = false;
     905                                $thisfile_video['bits_per_sample'] = 24;
     906
     907                                $thisfile_audio['dataformat']   = 'adpcm';
     908                                $thisfile_audio['lossless']     = false;
     909                                break;
     910
     911
     912                        // http://en.wikipedia.org/wiki/CD-DA
    878913                        case 'CDDA':
    879                                 $thisfile_audio['bitrate_mode'] = 'cbr';
     914                                $info['fileformat'] = 'cda';
     915                            unset($info['mime_type']);
     916
    880917                                $thisfile_audio_dataformat      = 'cda';
    881                                 $thisfile_audio['lossless']     = true;
    882                                 unset($info['mime_type']);
    883918
    884919                                $info['avdataoffset'] = 44;
    … …  
    902937
    903938                                        // hardcoded data for CD-audio
     939                                        $thisfile_audio['lossless']        = true;
    904940                                        $thisfile_audio['sample_rate']     = 44100;
    905941                                        $thisfile_audio['channels']        = 2;
    … …  
    910946                                break;
    911947
    912 
     948            // http://en.wikipedia.org/wiki/AIFF
    913949                        case 'AIFF':
    914950                        case 'AIFC':
     951                                $info['fileformat'] = 'aiff';
     952                                $info['mime_type']  = 'audio/x-aiff';
     953
    915954                                $thisfile_audio['bitrate_mode'] = 'cbr';
    916955                                $thisfile_audio_dataformat      = 'aiff';
    917956                                $thisfile_audio['lossless']     = true;
    918                                 $info['mime_type']      = 'audio/x-aiff';
    919957
    920958                                if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) {
    … …  
    10291067                                break;
    10301068
     1069                        // http://en.wikipedia.org/wiki/8SVX
    10311070                        case '8SVX':
     1071                                $info['fileformat'] = '8svx';
     1072                                $info['mime_type']  = 'audio/8svx';
     1073
    10321074                                $thisfile_audio['bitrate_mode']    = 'cbr';
    10331075                                $thisfile_audio_dataformat         = '8svx';
    10341076                                $thisfile_audio['bits_per_sample'] = 8;
    10351077                                $thisfile_audio['channels']        = 1; // overridden below, if need be
    1036                                 $info['mime_type']                = 'audio/x-aiff';
    10371078
    10381079                                if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) {
    … …  
    11091150                                break;
    11101151
    1111 
    11121152                        case 'CDXA':
    1113                                 $info['mime_type'] = 'video/mpeg';
     1153                                $info['fileformat'] = 'vcd'; // Asume Video CD
     1154                                $info['mime_type']  = 'video/mpeg';
     1155
    11141156                                if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) {
    1115                                         if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, false)) {
    1116                                                 $getid3_temp = new getID3();
    1117                                                 $getid3_temp->openfile($this->getid3->filename);
    1118                                                 $getid3_mpeg = new getid3_mpeg($getid3_temp);
    1119                                                 $getid3_mpeg->Analyze();
    1120                                                 if (empty($getid3_temp->info['error'])) {
    1121                                                         $info['audio']   = $getid3_temp->info['audio'];
    1122                                                         $info['video']   = $getid3_temp->info['video'];
    1123                                                         $info['mpeg']    = $getid3_temp->info['mpeg'];
    1124                                                         $info['warning'] = $getid3_temp->info['warning'];
    1125                                                 }
    1126                                                 unset($getid3_temp, $getid3_mpeg);
    1127                                         }
     1157                                        getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, true);
     1158
     1159                                        $getid3_temp = new getID3();
     1160                                        $getid3_temp->openfile($this->getid3->filename);
     1161                                        $getid3_mpeg = new getid3_mpeg($getid3_temp);
     1162                                        $getid3_mpeg->Analyze();
     1163                                        if (empty($getid3_temp->info['error'])) {
     1164                                                $info['audio']   = $getid3_temp->info['audio'];
     1165                                                $info['video']   = $getid3_temp->info['video'];
     1166                                                $info['mpeg']    = $getid3_temp->info['mpeg'];
     1167                                                $info['warning'] = $getid3_temp->info['warning'];
     1168                                        }
     1169                                        unset($getid3_temp, $getid3_mpeg);
    11281170                                }
    11291171                                break;
    … …  
    11321174                        default:
    11331175                                $info['error'][] = 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$RIFFsubtype.'" instead';
    1134                                 unset($info['fileformat']);
    1135                                 break;
     1176                                //unset($info['fileformat']);
    11361177                }
    11371178
    … …  
    11511192                                if (isset($thisfile_riff[$RIFFsubtype]['id3 '])) {
    11521193                                        getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
     1194
    11531195                                        $getid3_temp = new getID3();
    11541196                                        $getid3_temp->openfile($this->getid3->filename);
    … …  
    12791321        }
    12801322
     1323        public function ParseRIFFAMV($startoffset, $maxoffset) {
     1324                // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
     1325
     1326                // https://code.google.com/p/amv-codec-tools/wiki/AmvDocumentation
     1327                //typedef struct _amvmainheader {
     1328                //FOURCC fcc; // 'amvh'
     1329                //DWORD cb;
     1330                //DWORD dwMicroSecPerFrame;
     1331                //BYTE reserve[28];
     1332                //DWORD dwWidth;
     1333                //DWORD dwHeight;
     1334                //DWORD dwSpeed;
     1335                //DWORD reserve0;
     1336                //DWORD reserve1;
     1337                //BYTE bTimeSec;
     1338                //BYTE bTimeMin;
     1339                //WORD wTimeHour;
     1340                //} AMVMAINHEADER;
     1341
     1342                $info = &$this->getid3->info;
     1343                $RIFFchunk = false;
     1344
     1345                try {
     1346
     1347                        $this->fseek($startoffset);
     1348                        $maxoffset = min($maxoffset, $info['avdataend']);
     1349                        $AMVheader = $this->fread(284);
     1350                        if (substr($AMVheader,   0,  8) != 'hdrlamvh') {
     1351                                throw new Exception('expecting "hdrlamv" at offset '.($startoffset +   0).', found "'.substr($AMVheader,   0, 8).'"');
     1352                        }
     1353                        if (substr($AMVheader,   8,  4) != "\x38\x00\x00\x00") { // "amvh" chunk size, hardcoded to 0x38 = 56 bytes
     1354                                throw new Exception('expecting "0x38000000" at offset '.($startoffset +   8).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader,   8, 4)).'"');
     1355                        }
     1356                        $RIFFchunk = array();
     1357                        $RIFFchunk['amvh']['us_per_frame']   = getid3_lib::LittleEndian2Int(substr($AMVheader,  12,  4));
     1358                        $RIFFchunk['amvh']['reserved28']     =                              substr($AMVheader,  16, 28);  // null? reserved?
     1359                        $RIFFchunk['amvh']['resolution_x']   = getid3_lib::LittleEndian2Int(substr($AMVheader,  44,  4));
     1360                        $RIFFchunk['amvh']['resolution_y']   = getid3_lib::LittleEndian2Int(substr($AMVheader,  48,  4));
     1361                        $RIFFchunk['amvh']['frame_rate_int'] = getid3_lib::LittleEndian2Int(substr($AMVheader,  52,  4));
     1362                        $RIFFchunk['amvh']['reserved0']      = getid3_lib::LittleEndian2Int(substr($AMVheader,  56,  4)); // 1? reserved?
     1363                        $RIFFchunk['amvh']['reserved1']      = getid3_lib::LittleEndian2Int(substr($AMVheader,  60,  4)); // 0? reserved?
     1364                        $RIFFchunk['amvh']['runtime_sec']    = getid3_lib::LittleEndian2Int(substr($AMVheader,  64,  1));
     1365                        $RIFFchunk['amvh']['runtime_min']    = getid3_lib::LittleEndian2Int(substr($AMVheader,  65,  1));
     1366                        $RIFFchunk['amvh']['runtime_hrs']    = getid3_lib::LittleEndian2Int(substr($AMVheader,  66,  2));
     1367
     1368                        $info['video']['frame_rate']   = 1000000 / $RIFFchunk['amvh']['us_per_frame'];
     1369                        $info['video']['resolution_x'] = $RIFFchunk['amvh']['resolution_x'];
     1370                        $info['video']['resolution_y'] = $RIFFchunk['amvh']['resolution_y'];
     1371                        $info['playtime_seconds']      = ($RIFFchunk['amvh']['runtime_hrs'] * 3600) + ($RIFFchunk['amvh']['runtime_min'] * 60) + $RIFFchunk['amvh']['runtime_sec'];
     1372
     1373                        // the rest is all hardcoded(?) and does not appear to be useful until you get to audio info at offset 256, even then everything is probably hardcoded
     1374
     1375                        if (substr($AMVheader,  68, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x38\x00\x00\x00") {
     1376                                throw new Exception('expecting "LIST<0x00000000>strlstrh<0x38000000>" at offset '.($startoffset +  68).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader,  68, 20)).'"');
     1377                        }
     1378                        // followed by 56 bytes of null: substr($AMVheader,  88, 56) -> 144
     1379                        if (substr($AMVheader, 144,  8) != 'strf'."\x24\x00\x00\x00") {
     1380                                throw new Exception('expecting "strf<0x24000000>" at offset '.($startoffset + 144).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 144,  8)).'"');
     1381                        }
     1382                        // followed by 36 bytes of null: substr($AMVheader, 144, 36) -> 180
     1383
     1384                        if (substr($AMVheader, 188, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x30\x00\x00\x00") {
     1385                                throw new Exception('expecting "LIST<0x00000000>strlstrh<0x30000000>" at offset '.($startoffset + 188).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 188, 20)).'"');
     1386                        }
     1387                        // followed by 48 bytes of null: substr($AMVheader, 208, 48) -> 256
     1388                        if (substr($AMVheader, 256,  8) != 'strf'."\x14\x00\x00\x00") {
     1389                                throw new Exception('expecting "strf<0x14000000>" at offset '.($startoffset + 256).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 256,  8)).'"');
     1390                        }
     1391                        // followed by 20 bytes of a modified WAVEFORMATEX:
     1392                        // typedef struct {
     1393                        // WORD wFormatTag;       //(Fixme: this is equal to PCM's 0x01 format code)
     1394                        // WORD nChannels;        //(Fixme: this is always 1)
     1395                        // DWORD nSamplesPerSec;  //(Fixme: for all known sample files this is equal to 22050)
     1396                        // DWORD nAvgBytesPerSec; //(Fixme: for all known sample files this is equal to 44100)
     1397                        // WORD nBlockAlign;      //(Fixme: this seems to be 2 in AMV files, is this correct ?)
     1398                        // WORD wBitsPerSample;   //(Fixme: this seems to be 16 in AMV files instead of the expected 4)
     1399                        // WORD cbSize;           //(Fixme: this seems to be 0 in AMV files)
     1400                        // WORD reserved;
     1401                        // } WAVEFORMATEX;
     1402                        $RIFFchunk['strf']['wformattag']      = getid3_lib::LittleEndian2Int(substr($AMVheader,  264,  2));
     1403                        $RIFFchunk['strf']['nchannels']       = getid3_lib::LittleEndian2Int(substr($AMVheader,  266,  2));
     1404                        $RIFFchunk['strf']['nsamplespersec']  = getid3_lib::LittleEndian2Int(substr($AMVheader,  268,  4));
     1405                        $RIFFchunk['strf']['navgbytespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader,  272,  4));
     1406                        $RIFFchunk['strf']['nblockalign']     = getid3_lib::LittleEndian2Int(substr($AMVheader,  276,  2));
     1407                        $RIFFchunk['strf']['wbitspersample']  = getid3_lib::LittleEndian2Int(substr($AMVheader,  278,  2));
     1408                        $RIFFchunk['strf']['cbsize']          = getid3_lib::LittleEndian2Int(substr($AMVheader,  280,  2));
     1409                        $RIFFchunk['strf']['reserved']        = getid3_lib::LittleEndian2Int(substr($AMVheader,  282,  2));
     1410
     1411
     1412                        $info['audio']['lossless']        = false;
     1413                        $info['audio']['sample_rate']     = $RIFFchunk['strf']['nsamplespersec'];
     1414                        $info['audio']['channels']        = $RIFFchunk['strf']['nchannels'];
     1415                        $info['audio']['bits_per_sample'] = $RIFFchunk['strf']['wbitspersample'];
     1416                        $info['audio']['bitrate']         = $info['audio']['sample_rate'] * $info['audio']['channels'] * $info['audio']['bits_per_sample'];
     1417                        $info['audio']['bitrate_mode']    = 'cbr';
     1418
     1419
     1420                } catch (getid3_exception $e) {
     1421                        if ($e->getCode() == 10) {
     1422                                $this->warning('RIFFAMV parser: '.$e->getMessage());
     1423                        } else {
     1424                                throw $e;
     1425                        }
     1426                }
     1427
     1428                return $RIFFchunk;
     1429        }
     1430
     1431
    12811432        public function ParseRIFF($startoffset, $maxoffset) {
    12821433                $info = &$this->getid3->info;
    … …  
    13301481                                                                                        $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
    13311482                                                                                        $getid3_temp->info['avdataend']    = $this->ftell() + $AudioChunkSize;
    1332                                                                                         $getid3_mp3 = new getid3_mp3($getid3_temp);
     1483                                                                                        $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
    13331484                                                                                        $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
    13341485                                                                                        if (isset($getid3_temp->info['mpeg']['audio'])) {
    … …  
    14131564                                                                                $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
    14141565                                                                                $getid3_temp->info['avdataend']    = $info['avdataend'];
    1415                                                                                 $getid3_mp3 = new getid3_mp3($getid3_temp);
     1566                                                                                $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
    14161567                                                                                $getid3_mp3->getOnlyMPEGaudioInfo($info['avdataoffset'], false);
    14171568                                                                                if (empty($getid3_temp->info['error'])) {
    … …  
    24272578
    24282579        private function EitherEndian2Int($byteword, $signed=false) {
    2429                 if ($this->getid3->info['fileformat'] == 'riff') {
     2580                if ($this->container == 'riff') {
    24302581                        return getid3_lib::LittleEndian2Int($byteword, $signed);
    24312582                }
  • trunk/src/wp-includes/ID3/module.audio.ac3.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
  • trunk/src/wp-includes/ID3/module.audio.dts.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
  • trunk/src/wp-includes/ID3/module.audio.flac.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
  • trunk/src/wp-includes/ID3/module.audio.mp3.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    9697                        // Not sure what version of LAME this is - look in padding of last frame for longer version string
    9798                        $PossibleLAMEversionStringOffset = $info['avdataend'] - $PossiblyLongerLAMEversion_FrameLength;
    98                         fseek($this->getid3->fp, $PossibleLAMEversionStringOffset);
    99                         $PossiblyLongerLAMEversion_Data = fread($this->getid3->fp, $PossiblyLongerLAMEversion_FrameLength);
     99                        $this->fseek($PossibleLAMEversionStringOffset);
     100                        $PossiblyLongerLAMEversion_Data = $this->fread($PossiblyLongerLAMEversion_FrameLength);
    100101                        switch (substr($CurrentDataLAMEversionString, -1)) {
    101102                                case 'a':
    … …  
    423424                }
    424425
    425                 if (fseek($this->getid3->fp, $offset, SEEK_SET) != 0) {
     426                if ($this->fseek($offset) != 0) {
    426427                        $info['error'][] = 'decodeMPEGaudioHeader() failed to seek to next offset at '.$offset;
    427428                        return false;
    428429                }
    429                 //$headerstring = fread($this->getid3->fp, 1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame
    430                 $headerstring = fread($this->getid3->fp, 226); // LAME header at offset 36 + 190 bytes of Xing/LAME data
     430                //$headerstring = $this->fread(1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame
     431                $headerstring = $this->fread(226); // LAME header at offset 36 + 190 bytes of Xing/LAME data
    431432
    432433                // MP3 audio frame structure:
    … …  
    891892                if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($info['avdataend'] - $info['avdataoffset']))) {
    892893                        if ($ExpectedNumberOfAudioBytes > ($info['avdataend'] - $info['avdataoffset'])) {
    893                                 if (isset($info['fileformat']) && ($info['fileformat'] == 'riff')) {
     894                                if ($this->isDependencyFor('matroska') || $this->isDependencyFor('riff')) {
    894895                                        // ignore, audio data is broken into chunks so will always be data "missing"
    895                                 } elseif (($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])) == 1) {
    896                                         $info['warning'][] = 'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)';
    897                                 } else {
    898                                         $info['warning'][] = 'Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])).' bytes)';
     896                                }
     897                                elseif (($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])) == 1) {
     898                                        $this->warning('Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)');
     899                                }
     900                                else {
     901                                        $this->warning('Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])).' bytes)');
    899902                                }
    900903                        } else {
    901904                                if ((($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) {
    902                                 //      $prenullbytefileoffset = ftell($this->getid3->fp);
    903                                 //      fseek($this->getid3->fp, $info['avdataend'], SEEK_SET);
    904                                 //      $PossibleNullByte = fread($this->getid3->fp, 1);
    905                                 //      fseek($this->getid3->fp, $prenullbytefileoffset, SEEK_SET);
     905                                //      $prenullbytefileoffset = $this->ftell();
     906                                //      $this->fseek($info['avdataend']);
     907                                //      $PossibleNullByte = $this->fread(1);
     908                                //      $this->fseek($prenullbytefileoffset);
    906909                                //      if ($PossibleNullByte === "\x00") {
    907910                                                $info['avdataend']--;
    … …  
    11191122                $info = &$this->getid3->info;
    11201123
    1121                 fseek($this->getid3->fp, $offset, SEEK_SET);
    1122                 $MPEGaudioData = fread($this->getid3->fp, 32768);
     1124                $this->fseek($offset);
     1125                $MPEGaudioData = $this->fread(32768);
    11231126
    11241127                $SyncPattern1 = substr($MPEGaudioData, 0, 4);
    … …  
    11671170                        $nextoffset = $offset + $framelength;
    11681171                        while ($nextoffset < ($info['avdataend'] - 6)) {
    1169                                 fseek($this->getid3->fp, $nextoffset - 1, SEEK_SET);
    1170                                 $NextSyncPattern = fread($this->getid3->fp, 6);
     1172                                $this->fseek($nextoffset - 1);
     1173                                $NextSyncPattern = $this->fread(6);
    11711174                                if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) {
    11721175                                        // good - found where expected
    … …  
    12161219
    12171220                $info = &$this->getid3->info;
    1218                 fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
     1221                $this->fseek($info['avdataoffset']);
    12191222
    12201223                $max_frames_scan = 5000;
    … …  
    12221225
    12231226                $previousvalidframe = $info['avdataoffset'];
    1224                 while (ftell($this->getid3->fp) < $info['avdataend']) {
     1227                while ($this->ftell() < $info['avdataend']) {
    12251228                        set_time_limit(30);
    1226                         $head4 = fread($this->getid3->fp, 4);
     1229                        $head4 = $this->fread(4);
    12271230                        if (strlen($head4) < 4) {
    12281231                                break;
    … …  
    12311234                                for ($i = 1; $i < 4; $i++) {
    12321235                                        if ($head4{$i} == "\xFF") {
    1233                                                 fseek($this->getid3->fp, $i - 4, SEEK_CUR);
     1236                                                $this->fseek($i - 4, SEEK_CUR);
    12341237                                                continue 2;
    12351238                                        }
    … …  
    12591262                                }
    12601263                                if ($MPEGaudioHeaderLengthCache[$head4] > 4) {
    1261                                         $WhereWeWere = ftell($this->getid3->fp);
    1262                                         fseek($this->getid3->fp, $MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR);
    1263                                         $next4 = fread($this->getid3->fp, 4);
     1264                                        $WhereWeWere = $this->ftell();
     1265                                        $this->fseek($MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR);
     1266                                        $next4 = $this->fread(4);
    12641267                                        if ($next4{0} == "\xFF") {
    12651268                                                if (!isset($MPEGaudioHeaderDecodeCache[$next4])) {
    … …  
    12701273                                                }
    12711274                                                if ($MPEGaudioHeaderValidCache[$next4]) {
    1272                                                         fseek($this->getid3->fp, -4, SEEK_CUR);
     1275                                                        $this->fseek(-4, SEEK_CUR);
    12731276
    12741277                                                        getid3_lib::safe_inc($Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]]);
    … …  
    12781281                                                        getid3_lib::safe_inc($Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]]);
    12791282                                                        if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) {
    1280                                                                 $pct_data_scanned = (ftell($this->getid3->fp) - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']);
     1283                                                                $pct_data_scanned = ($this->ftell() - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']);
    12811284                                                                $info['warning'][] = 'too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
    12821285                                                                foreach ($Distribution as $key1 => $value1) {
    … …  
    12911294                                        }
    12921295                                        unset($next4);
    1293                                         fseek($this->getid3->fp, $WhereWeWere - 3, SEEK_SET);
     1296                                        $this->fseek($WhereWeWere - 3);
    12941297                                }
    12951298
    … …  
    13561359                }
    13571360
    1358                 fseek($this->getid3->fp, $avdataoffset, SEEK_SET);
     1361                $this->fseek($avdataoffset);
    13591362                $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdataoffset);
    13601363                if ($sync_seek_buffer_size <= 0) {
    … …  
    13621365                        return false;
    13631366                }
    1364                 $header = fread($this->getid3->fp, $sync_seek_buffer_size);
     1367                $header = $this->fread($sync_seek_buffer_size);
    13651368                $sync_seek_buffer_size = strlen($header);
    13661369                $SynchSeekOffset = 0;
    … …  
    14741477                                                $dummy = array('error'=>$info['error'], 'warning'=>$info['warning'], 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
    14751478                                                $synchstartoffset = $info['avdataoffset'];
    1476                                                 fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
     1479                                                $this->fseek($info['avdataoffset']);
    14771480
    14781481                                                // you can play with these numbers:
    … …  
    14891492                                                for ($current_segment = 0; $current_segment < $max_scan_segments; $current_segment++) {
    14901493                                                        $frames_scanned_this_segment = 0;
    1491                                                         if (ftell($this->getid3->fp) >= $info['avdataend']) {
     1494                                                        if ($this->ftell() >= $info['avdataend']) {
    14921495                                                                break;
    14931496                                                        }
    1494                                                         $scan_start_offset[$current_segment] = max(ftell($this->getid3->fp), $info['avdataoffset'] + round($current_segment * (($info['avdataend'] - $info['avdataoffset']) / $max_scan_segments)));
     1497                                                        $scan_start_offset[$current_segment] = max($this->ftell(), $info['avdataoffset'] + round($current_segment * (($info['avdataend'] - $info['avdataoffset']) / $max_scan_segments)));
    14951498                                                        if ($current_segment > 0) {
    1496                                                                 fseek($this->getid3->fp, $scan_start_offset[$current_segment], SEEK_SET);
    1497                                                                 $buffer_4k = fread($this->getid3->fp, 4096);
     1499                                                                $this->fseek($scan_start_offset[$current_segment]);
     1500                                                                $buffer_4k = $this->fread(4096);
    14981501                                                                for ($j = 0; $j < (strlen($buffer_4k) - 4); $j++) {
    14991502                                                                        if (($buffer_4k{$j} == "\xFF") && ($buffer_4k{($j + 1)} > "\xE0")) { // synch detected
    … …  
    15241527                                                                $frames_scanned++;
    15251528                                                                if ($frames_scan_per_segment && (++$frames_scanned_this_segment >= $frames_scan_per_segment)) {
    1526                                                                         $this_pct_scanned = (ftell($this->getid3->fp) - $scan_start_offset[$current_segment]) / ($info['avdataend'] - $info['avdataoffset']);
     1529                                                                        $this_pct_scanned = ($this->ftell() - $scan_start_offset[$current_segment]) / ($info['avdataend'] - $info['avdataoffset']);
    15271530                                                                        if (($current_segment == 0) && (($this_pct_scanned * $max_scan_segments) >= 1)) {
    15281531                                                                                // file likely contains < $max_frames_scan, just scan as one segment
  • trunk/src/wp-includes/ID3/module.audio.ogg.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    114115                                $info['audio']['bitrate_mode'] = 'vbr';
    115116                        }
     117
     118                } elseif (substr($filedata, 0, 7) == "\x80".'theora') {
     119
     120                        // http://www.theora.org/doc/Theora.pdf (section 6.2)
     121
     122                        $info['ogg']['pageheader']['theora']['theora_magic']             =                           substr($filedata, $filedataoffset,  7); // hard-coded to "\x80.'theora'
     123                        $filedataoffset += 7;
     124                        $info['ogg']['pageheader']['theora']['version_major']            = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
     125                        $filedataoffset += 1;
     126                        $info['ogg']['pageheader']['theora']['version_minor']            = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
     127                        $filedataoffset += 1;
     128                        $info['ogg']['pageheader']['theora']['version_revision']         = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
     129                        $filedataoffset += 1;
     130                        $info['ogg']['pageheader']['theora']['frame_width_macroblocks']  = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  2));
     131                        $filedataoffset += 2;
     132                        $info['ogg']['pageheader']['theora']['frame_height_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  2));
     133                        $filedataoffset += 2;
     134                        $info['ogg']['pageheader']['theora']['resolution_x']             = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
     135                        $filedataoffset += 3;
     136                        $info['ogg']['pageheader']['theora']['resolution_y']             = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
     137                        $filedataoffset += 3;
     138                        $info['ogg']['pageheader']['theora']['picture_offset_x']         = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
     139                        $filedataoffset += 1;
     140                        $info['ogg']['pageheader']['theora']['picture_offset_y']         = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
     141                        $filedataoffset += 1;
     142                        $info['ogg']['pageheader']['theora']['frame_rate_numerator']     = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  4));
     143                        $filedataoffset += 4;
     144                        $info['ogg']['pageheader']['theora']['frame_rate_denominator']   = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  4));
     145                        $filedataoffset += 4;
     146                        $info['ogg']['pageheader']['theora']['pixel_aspect_numerator']   = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
     147                        $filedataoffset += 3;
     148                        $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
     149                        $filedataoffset += 3;
     150                        $info['ogg']['pageheader']['theora']['color_space_id']           = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
     151                        $filedataoffset += 1;
     152                        $info['ogg']['pageheader']['theora']['nominal_bitrate']          = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
     153                        $filedataoffset += 3;
     154                        $info['ogg']['pageheader']['theora']['flags']                    = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  2));
     155                        $filedataoffset += 2;
     156
     157                        $info['ogg']['pageheader']['theora']['quality']         = ($info['ogg']['pageheader']['theora']['flags'] & 0xFC00) >> 10;
     158                        $info['ogg']['pageheader']['theora']['kfg_shift']       = ($info['ogg']['pageheader']['theora']['flags'] & 0x03E0) >>  5;
     159                        $info['ogg']['pageheader']['theora']['pixel_format_id'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0018) >>  3;
     160                        $info['ogg']['pageheader']['theora']['reserved']        = ($info['ogg']['pageheader']['theora']['flags'] & 0x0007) >>  0; // should be 0
     161                        $info['ogg']['pageheader']['theora']['color_space']     = self::TheoraColorSpace($info['ogg']['pageheader']['theora']['color_space_id']);
     162                        $info['ogg']['pageheader']['theora']['pixel_format']    = self::TheoraPixelFormat($info['ogg']['pageheader']['theora']['pixel_format_id']);
     163
     164                        $info['video']['dataformat']   = 'theora';
     165                        $info['mime_type']             = 'video/ogg';
     166                        //$info['audio']['bitrate_mode'] = 'abr';
     167                        //$info['audio']['lossless']     = false;
     168                        $info['video']['resolution_x'] = $info['ogg']['pageheader']['theora']['resolution_x'];
     169                        $info['video']['resolution_y'] = $info['ogg']['pageheader']['theora']['resolution_y'];
     170                        if ($info['ogg']['pageheader']['theora']['frame_rate_denominator'] > 0) {
     171                                $info['video']['frame_rate'] = (float) $info['ogg']['pageheader']['theora']['frame_rate_numerator'] / $info['ogg']['pageheader']['theora']['frame_rate_denominator'];
     172                        }
     173                        if ($info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] > 0) {
     174                                $info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'];
     175                        }
     176$info['warning'][] = 'Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable';
    116177
    117178
    … …  
    173234                                } elseif (substr($filedata, 1, 6) == 'theora') {
    174235
    175                                         $info['video']['dataformat'] = 'theora';
    176                                         $info['error'][] = 'Ogg Theora not correctly handled in this version of getID3 ['.$this->getid3->version().']';
     236                                        $info['video']['dataformat'] = 'theora1';
     237                                        $info['error'][] = 'Ogg Theora (v1) not correctly handled in this version of getID3 ['.$this->getid3->version().']';
    177238                                        //break;
    178239
    … …  
    669730        }
    670731
     732        public static function TheoraColorSpace($colorspace_id) {
     733                // http://www.theora.org/doc/Theora.pdf (table 6.3)
     734                static $TheoraColorSpaceLookup = array();
     735                if (empty($TheoraColorSpaceLookup)) {
     736                        $TheoraColorSpaceLookup[0] = 'Undefined';
     737                        $TheoraColorSpaceLookup[1] = 'Rec. 470M';
     738                        $TheoraColorSpaceLookup[2] = 'Rec. 470BG';
     739                        $TheoraColorSpaceLookup[3] = 'Reserved';
     740                }
     741                return (isset($TheoraColorSpaceLookup[$colorspace_id]) ? $TheoraColorSpaceLookup[$colorspace_id] : null);
     742        }
     743
     744        public static function TheoraPixelFormat($pixelformat_id) {
     745                // http://www.theora.org/doc/Theora.pdf (table 6.4)
     746                static $TheoraPixelFormatLookup = array();
     747                if (empty($TheoraPixelFormatLookup)) {
     748                        $TheoraPixelFormatLookup[0] = '4:2:0';
     749                        $TheoraPixelFormatLookup[1] = 'Reserved';
     750                        $TheoraPixelFormatLookup[2] = '4:2:2';
     751                        $TheoraPixelFormatLookup[3] = '4:4:4';
     752                }
     753                return (isset($TheoraPixelFormatLookup[$pixelformat_id]) ? $TheoraPixelFormatLookup[$pixelformat_id] : null);
     754        }
     755
    671756}
  • trunk/src/wp-includes/ID3/module.tag.apetag.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    3334                if ($this->overrideendoffset == 0) {
    3435
    35                         fseek($this->getid3->fp, 0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
    36                         $APEfooterID3v1 = fread($this->getid3->fp, $id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
     36                        $this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
     37                        $APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
    3738
    3839                        //if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
    … …  
    5253                } else {
    5354
    54                         fseek($this->getid3->fp, $this->overrideendoffset - $apetagheadersize, SEEK_SET);
    55                         if (fread($this->getid3->fp, 8) == 'APETAGEX') {
     55                        $this->fseek($this->overrideendoffset - $apetagheadersize);
     56                        if ($this->fread(8) == 'APETAGEX') {
    5657                                $info['ape']['tag_offset_end'] = $this->overrideendoffset;
    5758                        }
    … …  
    6970                $thisfile_ape = &$info['ape'];
    7071
    71                 fseek($this->getid3->fp, $thisfile_ape['tag_offset_end'] - $apetagheadersize, SEEK_SET);
    72                 $APEfooterData = fread($this->getid3->fp, 32);
     72                $this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize);
     73                $APEfooterData = $this->fread(32);
    7374                if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
    7475                        $info['error'][] = 'Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end'];
    … …  
    7778
    7879                if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
    79                         fseek($this->getid3->fp, $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize, SEEK_SET);
    80                         $thisfile_ape['tag_offset_start'] = ftell($this->getid3->fp);
    81                         $APEtagData = fread($this->getid3->fp, $thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
     80                        $this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize);
     81                        $thisfile_ape['tag_offset_start'] = $this->ftell();
     82                        $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
    8283                } else {
    8384                        $thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
    84                         fseek($this->getid3->fp, $thisfile_ape['tag_offset_start'], SEEK_SET);
    85                         $APEtagData = fread($this->getid3->fp, $thisfile_ape['footer']['raw']['tagsize']);
     85                        $this->fseek($thisfile_ape['tag_offset_start']);
     86                        $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']);
    8687                }
    8788                $info['avdataend'] = $thisfile_ape['tag_offset_start'];
  • trunk/src/wp-includes/ID3/module.tag.id3v1.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    2627                }
    2728
    28                 fseek($this->getid3->fp, -256, SEEK_END);
    29                 $preid3v1 = fread($this->getid3->fp, 128);
    30                 $id3v1tag = fread($this->getid3->fp, 128);
     29                $this->fseek(-256, SEEK_END);
     30                $preid3v1 = $this->fread(128);
     31                $id3v1tag = $this->fread(128);
    3132
    3233                if (substr($id3v1tag, 0, 3) == 'TAG') {
  • trunk/src/wp-includes/ID3/module.tag.id3v2.php

    r24696 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    5253
    5354
    54                 fseek($this->getid3->fp, $this->StartingOffset, SEEK_SET);
    55                 $header = fread($this->getid3->fp, 10);
     55                $this->fseek($this->StartingOffset);
     56                $header = $this->fread(10);
    5657                if (substr($header, 0, 3) == 'ID3'  &&  strlen($header) == 10) {
    5758
    … …  
    132133                if ($sizeofframes > 0) {
    133134
    134                         $framedata = fread($this->getid3->fp, $sizeofframes); // read all frames from file into $framedata variable
     135                        $framedata = $this->fread($sizeofframes); // read all frames from file into $framedata variable
    135136
    136137                        //    if entire frame data is unsynched, de-unsynch it now (ID3v2.3.x)
    … …  
    424425
    425426                if (isset($thisfile_id3v2_flags['isfooter']) && $thisfile_id3v2_flags['isfooter']) {
    426                         $footer = fread($this->getid3->fp, 10);
     427                        $footer = $this->fread(10);
    427428                        if (substr($footer, 0, 3) == '3DI') {
    428429                                $thisfile_id3v2['footer'] = true;
    … …  
    643644                        $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
    644645                        if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
    645                                 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']));
     646                                $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0));
     647                                if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) {
     648                                        $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']));
     649                                } else {
     650                                        $info['id3v2']['comments'][$parsedFrame['framenameshort']][]            = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']));
     651                                }
    646652                        }
    647653                        //unset($parsedFrame['data']); do not unset, may be needed elsewhere, e.g. for replaygain
    … …  
    10781084                                $parsedFrame['data']         = $frame_text;
    10791085                                if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
    1080                                         $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
     1086                                        $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (!empty($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0));
     1087                                        if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) {
     1088                                                $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
     1089                                        } else {
     1090                                                $info['id3v2']['comments'][$parsedFrame['framenameshort']][]            = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
     1091                                        }
    10811092                                }
    10821093
    … …  
    18861897                        $parsedFrame['bitsperpoint'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
    18871898                        $frame_bytesperpoint = ceil($parsedFrame['bitsperpoint'] / 8);
    1888                         for ($i = 0; $i < $frame_indexpoints; $i++) {
     1899                        for ($i = 0; $i < $parsedFrame['indexpoints']; $i++) {
    18891900                                $parsedFrame['indexes'][$i] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesperpoint));
    18901901                                $frame_offset += $frame_bytesperpoint;
    … …  
    34123423
    34133424}
    3414 
  • trunk/src/wp-includes/ID3/module.tag.lyrics3.php

    r23766 r29734  
    44//  available at http://getid3.sourceforge.net                 //
    55//            or http://www.getid3.org                         //
     6//          also https://github.com/JamesHeinrich/getID3       //
    67/////////////////////////////////////////////////////////////////
    78// See readme.txt for more details                             //
    … …  
    2829                }
    2930
    30                 fseek($this->getid3->fp, (0 - 128 - 9 - 6), SEEK_END);          // end - ID3v1 - "LYRICSEND" - [Lyrics3size]
    31                 $lyrics3_id3v1 = fread($this->getid3->fp, 128 + 9 + 6);
     31                $this->fseek((0 - 128 - 9 - 6), SEEK_END);          // end - ID3v1 - "LYRICSEND" - [Lyrics3size]
     32                $lyrics3_id3v1 = $this->fread(128 + 9 + 6);
    3233                $lyrics3lsz    = substr($lyrics3_id3v1,  0,   6); // Lyrics3size
    3334                $lyrics3end    = substr($lyrics3_id3v1,  6,   9); // LYRICSEND or LYRICS200
    … …  
    6970                        if (isset($info['ape']['tag_offset_start']) && ($info['ape']['tag_offset_start'] > 15)) {
    7071
    71                                 fseek($this->getid3->fp, $info['ape']['tag_offset_start'] - 15, SEEK_SET);
    72                                 $lyrics3lsz = fread($this->getid3->fp, 6);
    73                                 $lyrics3end = fread($this->getid3->fp, 9);
     72                                $this->fseek($info['ape']['tag_offset_start'] - 15);
     73                                $lyrics3lsz = $this->fread(6);
     74                                $lyrics3end = $this->fread(9);
    7475
    7576                                if ($lyrics3end == 'LYRICSEND') {
    … …  
    102103                        if (!isset($info['ape'])) {
    103104                                $GETID3_ERRORARRAY = &$info['warning'];
    104                                 if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, false)) {
    105                                         $getid3_temp = new getID3();
    106                                         $getid3_temp->openfile($this->getid3->filename);
    107                                         $getid3_apetag = new getid3_apetag($getid3_temp);
    108                                         $getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start'];
    109                                         $getid3_apetag->Analyze();
    110                                         if (!empty($getid3_temp->info['ape'])) {
    111                                                 $info['ape'] = $getid3_temp->info['ape'];
    112                                         }
    113                                         if (!empty($getid3_temp->info['replay_gain'])) {
    114                                                 $info['replay_gain'] = $getid3_temp->info['replay_gain'];
    115                                         }
    116                                         unset($getid3_temp, $getid3_apetag);
    117                                 }
     105                                getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true);
     106                                $getid3_temp = new getID3();
     107                                $getid3_temp->openfile($this->getid3->filename);
     108                                $getid3_apetag = new getid3_apetag($getid3_temp);
     109                                $getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start'];
     110                                $getid3_apetag->Analyze();
     111                                if (!empty($getid3_temp->info['ape'])) {
     112                                        $info['ape'] = $getid3_temp->info['ape'];
     113                                }
     114                                if (!empty($getid3_temp->info['replay_gain'])) {
     115                                        $info['replay_gain'] = $getid3_temp->info['replay_gain'];
     116                                }
     117                                unset($getid3_temp, $getid3_apetag);
    118118                        }
    119119
    … …  
    133133                }
    134134
    135                 fseek($this->getid3->fp, $endoffset, SEEK_SET);
     135                $this->fseek($endoffset);
    136136                if ($length <= 0) {
    137137                        return false;
    138138                }
    139                 $rawdata = fread($this->getid3->fp, $length);
     139                $rawdata = $this->fread($length);
    140140
    141141                $ParsedLyrics3['raw']['lyrics3version'] = $version;
    … …  
    170170                                        $this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
    171171                                } else {
    172                                         $info['error'][] = '"LYRICSEND" expected at '.(ftell($this->getid3->fp) - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead';
     172                                        $info['error'][] = '"LYRICSEND" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead';
    173173                                        return false;
    174174                                }
    … …  
    218218                                        }
    219219                                } else {
    220                                         $info['error'][] = '"LYRICS200" expected at '.(ftell($this->getid3->fp) - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead';
     220                                        $info['error'][] = '"LYRICS200" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead';
    221221                                        return false;
    222222                                }
  • trunk/src/wp-includes/ID3/readme.txt

    r24696 r29734  
    33//  available at http://getid3.sourceforge.net                 //
    44//            or http://www.getid3.org                         //
     5//          also https://github.com/JamesHeinrich/getID3       //
    56/////////////////////////////////////////////////////////////////
    67
    … …  
    6869
    6970Reads & parses (to varying degrees):
    70 # tags:
     71 ¤ tags:
    7172  * APE (v1 and v2)
    7273  * ID3v1 (& ID3v1.1)
    … …  
    7475  * Lyrics3 (v1 & v2)
    7576
    76 # audio-lossy:
     77 ¤ audio-lossy:
    7778  * MP3/MP2/MP1
    7879  * MPC / Musepack
    … …  
    8687  * VQF
    8788
    88 # audio-lossless:
     89 ¤ audio-lossless:
    8990  * AIFF
    9091  * AU
    … …  
    105106  * WavPack
    106107
    107 # audio-video:
     108 ¤ audio-video:
    108109  * ASF: ASF, Windows Media Audio (WMA), Windows Media Video (WMV)
    109110  * AVI (RIFF)
    … …  
    115116  * RealVideo
    116117
    117 # still image:
     118 ¤ still image:
    118119  * BMP
    119120  * GIF
    … …  
    124125  * PhotoCD
    125126
    126 # data:
     127 ¤ data:
    127128  * ISO-9660 CD-ROM image (directory structure)
    128129  * SZIP (limited support)
    … …  
    310311* Support for RIFF-INFO chunks
    311312  * http://lotto.st-andrews.ac.uk/~njh/tag_interchange.html
    312     (thanks Nick Humfrey <njh@surgeradio*co*uk>)
     313    (thanks Nick Humfrey <njhØsurgeradio*co*uk>)
    313314  * http://abcavi.narod.ru/sof/abcavi/infotags.htm
    314315    (thanks Kibi)
    … …  
    325326* Support for ICO
    326327* Support for ANI
    327 * Support for EXE (comments, author, etc) (thanks p*quaedackers@planet*nl)
     328* Support for EXE (comments, author, etc) (thanks p*quaedackersØplanet*nl)
    328329* Support for DVD-IFO (region, subtitles, aspect ratio, etc)
    329   (thanks p*quaedackers@planet*nl)
     330  (thanks p*quaedackersØplanet*nl)
    330331* More complete support for SWF - parsing encapsulated MP3 and/or JPEG content
    331     (thanks n8n8@yahoo*com)
     332    (thanks n8n8Øyahoo*com)
    332333* Support for a2b
    333334* Optional scan-through-frames for AVI verification
    334   (thanks rockcohen@massive-interactive*nl)
    335 * Support for TTF (thanks info@butterflyx*com)
     335  (thanks rockcohenØmassive-interactive*nl)
     336* Support for TTF (thanks infoØbutterflyx*com)
    336337* Support for DSS (http://www.getid3.org/phpBB3/viewtopic.php?t=171)
    337338* Support for SMAF (http://smaf-yamaha.com/what/demo.html)
    … …  
    339340* Support for AMR (http://www.getid3.org/phpBB3/viewtopic.php?t=195)
    340341* Support for 3gpp (http://www.getid3.org/phpBB3/viewtopic.php?t=195)
    341 * Support for ID4 (http://www.wackysoft.cjb.net grizlyY2K@hotmail*com)
     342* Support for ID4 (http://www.wackysoft.cjb.net grizlyY2KØhotmail*com)
    342343* Parse XML data returned in Ogg comments
    343 * Parse XML data from Quicktime SMIL metafiles (klausrath@mac*com)
     344* Parse XML data from Quicktime SMIL metafiles (klausrathØmac*com)
    344345* ID3v2 genre string creator function
    345346* More complete parsing of JPG
    … …  
    425426    to show that playtime is incorrect. Other data should be mostly
    426427    correct, assuming that data is constant throughout the file)
    427 
     428* PHP <= v5 on Windows cannot read UTF-8 filenames
    428429
    429430
Note: See TracChangeset for help on using the changeset viewer.