Changeset 52254 for trunk/src/wp-includes/ID3/module.audio-video.riff.php
- Timestamp:
- 11/26/2021 03:04:10 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ID3/module.audio-video.riff.php
r51901 r52254 57 57 $thisfile_riff_WAVE = array(); 58 58 59 $Original = array(); 59 60 $Original['avdataoffset'] = $info['avdataoffset']; 60 61 $Original['avdataend'] = $info['avdataend']; … … 297 298 $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0]; 298 299 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 302 312 $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10); 303 313 $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8); … … 308 318 if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) { 309 319 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(); 310 321 list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date; 311 322 list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time; … … 452 463 } 453 464 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 } 455 521 456 522 if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) { … … 734 800 if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) { 735 801 if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) { 802 $thisfile_riff_raw_strf_strhfccType_streamindex = null; 736 803 for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) { 737 804 if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) { … … 1070 1137 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); 1071 1138 $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); 1073 1140 $getid3_id3v2 = new getid3_id3v2($getid3_temp); 1074 1141 $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8; … … 1173 1240 1174 1241 $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); 1176 1243 $getid3_mpeg = new getid3_mpeg($getid3_temp); 1177 1244 $getid3_mpeg->Analyze(); … … 1259 1326 1260 1327 $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); 1262 1329 $getid3_id3v2 = new getid3_id3v2($getid3_temp); 1263 1330 $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8; … … 1515 1582 $RIFFchunk = false; 1516 1583 $FoundAllChunksWeNeed = false; 1584 $LISTchunkParent = null; 1585 $LISTchunkMaxOffset = null; 1586 $AC3syncwordBytes = pack('n', getid3_ac3::syncword); // 0x0B77 -> "\x0B\x77" 1517 1587 1518 1588 try { … … 1558 1628 if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) { 1559 1629 $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); 1561 1631 $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; 1562 1632 $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; … … 1576 1646 } 1577 1647 1578 } elseif (strpos($FirstFourBytes, getid3_ac3::syncword) === 0) { 1579 1648 } elseif (strpos($FirstFourBytes, $AC3syncwordBytes) === 0) { 1580 1649 // AC3 1581 1650 $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); 1583 1652 $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; 1584 1653 $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; … … 1641 1710 if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) { 1642 1711 $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); 1644 1713 $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; 1645 1714 $getid3_temp->info['avdataend'] = $info['avdataend']; … … 1653 1722 } 1654 1723 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)) { 1656 1725 1657 1726 // This is probably AC-3 data 1658 1727 $getid3_temp = new getID3(); 1659 1728 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); 1661 1730 $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; 1662 1731 $getid3_temp->info['avdataend'] = $info['avdataend']; … … 1674 1743 $ac3_data .= substr($testData, 8 + $i + 0, 1); 1675 1744 } 1745 $getid3_ac3->getid3->info['avdataoffset'] = 0; 1746 $getid3_ac3->getid3->info['avdataend'] = strlen($ac3_data); 1676 1747 $getid3_ac3->AnalyzeString($ac3_data); 1677 1748 } … … 1692 1763 // This is probably DTS data 1693 1764 $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); 1695 1766 $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; 1696 1767 $getid3_dts = new getid3_dts($getid3_temp); … … 1733 1804 case 'MEXT': 1734 1805 case 'DISP': 1806 case 'wamd': 1807 case 'guan': 1735 1808 // always read data in 1736 1809 case 'JUNK': … … 2077 2150 public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) { 2078 2151 2152 $parsed = array(); 2079 2153 $parsed['biSize'] = substr($BITMAPINFOHEADER, 0, 4); // number of bytes required by the BITMAPINFOHEADER structure 2080 2154 $parsed['biWidth'] = substr($BITMAPINFOHEADER, 4, 4); // width of the bitmap in pixels
Note: See TracChangeset
for help on using the changeset viewer.