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