Make WordPress Core


Ignore:
Timestamp:
11/26/2021 03:04:10 AM (5 years ago)
Author:
SergeyBiryukov
Message:

External Libraries: Update getID3 to version 1.9.21.

The latest version includes preliminary PHP 8.1 support, as well as a variety of bug fixes.

Release notes: https://github.com/JamesHeinrich/getID3/releases/tag/v1.9.21

A full list of changes in this update can be found on GitHub:
https://github.com/JamesHeinrich/getID3/compare/v1.9.20...v1.9.21

This commit also includes:

  • Setting the $options_audiovideo_quicktime_ReturnAtomData property (now false by default) to true in wp_read_video_metadata() and wp_read_audio_metadata() in order to get the created_timestamp value.
  • PHPCS adjustments previously made for a passing PHP Compatibility scan.

Follow-up to [47601], [47737], [47902], [48278], [49621], [50714].

Props jrf, SergeyBiryukov.
Fixes #54162.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ID3/module.audio-video.riff.php

    r51901 r52254  
    5757                $thisfile_riff_WAVE        = array();
    5858
     59                $Original                 = array();
    5960                $Original['avdataoffset'] = $info['avdataoffset'];
    6061                $Original['avdataend']    = $info['avdataend'];
     
    297298                                        $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];
    298299
    299                                         $thisfile_riff_WAVE_bext_0['title']          =                         trim(substr($thisfile_riff_WAVE_bext_0['data'],   0, 256));
    300                                         $thisfile_riff_WAVE_bext_0['author']         =                         trim(substr($thisfile_riff_WAVE_bext_0['data'], 256,  32));
    301                                         $thisfile_riff_WAVE_bext_0['reference']      =                         trim(substr($thisfile_riff_WAVE_bext_0['data'], 288,  32));
     300                                        $thisfile_riff_WAVE_bext_0['title']          =                              substr($thisfile_riff_WAVE_bext_0['data'],   0, 256);
     301                                        $thisfile_riff_WAVE_bext_0['author']         =                              substr($thisfile_riff_WAVE_bext_0['data'], 256,  32);
     302                                        $thisfile_riff_WAVE_bext_0['reference']      =                              substr($thisfile_riff_WAVE_bext_0['data'], 288,  32);
     303                                        foreach (array('title','author','reference') as $bext_key) {
     304                                                // Some software (notably Logic Pro) may not blank existing data before writing a null-terminated string to the offsets
     305                                                // assigned for text fields, resulting in a null-terminated string (or possibly just a single null) followed by garbage
     306                                                // Keep only string as far as first null byte, discard rest of fixed-width data
     307                                                // https://github.com/JamesHeinrich/getID3/issues/263
     308                                                $null_terminator_offset = strpos($thisfile_riff_WAVE_bext_0[$bext_key], "\x00");
     309                                                $thisfile_riff_WAVE_bext_0[$bext_key] = substr($thisfile_riff_WAVE_bext_0[$bext_key], 0, $null_terminator_offset);
     310                                        }
     311
    302312                                        $thisfile_riff_WAVE_bext_0['origin_date']    =                              substr($thisfile_riff_WAVE_bext_0['data'], 320,  10);
    303313                                        $thisfile_riff_WAVE_bext_0['origin_time']    =                              substr($thisfile_riff_WAVE_bext_0['data'], 330,   8);
     
    308318                                        if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) {
    309319                                                if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) {
     320                                                        $bext_timestamp = array();
    310321                                                        list($dummy, $bext_timestamp['year'], $bext_timestamp['month'],  $bext_timestamp['day'])    = $matches_bext_date;
    311322                                                        list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time;
     
    452463                                }
    453464
    454 
     465                                if (isset($thisfile_riff_WAVE['guan'][0]['data'])) {
     466                                        // shortcut
     467                                        $thisfile_riff_WAVE_guan_0 = &$thisfile_riff_WAVE['guan'][0];
     468                                        if (!empty($thisfile_riff_WAVE_guan_0['data']) && (substr($thisfile_riff_WAVE_guan_0['data'], 0, 14) == 'GUANO|Version:')) {
     469                                                $thisfile_riff['guano'] = array();
     470                                                foreach (explode("\n", $thisfile_riff_WAVE_guan_0['data']) as $line) {
     471                                                        if ($line) {
     472                                                                @list($key, $value) = explode(':', $line, 2);
     473                                                                if (substr($value, 0, 3) == '[{"') {
     474                                                                        if ($decoded = @json_decode($value, true)) {
     475                                                                                if (!empty($decoded) && (count($decoded) == 1)) {
     476                                                                                        $value = $decoded[0];
     477                                                                                } else {
     478                                                                                        $value = $decoded;
     479                                                                                }
     480                                                                        }
     481                                                                }
     482                                                                $thisfile_riff['guano'] = array_merge_recursive($thisfile_riff['guano'], getid3_lib::CreateDeepArray($key, '|', $value));
     483                                                        }
     484                                                }
     485
     486                                                // https://www.wildlifeacoustics.com/SCHEMA/GUANO.html
     487                                                foreach ($thisfile_riff['guano'] as $key => $value) {
     488                                                        switch ($key) {
     489                                                                case 'Loc Position':
     490                                                                        if (preg_match('#^([\\+\\-]?[0-9]+\\.[0-9]+) ([\\+\\-]?[0-9]+\\.[0-9]+)$#', $value, $matches)) {
     491                                                                                list($dummy, $latitude, $longitude) = $matches;
     492                                                                                $thisfile_riff['comments']['gps_latitude'][0]  = floatval($latitude);
     493                                                                                $thisfile_riff['comments']['gps_longitude'][0] = floatval($longitude);
     494                                                                                $thisfile_riff['guano'][$key] = floatval($latitude).' '.floatval($longitude);
     495                                                                        }
     496                                                                        break;
     497                                                                case 'Loc Elevation': // Elevation/altitude above mean sea level in meters
     498                                                                        $thisfile_riff['comments']['gps_altitude'][0] = floatval($value);
     499                                                                        $thisfile_riff['guano'][$key] = (float) $value;
     500                                                                        break;
     501                                                                case 'Filter HP':        // High-pass filter frequency in kHz
     502                                                                case 'Filter LP':        // Low-pass filter frequency in kHz
     503                                                                case 'Humidity':         // Relative humidity as a percentage
     504                                                                case 'Length':           // Recording length in seconds
     505                                                                case 'Loc Accuracy':     // Estimated Position Error in meters
     506                                                                case 'Temperature Ext':  // External temperature in degrees Celsius outside the recorder's housing
     507                                                                case 'Temperature Int':  // Internal temperature in degrees Celsius inside the recorder's housing
     508                                                                        $thisfile_riff['guano'][$key] = (float) $value;
     509                                                                        break;
     510                                                                case 'Samplerate':       // Recording sample rate, Hz
     511                                                                case 'TE':               // Time-expansion factor. If not specified, then 1 (no time-expansion a.k.a. direct-recording) is assumed.
     512                                                                        $thisfile_riff['guano'][$key] = (int) $value;
     513                                                                        break;
     514                                                        }
     515                                                }
     516
     517                                        } else {
     518                                                $this->warning('RIFF.guan data not in expected format');
     519                                        }
     520                                }
    455521
    456522                                if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) {
     
    734800                                if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
    735801                                        if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) {
     802                                                $thisfile_riff_raw_strf_strhfccType_streamindex = null;
    736803                                                for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
    737804                                                        if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
     
    10701137                                        getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
    10711138                                        $getid3_temp = new getID3();
    1072                                         $getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
     1139                                        $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
    10731140                                        $getid3_id3v2 = new getid3_id3v2($getid3_temp);
    10741141                                        $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8;
     
    11731240
    11741241                                        $getid3_temp = new getID3();
    1175                                         $getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
     1242                                        $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
    11761243                                        $getid3_mpeg = new getid3_mpeg($getid3_temp);
    11771244                                        $getid3_mpeg->Analyze();
     
    12591326
    12601327                                        $getid3_temp = new getID3();
    1261                                         $getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
     1328                                        $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
    12621329                                        $getid3_id3v2 = new getid3_id3v2($getid3_temp);
    12631330                                        $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8;
     
    15151582                $RIFFchunk = false;
    15161583                $FoundAllChunksWeNeed = false;
     1584                $LISTchunkParent = null;
     1585                $LISTchunkMaxOffset = null;
     1586                $AC3syncwordBytes = pack('n', getid3_ac3::syncword); // 0x0B77 -> "\x0B\x77"
    15171587
    15181588                try {
     
    15581628                                                                                if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) {
    15591629                                                                                        $getid3_temp = new getID3();
    1560                                                                                         $getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
     1630                                                                                        $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
    15611631                                                                                        $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
    15621632                                                                                        $getid3_temp->info['avdataend']    = $this->ftell() + $AudioChunkSize;
     
    15761646                                                                                }
    15771647
    1578                                                                         } elseif (strpos($FirstFourBytes, getid3_ac3::syncword) === 0) {
    1579 
     1648                                                                        } elseif (strpos($FirstFourBytes, $AC3syncwordBytes) === 0) {
    15801649                                                                                // AC3
    15811650                                                                                $getid3_temp = new getID3();
    1582                                                                                 $getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
     1651                                                                                $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
    15831652                                                                                $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
    15841653                                                                                $getid3_temp->info['avdataend']    = $this->ftell() + $AudioChunkSize;
     
    16411710                                                                        if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) {
    16421711                                                                                $getid3_temp = new getID3();
    1643                                                                                 $getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
     1712                                                                                $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
    16441713                                                                                $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
    16451714                                                                                $getid3_temp->info['avdataend']    = $info['avdataend'];
     
    16531722                                                                        }
    16541723
    1655                                                                 } elseif (($isRegularAC3 = (substr($testData, 0, 2) == getid3_ac3::syncword)) || substr($testData, 8, 2) == strrev(getid3_ac3::syncword)) {
     1724                                                                } elseif (($isRegularAC3 = (substr($testData, 0, 2) == $AC3syncwordBytes)) || substr($testData, 8, 2) == strrev($AC3syncwordBytes)) {
    16561725
    16571726                                                                        // This is probably AC-3 data
    16581727                                                                        $getid3_temp = new getID3();
    16591728                                                                        if ($isRegularAC3) {
    1660                                                                                 $getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
     1729                                                                                $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
    16611730                                                                                $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
    16621731                                                                                $getid3_temp->info['avdataend']    = $info['avdataend'];
     
    16741743                                                                                        $ac3_data .= substr($testData, 8 + $i + 0, 1);
    16751744                                                                                }
     1745                                                                                $getid3_ac3->getid3->info['avdataoffset'] = 0;
     1746                                                                                $getid3_ac3->getid3->info['avdataend']    = strlen($ac3_data);
    16761747                                                                                $getid3_ac3->AnalyzeString($ac3_data);
    16771748                                                                        }
     
    16921763                                                                        // This is probably DTS data
    16931764                                                                        $getid3_temp = new getID3();
    1694                                                                         $getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
     1765                                                                        $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
    16951766                                                                        $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
    16961767                                                                        $getid3_dts = new getid3_dts($getid3_temp);
     
    17331804                                                        case 'MEXT':
    17341805                                                        case 'DISP':
     1806                                                        case 'wamd':
     1807                                                        case 'guan':
    17351808                                                                // always read data in
    17361809                                                        case 'JUNK':
     
    20772150        public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) {
    20782151
     2152                $parsed                    = array();
    20792153                $parsed['biSize']          = substr($BITMAPINFOHEADER,  0, 4); // number of bytes required by the BITMAPINFOHEADER structure
    20802154                $parsed['biWidth']         = substr($BITMAPINFOHEADER,  4, 4); // width of the bitmap in pixels
Note: See TracChangeset for help on using the changeset viewer.