Changeset 29734 for trunk/src/wp-includes/ID3/module.audio-video.asf.php
- Timestamp:
- 09/11/2014 07:06:33 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ID3/module.audio-video.asf.php
r23766 r29734 4 4 // available at http://getid3.sourceforge.net // 5 5 // or http://www.getid3.org // 6 // also https://github.com/JamesHeinrich/getID3 // 6 7 ///////////////////////////////////////////////////////////////// 7 8 // See readme.txt for more details // … … 16 17 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); 17 18 18 class getid3_asf extends getid3_handler 19 { 19 class getid3_asf extends getid3_handler { 20 20 21 21 public function __construct(getID3 $getid3) { … … 67 67 $info['fileformat'] = 'asf'; 68 68 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); 71 71 72 72 $thisfile_asf_headerobject['objectid'] = substr($HeaderObjectData, 0, 16); 73 73 $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']); 74 74 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).'}'); 80 77 } 81 78 $thisfile_asf_headerobject['objectsize'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8)); … … 84 81 $thisfile_asf_headerobject['reserved2'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1)); 85 82 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); 88 85 $offset = 0; 89 86 … … 285 282 $thisfile_asf_headerextensionobject['extension_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']); 286 283 $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); 288 285 if ($unhandled_sections === 0) { 289 286 unset($thisfile_asf_headerextensionobject['extension_data']); … … 333 330 $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); 334 331 $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']); 336 333 337 334 $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character … … 827 824 828 825 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>'; 845 834 } 846 835 break; … … 861 850 $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1)); 862 851 $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']); 864 853 $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4)); 865 854 $wm_picture_offset += 4; … … 1157 1146 } 1158 1147 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); 1161 1150 $offset = 0; 1162 1151 $NextObjectGUID = substr($NextObjectDataHeader, 0, 16); … … 1180 1169 $thisfile_asf_dataobject = &$thisfile_asf['data_object']; 1181 1170 1182 $DataObjectData = $NextObjectDataHeader. fread($this->getid3->fp,50 - 24);1171 $DataObjectData = $NextObjectDataHeader.$this->fread(50 - 24); 1183 1172 $offset = 24; 1184 1173 … … 1208 1197 // * Error Correction Data 1209 1198 1210 $info['avdataoffset'] = ftell($this->getid3->fp);1211 fseek($this->getid3->fp,($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data1212 $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(); 1213 1202 break; 1214 1203 … … 1230 1219 $thisfile_asf_simpleindexobject = &$thisfile_asf['simple_index_object']; 1231 1220 1232 $SimpleIndexObjectData = $NextObjectDataHeader. fread($this->getid3->fp,56 - 24);1221 $SimpleIndexObjectData = $NextObjectDataHeader.$this->fread(56 - 24); 1233 1222 $offset = 24; 1234 1223 … … 1247 1236 $offset += 4; 1248 1237 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']); 1250 1239 for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) { 1251 1240 $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4)); … … 1284 1273 $thisfile_asf_asfindexobject = &$thisfile_asf['asf_index_object']; 1285 1274 1286 $ASFIndexObjectData = $NextObjectDataHeader. fread($this->getid3->fp,34 - 24);1275 $ASFIndexObjectData = $NextObjectDataHeader.$this->fread(34 - 24); 1287 1276 $offset = 24; 1288 1277 … … 1298 1287 $offset += 4; 1299 1288 1300 $ASFIndexObjectData .= fread($this->getid3->fp,4 * $thisfile_asf_asfindexobject['index_specifiers_count']);1289 $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count']); 1301 1290 for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { 1302 1291 $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2)); … … 1308 1297 } 1309 1298 1310 $ASFIndexObjectData .= fread($this->getid3->fp,4);1299 $ASFIndexObjectData .= $this->fread(4); 1311 1300 $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); 1312 1301 $offset += 4; 1313 1302 1314 $ASFIndexObjectData .= fread($this->getid3->fp,8 * $thisfile_asf_asfindexobject['index_specifiers_count']);1303 $ASFIndexObjectData .= $this->fread(8 * $thisfile_asf_asfindexobject['index_specifiers_count']); 1315 1304 for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { 1316 1305 $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8)); … … 1318 1307 } 1319 1308 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']); 1321 1310 for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) { 1322 1311 for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { … … 1333 1322 $info['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8); 1334 1323 } 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); 1338 1327 break; 1339 1328 } … … 1434 1423 } 1435 1424 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; 1438 1427 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'])) { 1440 1429 $thisfile_video['resolution_x'] = $valuearray['resolution_x']; 1441 1430 $thisfile_video['resolution_y'] = $valuearray['resolution_y']; … … 1452 1441 } 1453 1442 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'); 1463 1451 } 1464 1452 … … 1667 1655 1668 1656 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); 1689 1682 } 1690 return (isset($WMpictureTypeLookup[$WMpictureType]) ? $WMpictureTypeLookup[$WMpictureType] : ''); 1683 1684 return (isset($lookup[$WMpictureType]) ? $lookup[$WMpictureType] : ''); 1691 1685 } 1692 1686 1693 public function ASF_HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) {1687 public function HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) { 1694 1688 // http://msdn.microsoft.com/en-us/library/bb643323.aspx 1695 1689 … … 1826 1820 $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); 1827 1821 $offset += 2; 1828 $descriptionRecord['data_type_text'] = $this->ASFmetadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']);1822 $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']); 1829 1823 1830 1824 $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); … … 1898 1892 $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); 1899 1893 $offset += 2; 1900 $descriptionRecord['data_type_text'] = $this->ASFmetadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']);1894 $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']); 1901 1895 1902 1896 $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); … … 1938 1932 1939 1933 1940 public static function ASFmetadataLibraryObjectDataTypeLookup($id) {1941 static $ ASFmetadataLibraryObjectDataTypeLookup = array(1934 public static function metadataLibraryObjectDataTypeLookup($id) { 1935 static $lookup = array( 1942 1936 0x0000 => 'Unicode string', // The data consists of a sequence of Unicode characters 1943 1937 0x0001 => 'BYTE array', // The type of the data is implementation-specific … … 1948 1942 0x0006 => 'GUID', // The data is 16 bytes long and should be interpreted as a 128-bit GUID 1949 1943 ); 1950 return (isset($ ASFmetadataLibraryObjectDataTypeLookup[$id]) ? $ASFmetadataLibraryObjectDataTypeLookup[$id] : 'invalid');1944 return (isset($lookup[$id]) ? $lookup[$id] : 'invalid'); 1951 1945 } 1952 1946 … … 1965 1959 $WMpicture['image_type_id'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 1)); 1966 1960 $offset += 1; 1967 $WMpicture['image_type'] = $this->WMpictureTypeLookup($WMpicture['image_type_id']);1961 $WMpicture['image_type'] = self::WMpictureTypeLookup($WMpicture['image_type_id']); 1968 1962 $WMpicture['image_size'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 4)); 1969 1963 $offset += 4;
Note: See TracChangeset
for help on using the changeset viewer.