Changeset 32979 for trunk/src/wp-includes/ID3/module.tag.id3v2.php
- Timestamp:
- 06/28/2015 12:16:17 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ID3/module.tag.id3v2.php
r29734 r32979 626 626 $frame_offset = 0; 627 627 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 628 628 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 629 629 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 630 630 $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; 631 } 632 $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); 633 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { 631 $frame_textencoding_terminator = "\x00"; 632 } 633 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 634 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 634 635 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 635 636 } … … 641 642 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 642 643 643 $parsedFrame['description'] = $frame_description;644 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)));644 $parsedFrame['description'] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $frame_description)); 645 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 645 646 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 646 647 $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); … … 718 719 $frame_offset = 0; 719 720 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 721 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 720 722 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 721 723 $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; 722 } 723 $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); 724 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { 724 $frame_textencoding_terminator = "\x00"; 725 } 726 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 727 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 725 728 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 726 729 } … … 730 733 $frame_description = ''; 731 734 } 732 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)));733 734 $frame_terminatorpos = strpos($parsedFrame['data'], $ this->TextEncodingTerminatorLookup($frame_textencoding));735 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {735 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 736 737 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator); 738 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 736 739 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 737 740 } … … 957 960 $frame_offset = 0; 958 961 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 962 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 959 963 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 960 964 $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; 965 $frame_textencoding_terminator = "\x00"; 961 966 } 962 967 $frame_language = substr($parsedFrame['data'], $frame_offset, 3); 963 968 $frame_offset += 3; 964 $frame_terminatorpos = strpos($parsedFrame['data'], $ this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);965 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {969 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 970 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 966 971 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 967 972 } … … 970 975 $frame_description = ''; 971 976 } 972 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)));977 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 973 978 974 979 $parsedFrame['encodingid'] = $frame_textencoding; … … 1003 1008 $frame_offset = 0; 1004 1009 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1010 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1005 1011 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1006 1012 $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; 1013 $frame_textencoding_terminator = "\x00"; 1007 1014 } 1008 1015 $frame_language = substr($parsedFrame['data'], $frame_offset, 3); … … 1021 1028 while (strlen($frame_remainingdata)) { 1022 1029 $frame_offset = 0; 1023 $frame_terminatorpos = strpos($frame_remainingdata, $ this->TextEncodingTerminatorLookup($frame_textencoding));1030 $frame_terminatorpos = strpos($frame_remainingdata, $frame_textencoding_terminator); 1024 1031 if ($frame_terminatorpos === false) { 1025 1032 $frame_remainingdata = ''; 1026 1033 } else { 1027 if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {1034 if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 1028 1035 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1029 1036 } 1030 1037 $parsedFrame['lyrics'][$timestampindex]['data'] = substr($frame_remainingdata, $frame_offset, $frame_terminatorpos - $frame_offset); 1031 1038 1032 $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)));1039 $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator)); 1033 1040 if (($timestampindex == 0) && (ord($frame_remainingdata{0}) != 0)) { 1034 1041 // timestamp probably omitted for first data item … … 1061 1068 $frame_offset = 0; 1062 1069 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1070 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1063 1071 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1064 1072 $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; 1073 $frame_textencoding_terminator = "\x00"; 1065 1074 } 1066 1075 $frame_language = substr($parsedFrame['data'], $frame_offset, 3); 1067 1076 $frame_offset += 3; 1068 $frame_terminatorpos = strpos($parsedFrame['data'], $ this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);1069 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {1077 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1078 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 1070 1079 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1071 1080 } … … 1074 1083 $frame_description = ''; 1075 1084 } 1076 $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)));1085 $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 1077 1086 1078 1087 $parsedFrame['encodingid'] = $frame_textencoding; … … 1331 1340 $frame_offset = 0; 1332 1341 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1342 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1333 1343 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1334 1344 $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; 1345 $frame_textencoding_terminator = "\x00"; 1335 1346 } 1336 1347 … … 1368 1379 $info['warning'][] = 'data portion of APIC frame is missing at offset '.($parsedFrame['dataoffset'] + 8 + $frame_offset); 1369 1380 } else { 1370 $frame_terminatorpos = strpos($parsedFrame['data'], $ this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);1371 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {1381 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1382 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 1372 1383 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1373 1384 } … … 1387 1398 $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype); 1388 1399 $parsedFrame['description'] = $frame_description; 1389 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)));1400 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 1390 1401 $parsedFrame['datalength'] = strlen($parsedFrame['data']); 1391 1402 … … 1444 1455 $info['id3v2']['comments']['picture'] = array(); 1445 1456 } 1446 $info['id3v2']['comments']['picture'][] = array('data'=>$parsedFrame['data'], 'image_mime'=>$parsedFrame['image_mime']); 1457 $comments_picture_data = array(); 1458 foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { 1459 if (isset($parsedFrame[$picture_key])) { 1460 $comments_picture_data[$picture_key] = $parsedFrame[$picture_key]; 1461 } 1462 } 1463 $info['id3v2']['comments']['picture'][] = $comments_picture_data; 1464 unset($comments_picture_data); 1447 1465 } 1448 1466 } … … 1463 1481 $frame_offset = 0; 1464 1482 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1483 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1465 1484 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1466 1485 $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; 1486 $frame_textencoding_terminator = "\x00"; 1467 1487 } 1468 1488 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); … … 1473 1493 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1474 1494 1475 $frame_terminatorpos = strpos($parsedFrame['data'], $ this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);1476 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {1495 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1496 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 1477 1497 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1478 1498 } … … 1481 1501 $frame_filename = ''; 1482 1502 } 1483 $frame_offset = $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding));1484 1485 $frame_terminatorpos = strpos($parsedFrame['data'], $ this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);1486 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {1503 $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); 1504 1505 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1506 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 1487 1507 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1488 1508 } … … 1491 1511 $frame_description = ''; 1492 1512 } 1493 $frame_offset = $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding));1513 $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); 1494 1514 1495 1515 $parsedFrame['objectdata'] = (string) substr($parsedFrame['data'], $frame_offset); … … 1608 1628 1609 1629 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'LINK')) || // 4.20 LINK Linked information 1610 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) { 1630 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) { // 4.22 LNK Linked information 1611 1631 // There may be more than one 'LINK' frame in a tag, 1612 1632 // but only one with the same contents … … 1636 1656 $parsedFrame['additionaldata'] = (string) substr($parsedFrame['data'], $frame_offset); 1637 1657 if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { 1638 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = utf8_encode($parsedFrame['url']);1658 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback_iso88591_utf8($parsedFrame['url']); 1639 1659 } 1640 1660 unset($parsedFrame['data']); … … 1730 1750 $frame_offset = 0; 1731 1751 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1752 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1732 1753 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1733 1754 $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; 1755 $frame_textencoding_terminator = "\x00"; 1734 1756 } 1735 1757 … … 1753 1775 $frame_receivedasid = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1754 1776 1755 $frame_terminatorpos = strpos($parsedFrame['data'], $ this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);1756 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {1777 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1778 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 1757 1779 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1758 1780 } … … 1761 1783 $frame_sellername = ''; 1762 1784 } 1763 $frame_offset = $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding));1764 1765 $frame_terminatorpos = strpos($parsedFrame['data'], $ this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);1766 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {1785 $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); 1786 1787 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1788 if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { 1767 1789 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1768 1790 } … … 1771 1793 $frame_description = ''; 1772 1794 } 1773 $frame_offset = $frame_terminatorpos + strlen($ this->TextEncodingTerminatorLookup($frame_textencoding));1795 $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); 1774 1796 1775 1797 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); … … 1944 1966 1945 1967 unset($parsedFrame['data']); 1968 1969 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CHAP')) { // CHAP Chapters frame (ID3v2.3+ only) 1970 // http://id3.org/id3v2-chapters-1.0 1971 // <ID3v2.3 or ID3v2.4 frame header, ID: "CHAP"> (10 bytes) 1972 // Element ID <text string> $00 1973 // Start time $xx xx xx xx 1974 // End time $xx xx xx xx 1975 // Start offset $xx xx xx xx 1976 // End offset $xx xx xx xx 1977 // <Optional embedded sub-frames> 1978 1979 $frame_offset = 0; 1980 @list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); 1981 $frame_offset += strlen($parsedFrame['element_id']."\x00"); 1982 $parsedFrame['time_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 1983 $frame_offset += 4; 1984 $parsedFrame['time_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 1985 $frame_offset += 4; 1986 if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { 1987 // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." 1988 $parsedFrame['offset_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 1989 } 1990 $frame_offset += 4; 1991 if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { 1992 // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." 1993 $parsedFrame['offset_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 1994 } 1995 $frame_offset += 4; 1996 1997 if ($frame_offset < strlen($parsedFrame['data'])) { 1998 $parsedFrame['subframes'] = array(); 1999 while ($frame_offset < strlen($parsedFrame['data'])) { 2000 // <Optional embedded sub-frames> 2001 $subframe = array(); 2002 $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); 2003 $frame_offset += 4; 2004 $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 2005 $frame_offset += 4; 2006 $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 2007 $frame_offset += 2; 2008 if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { 2009 $info['warning'][] = 'CHAP subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'; 2010 break; 2011 } 2012 $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); 2013 $frame_offset += $subframe['size']; 2014 2015 $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); 2016 $subframe['text'] = substr($subframe_rawdata, 1); 2017 $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); 2018 $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));; 2019 switch (substr($encoding_converted_text, 0, 2)) { 2020 case "\xFF\xFE": 2021 case "\xFE\xFF": 2022 switch (strtoupper($info['id3v2']['encoding'])) { 2023 case 'ISO-8859-1': 2024 case 'UTF-8': 2025 $encoding_converted_text = substr($encoding_converted_text, 2); 2026 // remove unwanted byte-order-marks 2027 break; 2028 default: 2029 // ignore 2030 break; 2031 } 2032 break; 2033 default: 2034 // do not remove BOM 2035 break; 2036 } 2037 2038 if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { 2039 if ($subframe['name'] == 'TIT2') { 2040 $parsedFrame['chapter_name'] = $encoding_converted_text; 2041 } elseif ($subframe['name'] == 'TIT3') { 2042 $parsedFrame['chapter_description'] = $encoding_converted_text; 2043 } 2044 $parsedFrame['subframes'][] = $subframe; 2045 } else { 2046 $info['warning'][] = 'ID3v2.CHAP subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'; 2047 } 2048 } 2049 unset($subframe_rawdata, $subframe, $encoding_converted_text); 2050 } 2051 2052 $id3v2_chapter_entry = array(); 2053 foreach (array('id', 'time_begin', 'time_end', 'offset_begin', 'offset_end', 'chapter_name', 'chapter_description') as $id3v2_chapter_key) { 2054 if (isset($parsedFrame[$id3v2_chapter_key])) { 2055 $id3v2_chapter_entry[$id3v2_chapter_key] = $parsedFrame[$id3v2_chapter_key]; 2056 } 2057 } 2058 if (!isset($info['id3v2']['chapters'])) { 2059 $info['id3v2']['chapters'] = array(); 2060 } 2061 $info['id3v2']['chapters'][] = $id3v2_chapter_entry; 2062 unset($id3v2_chapter_entry, $id3v2_chapter_key); 2063 2064 2065 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CTOC')) { // CTOC Chapters Table Of Contents frame (ID3v2.3+ only) 2066 // http://id3.org/id3v2-chapters-1.0 2067 // <ID3v2.3 or ID3v2.4 frame header, ID: "CTOC"> (10 bytes) 2068 // Element ID <text string> $00 2069 // CTOC flags %xx 2070 // Entry count $xx 2071 // Child Element ID <string>$00 /* zero or more child CHAP or CTOC entries */ 2072 // <Optional embedded sub-frames> 2073 2074 $frame_offset = 0; 2075 @list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); 2076 $frame_offset += strlen($parsedFrame['element_id']."\x00"); 2077 $ctoc_flags_raw = ord(substr($parsedFrame['data'], $frame_offset, 1)); 2078 $frame_offset += 1; 2079 $parsedFrame['entry_count'] = ord(substr($parsedFrame['data'], $frame_offset, 1)); 2080 $frame_offset += 1; 2081 2082 $terminator_position = null; 2083 for ($i = 0; $i < $parsedFrame['entry_count']; $i++) { 2084 $terminator_position = strpos($parsedFrame['data'], "\x00", $frame_offset); 2085 $parsedFrame['child_element_ids'][$i] = substr($parsedFrame['data'], $frame_offset, $terminator_position - $frame_offset); 2086 $frame_offset = $terminator_position + 1; 2087 } 2088 2089 $parsedFrame['ctoc_flags']['ordered'] = (bool) ($ctoc_flags_raw & 0x01); 2090 $parsedFrame['ctoc_flags']['top_level'] = (bool) ($ctoc_flags_raw & 0x03); 2091 2092 unset($ctoc_flags_raw, $terminator_position); 2093 2094 if ($frame_offset < strlen($parsedFrame['data'])) { 2095 $parsedFrame['subframes'] = array(); 2096 while ($frame_offset < strlen($parsedFrame['data'])) { 2097 // <Optional embedded sub-frames> 2098 $subframe = array(); 2099 $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); 2100 $frame_offset += 4; 2101 $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 2102 $frame_offset += 4; 2103 $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 2104 $frame_offset += 2; 2105 if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { 2106 $info['warning'][] = 'CTOS subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'; 2107 break; 2108 } 2109 $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); 2110 $frame_offset += $subframe['size']; 2111 2112 $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); 2113 $subframe['text'] = substr($subframe_rawdata, 1); 2114 $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); 2115 $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));; 2116 switch (substr($encoding_converted_text, 0, 2)) { 2117 case "\xFF\xFE": 2118 case "\xFE\xFF": 2119 switch (strtoupper($info['id3v2']['encoding'])) { 2120 case 'ISO-8859-1': 2121 case 'UTF-8': 2122 $encoding_converted_text = substr($encoding_converted_text, 2); 2123 // remove unwanted byte-order-marks 2124 break; 2125 default: 2126 // ignore 2127 break; 2128 } 2129 break; 2130 default: 2131 // do not remove BOM 2132 break; 2133 } 2134 2135 if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { 2136 if ($subframe['name'] == 'TIT2') { 2137 $parsedFrame['toc_name'] = $encoding_converted_text; 2138 } elseif ($subframe['name'] == 'TIT3') { 2139 $parsedFrame['toc_description'] = $encoding_converted_text; 2140 } 2141 $parsedFrame['subframes'][] = $subframe; 2142 } else { 2143 $info['warning'][] = 'ID3v2.CTOC subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'; 2144 } 2145 } 2146 unset($subframe_rawdata, $subframe, $encoding_converted_text); 2147 } 1946 2148 1947 2149 } … … 3345 3547 255 => "\x00\x00" 3346 3548 ); 3347 return (isset($TextEncodingTerminatorLookup[$encoding]) ? $TextEncodingTerminatorLookup[$encoding] : '');3549 return (isset($TextEncodingTerminatorLookup[$encoding]) ? $TextEncodingTerminatorLookup[$encoding] : "\x00"); 3348 3550 } 3349 3551 … … 3423 3625 3424 3626 } 3627
Note: See TracChangeset
for help on using the changeset viewer.