PageRenderTime 39ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/getid3/module.tag.id3v2.php

https://bitbucket.org/Dianoga/playlist-generator
PHP | 3327 lines | 1438 code | 335 blank | 1554 comment | 468 complexity | 15d2ac3b9113568520bb519600b40da2 MD5 | raw file
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. /////////////////////////////////////////////////////////////////
  7. // See readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. /// //
  10. // module.tag.id3v2.php //
  11. // module for analyzing ID3v2 tags //
  12. // dependencies: module.tag.id3v1.php //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
  16. class getid3_id3v2 extends getid3_handler
  17. {
  18. var $inline_attachments = true; // true: return full data for all attachments; false: return no data for all attachments; integer: return data for attachments <= than this; string: save as file to this directory
  19. var $StartingOffset = 0;
  20. function Analyze() {
  21. $info = &$this->getid3->info;
  22. // Overall tag structure:
  23. // +-----------------------------+
  24. // | Header (10 bytes) |
  25. // +-----------------------------+
  26. // | Extended Header |
  27. // | (variable length, OPTIONAL) |
  28. // +-----------------------------+
  29. // | Frames (variable length) |
  30. // +-----------------------------+
  31. // | Padding |
  32. // | (variable length, OPTIONAL) |
  33. // +-----------------------------+
  34. // | Footer (10 bytes, OPTIONAL) |
  35. // +-----------------------------+
  36. // Header
  37. // ID3v2/file identifier "ID3"
  38. // ID3v2 version $04 00
  39. // ID3v2 flags (%ab000000 in v2.2, %abc00000 in v2.3, %abcd0000 in v2.4.x)
  40. // ID3v2 size 4 * %0xxxxxxx
  41. // shortcuts
  42. $info['id3v2']['header'] = true;
  43. $thisfile_id3v2 = &$info['id3v2'];
  44. $thisfile_id3v2['flags'] = array();
  45. $thisfile_id3v2_flags = &$thisfile_id3v2['flags'];
  46. fseek($this->getid3->fp, $this->StartingOffset, SEEK_SET);
  47. $header = fread($this->getid3->fp, 10);
  48. if (substr($header, 0, 3) == 'ID3' && strlen($header) == 10) {
  49. $thisfile_id3v2['majorversion'] = ord($header{3});
  50. $thisfile_id3v2['minorversion'] = ord($header{4});
  51. // shortcut
  52. $id3v2_majorversion = &$thisfile_id3v2['majorversion'];
  53. } else {
  54. unset($info['id3v2']);
  55. return false;
  56. }
  57. if ($id3v2_majorversion > 4) { // this script probably won't correctly parse ID3v2.5.x and above (if it ever exists)
  58. $info['error'][] = 'this script only parses up to ID3v2.4.x - this tag is ID3v2.'.$id3v2_majorversion.'.'.$thisfile_id3v2['minorversion'];
  59. return false;
  60. }
  61. $id3_flags = ord($header{5});
  62. switch ($id3v2_majorversion) {
  63. case 2:
  64. // %ab000000 in v2.2
  65. $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation
  66. $thisfile_id3v2_flags['compression'] = (bool) ($id3_flags & 0x40); // b - Compression
  67. break;
  68. case 3:
  69. // %abc00000 in v2.3
  70. $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation
  71. $thisfile_id3v2_flags['exthead'] = (bool) ($id3_flags & 0x40); // b - Extended header
  72. $thisfile_id3v2_flags['experim'] = (bool) ($id3_flags & 0x20); // c - Experimental indicator
  73. break;
  74. case 4:
  75. // %abcd0000 in v2.4
  76. $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation
  77. $thisfile_id3v2_flags['exthead'] = (bool) ($id3_flags & 0x40); // b - Extended header
  78. $thisfile_id3v2_flags['experim'] = (bool) ($id3_flags & 0x20); // c - Experimental indicator
  79. $thisfile_id3v2_flags['isfooter'] = (bool) ($id3_flags & 0x10); // d - Footer present
  80. break;
  81. }
  82. $thisfile_id3v2['headerlength'] = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length
  83. $thisfile_id3v2['tag_offset_start'] = $this->StartingOffset;
  84. $thisfile_id3v2['tag_offset_end'] = $thisfile_id3v2['tag_offset_start'] + $thisfile_id3v2['headerlength'];
  85. // create 'encoding' key - used by getid3::HandleAllTags()
  86. // in ID3v2 every field can have it's own encoding type
  87. // so force everything to UTF-8 so it can be handled consistantly
  88. $thisfile_id3v2['encoding'] = 'UTF-8';
  89. // Frames
  90. // All ID3v2 frames consists of one frame header followed by one or more
  91. // fields containing the actual information. The header is always 10
  92. // bytes and laid out as follows:
  93. //
  94. // Frame ID $xx xx xx xx (four characters)
  95. // Size 4 * %0xxxxxxx
  96. // Flags $xx xx
  97. $sizeofframes = $thisfile_id3v2['headerlength'] - 10; // not including 10-byte initial header
  98. if (!empty($thisfile_id3v2['exthead']['length'])) {
  99. $sizeofframes -= ($thisfile_id3v2['exthead']['length'] + 4);
  100. }
  101. if (!empty($thisfile_id3v2_flags['isfooter'])) {
  102. $sizeofframes -= 10; // footer takes last 10 bytes of ID3v2 header, after frame data, before audio
  103. }
  104. if ($sizeofframes > 0) {
  105. $framedata = fread($this->getid3->fp, $sizeofframes); // read all frames from file into $framedata variable
  106. // if entire frame data is unsynched, de-unsynch it now (ID3v2.3.x)
  107. if (!empty($thisfile_id3v2_flags['unsynch']) && ($id3v2_majorversion <= 3)) {
  108. $framedata = $this->DeUnsynchronise($framedata);
  109. }
  110. // [in ID3v2.4.0] Unsynchronisation [S:6.1] is done on frame level, instead
  111. // of on tag level, making it easier to skip frames, increasing the streamability
  112. // of the tag. The unsynchronisation flag in the header [S:3.1] indicates that
  113. // there exists an unsynchronised frame, while the new unsynchronisation flag in
  114. // the frame header [S:4.1.2] indicates unsynchronisation.
  115. //$framedataoffset = 10 + ($thisfile_id3v2['exthead']['length'] ? $thisfile_id3v2['exthead']['length'] + 4 : 0); // how many bytes into the stream - start from after the 10-byte header (and extended header length+4, if present)
  116. $framedataoffset = 10; // how many bytes into the stream - start from after the 10-byte header
  117. // Extended Header
  118. if (!empty($thisfile_id3v2_flags['exthead'])) {
  119. $extended_header_offset = 0;
  120. if ($id3v2_majorversion == 3) {
  121. // v2.3 definition:
  122. //Extended header size $xx xx xx xx // 32-bit integer
  123. //Extended Flags $xx xx
  124. // %x0000000 %00000000 // v2.3
  125. // x - CRC data present
  126. //Size of padding $xx xx xx xx
  127. $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), 0);
  128. $extended_header_offset += 4;
  129. $thisfile_id3v2['exthead']['flag_bytes'] = 2;
  130. $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes']));
  131. $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes'];
  132. $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x8000);
  133. $thisfile_id3v2['exthead']['padding_size'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4));
  134. $extended_header_offset += 4;
  135. if ($thisfile_id3v2['exthead']['flags']['crc']) {
  136. $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4));
  137. $extended_header_offset += 4;
  138. }
  139. $extended_header_offset += $thisfile_id3v2['exthead']['padding_size'];
  140. } elseif ($id3v2_majorversion == 4) {
  141. // v2.4 definition:
  142. //Extended header size 4 * %0xxxxxxx // 28-bit synchsafe integer
  143. //Number of flag bytes $01
  144. //Extended Flags $xx
  145. // %0bcd0000 // v2.4
  146. // b - Tag is an update
  147. // Flag data length $00
  148. // c - CRC data present
  149. // Flag data length $05
  150. // Total frame CRC 5 * %0xxxxxxx
  151. // d - Tag restrictions
  152. // Flag data length $01
  153. $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), true);
  154. $extended_header_offset += 4;
  155. $thisfile_id3v2['exthead']['flag_bytes'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should always be 1
  156. $extended_header_offset += 1;
  157. $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes']));
  158. $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes'];
  159. $thisfile_id3v2['exthead']['flags']['update'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x40);
  160. $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x20);
  161. $thisfile_id3v2['exthead']['flags']['restrictions'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x10);
  162. if ($thisfile_id3v2['exthead']['flags']['update']) {
  163. $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 0
  164. $extended_header_offset += 1;
  165. }
  166. if ($thisfile_id3v2['exthead']['flags']['crc']) {
  167. $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 5
  168. $extended_header_offset += 1;
  169. $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $ext_header_chunk_length), true, false);
  170. $extended_header_offset += $ext_header_chunk_length;
  171. }
  172. if ($thisfile_id3v2['exthead']['flags']['restrictions']) {
  173. $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 1
  174. $extended_header_offset += 1;
  175. // %ppqrrstt
  176. $restrictions_raw = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1));
  177. $extended_header_offset += 1;
  178. $thisfile_id3v2['exthead']['flags']['restrictions']['tagsize'] = ($restrictions_raw & 0xC0) >> 6; // p - Tag size restrictions
  179. $thisfile_id3v2['exthead']['flags']['restrictions']['textenc'] = ($restrictions_raw & 0x20) >> 5; // q - Text encoding restrictions
  180. $thisfile_id3v2['exthead']['flags']['restrictions']['textsize'] = ($restrictions_raw & 0x18) >> 3; // r - Text fields size restrictions
  181. $thisfile_id3v2['exthead']['flags']['restrictions']['imgenc'] = ($restrictions_raw & 0x04) >> 2; // s - Image encoding restrictions
  182. $thisfile_id3v2['exthead']['flags']['restrictions']['imgsize'] = ($restrictions_raw & 0x03) >> 0; // t - Image size restrictions
  183. $thisfile_id3v2['exthead']['flags']['restrictions_text']['tagsize'] = $this->LookupExtendedHeaderRestrictionsTagSizeLimits($thisfile_id3v2['exthead']['flags']['restrictions']['tagsize']);
  184. $thisfile_id3v2['exthead']['flags']['restrictions_text']['textenc'] = $this->LookupExtendedHeaderRestrictionsTextEncodings($thisfile_id3v2['exthead']['flags']['restrictions']['textenc']);
  185. $thisfile_id3v2['exthead']['flags']['restrictions_text']['textsize'] = $this->LookupExtendedHeaderRestrictionsTextFieldSize($thisfile_id3v2['exthead']['flags']['restrictions']['textsize']);
  186. $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgenc'] = $this->LookupExtendedHeaderRestrictionsImageEncoding($thisfile_id3v2['exthead']['flags']['restrictions']['imgenc']);
  187. $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgsize'] = $this->LookupExtendedHeaderRestrictionsImageSizeSize($thisfile_id3v2['exthead']['flags']['restrictions']['imgsize']);
  188. }
  189. if ($thisfile_id3v2['exthead']['length'] != $extended_header_offset) {
  190. $info['warning'][] = 'ID3v2.4 extended header length mismatch (expecting '.intval($thisfile_id3v2['exthead']['length']).', found '.intval($extended_header_offset).')';
  191. }
  192. }
  193. $framedataoffset += $extended_header_offset;
  194. $framedata = substr($framedata, $extended_header_offset);
  195. } // end extended header
  196. while (isset($framedata) && (strlen($framedata) > 0)) { // cycle through until no more frame data is left to parse
  197. if (strlen($framedata) <= $this->ID3v2HeaderLength($id3v2_majorversion)) {
  198. // insufficient room left in ID3v2 header for actual data - must be padding
  199. $thisfile_id3v2['padding']['start'] = $framedataoffset;
  200. $thisfile_id3v2['padding']['length'] = strlen($framedata);
  201. $thisfile_id3v2['padding']['valid'] = true;
  202. for ($i = 0; $i < $thisfile_id3v2['padding']['length']; $i++) {
  203. if ($framedata{$i} != "\x00") {
  204. $thisfile_id3v2['padding']['valid'] = false;
  205. $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i;
  206. $info['warning'][] = 'Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)';
  207. break;
  208. }
  209. }
  210. break; // skip rest of ID3v2 header
  211. }
  212. if ($id3v2_majorversion == 2) {
  213. // Frame ID $xx xx xx (three characters)
  214. // Size $xx xx xx (24-bit integer)
  215. // Flags $xx xx
  216. $frame_header = substr($framedata, 0, 6); // take next 6 bytes for header
  217. $framedata = substr($framedata, 6); // and leave the rest in $framedata
  218. $frame_name = substr($frame_header, 0, 3);
  219. $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 3, 3), 0);
  220. $frame_flags = 0; // not used for anything in ID3v2.2, just set to avoid E_NOTICEs
  221. } elseif ($id3v2_majorversion > 2) {
  222. // Frame ID $xx xx xx xx (four characters)
  223. // Size $xx xx xx xx (32-bit integer in v2.3, 28-bit synchsafe in v2.4+)
  224. // Flags $xx xx
  225. $frame_header = substr($framedata, 0, 10); // take next 10 bytes for header
  226. $framedata = substr($framedata, 10); // and leave the rest in $framedata
  227. $frame_name = substr($frame_header, 0, 4);
  228. if ($id3v2_majorversion == 3) {
  229. $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer
  230. } else { // ID3v2.4+
  231. $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 1); // 32-bit synchsafe integer (28-bit value)
  232. }
  233. if ($frame_size < (strlen($framedata) + 4)) {
  234. $nextFrameID = substr($framedata, $frame_size, 4);
  235. if ($this->IsValidID3v2FrameName($nextFrameID, $id3v2_majorversion)) {
  236. // next frame is OK
  237. } elseif (($frame_name == "\x00".'MP3') || ($frame_name == "\x00\x00".'MP') || ($frame_name == ' MP3') || ($frame_name == 'MP3e')) {
  238. // MP3ext known broken frames - "ok" for the purposes of this test
  239. } elseif (($id3v2_majorversion == 4) && ($this->IsValidID3v2FrameName(substr($framedata, getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0), 4), 3))) {
  240. $info['warning'][] = 'ID3v2 tag written as ID3v2.4, but with non-synchsafe integers (ID3v2.3 style). Older versions of (Helium2; iTunes) are known culprits of this. Tag has been parsed as ID3v2.3';
  241. $id3v2_majorversion = 3;
  242. $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer
  243. }
  244. }
  245. $frame_flags = getid3_lib::BigEndian2Int(substr($frame_header, 8, 2));
  246. }
  247. if ((($id3v2_majorversion == 2) && ($frame_name == "\x00\x00\x00")) || ($frame_name == "\x00\x00\x00\x00")) {
  248. // padding encountered
  249. $thisfile_id3v2['padding']['start'] = $framedataoffset;
  250. $thisfile_id3v2['padding']['length'] = strlen($frame_header) + strlen($framedata);
  251. $thisfile_id3v2['padding']['valid'] = true;
  252. $len = strlen($framedata);
  253. for ($i = 0; $i < $len; $i++) {
  254. if ($framedata{$i} != "\x00") {
  255. $thisfile_id3v2['padding']['valid'] = false;
  256. $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i;
  257. $info['warning'][] = 'Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)';
  258. break;
  259. }
  260. }
  261. break; // skip rest of ID3v2 header
  262. }
  263. if ($frame_name == 'COM ') {
  264. $info['warning'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by iTunes (versions "X v2.0.3", "v3.0.1" are known-guilty, probably others too)]';
  265. $frame_name = 'COMM';
  266. }
  267. if (($frame_size <= strlen($framedata)) && ($this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion))) {
  268. unset($parsedFrame);
  269. $parsedFrame['frame_name'] = $frame_name;
  270. $parsedFrame['frame_flags_raw'] = $frame_flags;
  271. $parsedFrame['data'] = substr($framedata, 0, $frame_size);
  272. $parsedFrame['datalength'] = getid3_lib::CastAsInt($frame_size);
  273. $parsedFrame['dataoffset'] = $framedataoffset;
  274. $this->ParseID3v2Frame($parsedFrame);
  275. $thisfile_id3v2[$frame_name][] = $parsedFrame;
  276. $framedata = substr($framedata, $frame_size);
  277. } else { // invalid frame length or FrameID
  278. if ($frame_size <= strlen($framedata)) {
  279. if ($this->IsValidID3v2FrameName(substr($framedata, $frame_size, 4), $id3v2_majorversion)) {
  280. // next frame is valid, just skip the current frame
  281. $framedata = substr($framedata, $frame_size);
  282. $info['warning'][] = 'Next ID3v2 frame is valid, skipping current frame.';
  283. } else {
  284. // next frame is invalid too, abort processing
  285. //unset($framedata);
  286. $framedata = null;
  287. $info['error'][] = 'Next ID3v2 frame is also invalid, aborting processing.';
  288. }
  289. } elseif ($frame_size == strlen($framedata)) {
  290. // this is the last frame, just skip
  291. $info['warning'][] = 'This was the last ID3v2 frame.';
  292. } else {
  293. // next frame is invalid too, abort processing
  294. //unset($framedata);
  295. $framedata = null;
  296. $info['warning'][] = 'Invalid ID3v2 frame size, aborting.';
  297. }
  298. if (!$this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion)) {
  299. switch ($frame_name) {
  300. case "\x00\x00".'MP':
  301. case "\x00".'MP3':
  302. case ' MP3':
  303. case 'MP3e':
  304. case "\x00".'MP':
  305. case ' MP':
  306. case 'MP3':
  307. $info['warning'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by "MP3ext (www.mutschler.de/mp3ext/)"]';
  308. break;
  309. default:
  310. $info['warning'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))).';
  311. break;
  312. }
  313. } elseif (!isset($framedata) || ($frame_size > strlen($framedata))) {
  314. $info['error'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: $frame_size ('.$frame_size.') > strlen($framedata) ('.(isset($framedata) ? strlen($framedata) : 'null').')).';
  315. } else {
  316. $info['error'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag).';
  317. }
  318. }
  319. $framedataoffset += ($frame_size + $this->ID3v2HeaderLength($id3v2_majorversion));
  320. }
  321. }
  322. // Footer
  323. // The footer is a copy of the header, but with a different identifier.
  324. // ID3v2 identifier "3DI"
  325. // ID3v2 version $04 00
  326. // ID3v2 flags %abcd0000
  327. // ID3v2 size 4 * %0xxxxxxx
  328. if (isset($thisfile_id3v2_flags['isfooter']) && $thisfile_id3v2_flags['isfooter']) {
  329. $footer = fread($this->getid3->fp, 10);
  330. if (substr($footer, 0, 3) == '3DI') {
  331. $thisfile_id3v2['footer'] = true;
  332. $thisfile_id3v2['majorversion_footer'] = ord($footer{3});
  333. $thisfile_id3v2['minorversion_footer'] = ord($footer{4});
  334. }
  335. if ($thisfile_id3v2['majorversion_footer'] <= 4) {
  336. $id3_flags = ord(substr($footer{5}));
  337. $thisfile_id3v2_flags['unsynch_footer'] = (bool) ($id3_flags & 0x80);
  338. $thisfile_id3v2_flags['extfoot_footer'] = (bool) ($id3_flags & 0x40);
  339. $thisfile_id3v2_flags['experim_footer'] = (bool) ($id3_flags & 0x20);
  340. $thisfile_id3v2_flags['isfooter_footer'] = (bool) ($id3_flags & 0x10);
  341. $thisfile_id3v2['footerlength'] = getid3_lib::BigEndian2Int(substr($footer, 6, 4), 1);
  342. }
  343. } // end footer
  344. if (isset($thisfile_id3v2['comments']['genre'])) {
  345. foreach ($thisfile_id3v2['comments']['genre'] as $key => $value) {
  346. unset($thisfile_id3v2['comments']['genre'][$key]);
  347. $thisfile_id3v2['comments'] = getid3_lib::array_merge_noclobber($thisfile_id3v2['comments'], array('genre'=>$this->ParseID3v2GenreString($value)));
  348. }
  349. }
  350. if (isset($thisfile_id3v2['comments']['track'])) {
  351. foreach ($thisfile_id3v2['comments']['track'] as $key => $value) {
  352. if (strstr($value, '/')) {
  353. list($thisfile_id3v2['comments']['tracknum'][$key], $thisfile_id3v2['comments']['totaltracks'][$key]) = explode('/', $thisfile_id3v2['comments']['track'][$key]);
  354. }
  355. }
  356. }
  357. if (!isset($thisfile_id3v2['comments']['year']) && !empty($thisfile_id3v2['comments']['recording_time'][0]) && preg_match('#^([0-9]{4})#', trim($thisfile_id3v2['comments']['recording_time'][0]), $matches)) {
  358. $thisfile_id3v2['comments']['year'] = array($matches[1]);
  359. }
  360. if (!empty($thisfile_id3v2['TXXX'])) {
  361. // MediaMonkey does this, maybe others: write a blank RGAD frame, but put replay-gain adjustment values in TXXX frames
  362. foreach ($thisfile_id3v2['TXXX'] as $txxx_array) {
  363. switch ($txxx_array['description']) {
  364. case 'replaygain_track_gain':
  365. if (empty($info['replay_gain']['track']['adjustment']) && !empty($txxx_array['data'])) {
  366. $info['replay_gain']['track']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data'])));
  367. }
  368. break;
  369. case 'replaygain_track_peak':
  370. if (empty($info['replay_gain']['track']['peak']) && !empty($txxx_array['data'])) {
  371. $info['replay_gain']['track']['peak'] = floatval($txxx_array['data']);
  372. }
  373. break;
  374. case 'replaygain_album_gain':
  375. if (empty($info['replay_gain']['album']['adjustment']) && !empty($txxx_array['data'])) {
  376. $info['replay_gain']['album']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data'])));
  377. }
  378. break;
  379. }
  380. }
  381. }
  382. // Set avdataoffset
  383. $info['avdataoffset'] = $thisfile_id3v2['headerlength'];
  384. if (isset($thisfile_id3v2['footer'])) {
  385. $info['avdataoffset'] += 10;
  386. }
  387. return true;
  388. }
  389. function ParseID3v2GenreString($genrestring) {
  390. // Parse genres into arrays of genreName and genreID
  391. // ID3v2.2.x, ID3v2.3.x: '(21)' or '(4)Eurodisco' or '(51)(39)' or '(55)((I think...)'
  392. // ID3v2.4.x: '21' $00 'Eurodisco' $00
  393. $clean_genres = array();
  394. if (strpos($genrestring, "\x00") === false) {
  395. $genrestring = preg_replace('#\(([0-9]{1,3})\)#', '$1'."\x00", $genrestring);
  396. }
  397. $genre_elements = explode("\x00", $genrestring);
  398. foreach ($genre_elements as $element) {
  399. $element = trim($element);
  400. if ($element) {
  401. if (preg_match('#^[0-9]{1,3}#', $element)) {
  402. $clean_genres[] = getid3_id3v1::LookupGenreName($element);
  403. } else {
  404. $clean_genres[] = str_replace('((', '(', $element);
  405. }
  406. }
  407. }
  408. return $clean_genres;
  409. }
  410. function ParseID3v2Frame(&$parsedFrame) {
  411. // shortcuts
  412. $info = &$this->getid3->info;
  413. $id3v2_majorversion = $info['id3v2']['majorversion'];
  414. $parsedFrame['framenamelong'] = $this->FrameNameLongLookup($parsedFrame['frame_name']);
  415. if (empty($parsedFrame['framenamelong'])) {
  416. unset($parsedFrame['framenamelong']);
  417. }
  418. $parsedFrame['framenameshort'] = $this->FrameNameShortLookup($parsedFrame['frame_name']);
  419. if (empty($parsedFrame['framenameshort'])) {
  420. unset($parsedFrame['framenameshort']);
  421. }
  422. if ($id3v2_majorversion >= 3) { // frame flags are not part of the ID3v2.2 standard
  423. if ($id3v2_majorversion == 3) {
  424. // Frame Header Flags
  425. // %abc00000 %ijk00000
  426. $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x8000); // a - Tag alter preservation
  427. $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // b - File alter preservation
  428. $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // c - Read only
  429. $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0080); // i - Compression
  430. $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // j - Encryption
  431. $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0020); // k - Grouping identity
  432. } elseif ($id3v2_majorversion == 4) {
  433. // Frame Header Flags
  434. // %0abc0000 %0h00kmnp
  435. $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // a - Tag alter preservation
  436. $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // b - File alter preservation
  437. $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x1000); // c - Read only
  438. $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // h - Grouping identity
  439. $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0008); // k - Compression
  440. $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0004); // m - Encryption
  441. $parsedFrame['flags']['Unsynchronisation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0002); // n - Unsynchronisation
  442. $parsedFrame['flags']['DataLengthIndicator'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0001); // p - Data length indicator
  443. // Frame-level de-unsynchronisation - ID3v2.4
  444. if ($parsedFrame['flags']['Unsynchronisation']) {
  445. $parsedFrame['data'] = $this->DeUnsynchronise($parsedFrame['data']);
  446. }
  447. if ($parsedFrame['flags']['DataLengthIndicator']) {
  448. $parsedFrame['data_length_indicator'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4), 1);
  449. $parsedFrame['data'] = substr($parsedFrame['data'], 4);
  450. }
  451. }
  452. // Frame-level de-compression
  453. if ($parsedFrame['flags']['compression']) {
  454. $parsedFrame['decompressed_size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4));
  455. if (!function_exists('gzuncompress')) {
  456. $info['warning'][] = 'gzuncompress() support required to decompress ID3v2 frame "'.$parsedFrame['frame_name'].'"';
  457. } else {
  458. if ($decompresseddata = @gzuncompress(substr($parsedFrame['data'], 4))) {
  459. //if ($decompresseddata = @gzuncompress($parsedFrame['data'])) {
  460. $parsedFrame['data'] = $decompresseddata;
  461. unset($decompresseddata);
  462. } else {
  463. $info['warning'][] = 'gzuncompress() failed on compressed contents of ID3v2 frame "'.$parsedFrame['frame_name'].'"';
  464. }
  465. }
  466. }
  467. }
  468. if (!empty($parsedFrame['flags']['DataLengthIndicator'])) {
  469. if ($parsedFrame['data_length_indicator'] != strlen($parsedFrame['data'])) {
  470. $info['warning'][] = 'ID3v2 frame "'.$parsedFrame['frame_name'].'" should be '.$parsedFrame['data_length_indicator'].' bytes long according to DataLengthIndicator, but found '.strlen($parsedFrame['data']).' bytes of data';
  471. }
  472. }
  473. if (isset($parsedFrame['datalength']) && ($parsedFrame['datalength'] == 0)) {
  474. $warning = 'Frame "'.$parsedFrame['frame_name'].'" at offset '.$parsedFrame['dataoffset'].' has no data portion';
  475. switch ($parsedFrame['frame_name']) {
  476. case 'WCOM':
  477. $warning .= ' (this is known to happen with files tagged by RioPort)';
  478. break;
  479. default:
  480. break;
  481. }
  482. $info['warning'][] = $warning;
  483. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'UFID')) || // 4.1 UFID Unique file identifier
  484. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'UFI'))) { // 4.1 UFI Unique file identifier
  485. // There may be more than one 'UFID' frame in a tag,
  486. // but only one with the same 'Owner identifier'.
  487. // <Header for 'Unique file identifier', ID: 'UFID'>
  488. // Owner identifier <text string> $00
  489. // Identifier <up to 64 bytes binary data>
  490. $exploded = explode("\x00", $parsedFrame['data'], 2);
  491. $parsedFrame['ownerid'] = (isset($exploded[0]) ? $exploded[0] : '');
  492. $parsedFrame['data'] = (isset($exploded[1]) ? $exploded[1] : '');
  493. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'TXXX')) || // 4.2.2 TXXX User defined text information frame
  494. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'TXX'))) { // 4.2.2 TXX User defined text information frame
  495. // There may be more than one 'TXXX' frame in each tag,
  496. // but only one with the same description.
  497. // <Header for 'User defined text information frame', ID: 'TXXX'>
  498. // Text encoding $xx
  499. // Description <text string according to encoding> $00 (00)
  500. // Value <text string according to encoding>
  501. $frame_offset = 0;
  502. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  503. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  504. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  505. }
  506. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  507. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  508. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  509. }
  510. $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  511. if (ord($frame_description) === 0) {
  512. $frame_description = '';
  513. }
  514. $parsedFrame['encodingid'] = $frame_textencoding;
  515. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  516. $parsedFrame['description'] = $frame_description;
  517. $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
  518. if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
  519. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']));
  520. }
  521. //unset($parsedFrame['data']); do not unset, may be needed elsewhere, e.g. for replaygain
  522. } elseif ($parsedFrame['frame_name']{0} == 'T') { // 4.2. T??[?] Text information frame
  523. // There may only be one text information frame of its kind in an tag.
  524. // <Header for 'Text information frame', ID: 'T000' - 'TZZZ',
  525. // excluding 'TXXX' described in 4.2.6.>
  526. // Text encoding $xx
  527. // Information <text string(s) according to encoding>
  528. $frame_offset = 0;
  529. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  530. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  531. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  532. }
  533. $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
  534. $parsedFrame['encodingid'] = $frame_textencoding;
  535. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  536. if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
  537. $string = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
  538. $string = rtrim($string, "\x00"); // remove possible terminating null (put by encoding id or software bug)
  539. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $string;
  540. unset($string);
  541. }
  542. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'WXXX')) || // 4.3.2 WXXX User defined URL link frame
  543. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'WXX'))) { // 4.3.2 WXX User defined URL link frame
  544. // There may be more than one 'WXXX' frame in each tag,
  545. // but only one with the same description
  546. // <Header for 'User defined URL link frame', ID: 'WXXX'>
  547. // Text encoding $xx
  548. // Description <text string according to encoding> $00 (00)
  549. // URL <text string>
  550. $frame_offset = 0;
  551. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  552. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  553. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  554. }
  555. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  556. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  557. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  558. }
  559. $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  560. if (ord($frame_description) === 0) {
  561. $frame_description = '';
  562. }
  563. $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
  564. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding));
  565. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  566. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  567. }
  568. if ($frame_terminatorpos) {
  569. // there are null bytes after the data - this is not according to spec
  570. // only use data up to first null byte
  571. $frame_urldata = (string) substr($parsedFrame['data'], 0, $frame_terminatorpos);
  572. } else {
  573. // no null bytes following data, just use all data
  574. $frame_urldata = (string) $parsedFrame['data'];
  575. }
  576. $parsedFrame['encodingid'] = $frame_textencoding;
  577. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  578. $parsedFrame['url'] = $frame_urldata;
  579. $parsedFrame['description'] = $frame_description;
  580. if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) {
  581. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['url']);
  582. }
  583. unset($parsedFrame['data']);
  584. } elseif ($parsedFrame['frame_name']{0} == 'W') { // 4.3. W??? URL link frames
  585. // There may only be one URL link frame of its kind in a tag,
  586. // except when stated otherwise in the frame description
  587. // <Header for 'URL link frame', ID: 'W000' - 'WZZZ', excluding 'WXXX'
  588. // described in 4.3.2.>
  589. // URL <text string>
  590. $parsedFrame['url'] = trim($parsedFrame['data']);
  591. if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) {
  592. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['url'];
  593. }
  594. unset($parsedFrame['data']);
  595. } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'IPLS')) || // 4.4 IPLS Involved people list (ID3v2.3 only)
  596. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'IPL'))) { // 4.4 IPL Involved people list (ID3v2.2 only)
  597. // There may only be one 'IPL' frame in each tag
  598. // <Header for 'User defined URL link frame', ID: 'IPL'>
  599. // Text encoding $xx
  600. // People list strings <textstrings>
  601. $frame_offset = 0;
  602. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  603. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  604. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  605. }
  606. $parsedFrame['encodingid'] = $frame_textencoding;
  607. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($parsedFrame['encodingid']);
  608. $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
  609. if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
  610. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
  611. }
  612. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MCDI')) || // 4.4 MCDI Music CD identifier
  613. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MCI'))) { // 4.5 MCI Music CD identifier
  614. // There may only be one 'MCDI' frame in each tag
  615. // <Header for 'Music CD identifier', ID: 'MCDI'>
  616. // CD TOC <binary data>
  617. if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
  618. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data'];
  619. }
  620. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ETCO')) || // 4.5 ETCO Event timing codes
  621. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ETC'))) { // 4.6 ETC Event timing codes
  622. // There may only be one 'ETCO' frame in each tag
  623. // <Header for 'Event timing codes', ID: 'ETCO'>
  624. // Time stamp format $xx
  625. // Where time stamp format is:
  626. // $01 (32-bit value) MPEG frames from beginning of file
  627. // $02 (32-bit value) milliseconds from beginning of file
  628. // Followed by a list of key events in the following format:
  629. // Type of event $xx
  630. // Time stamp $xx (xx ...)
  631. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  632. // or after the previous event. All events MUST be sorted in chronological order.
  633. $frame_offset = 0;
  634. $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  635. while ($frame_offset < strlen($parsedFrame['data'])) {
  636. $parsedFrame['typeid'] = substr($parsedFrame['data'], $frame_offset++, 1);
  637. $parsedFrame['type'] = $this->ETCOEventLookup($parsedFrame['typeid']);
  638. $parsedFrame['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
  639. $frame_offset += 4;
  640. }
  641. unset($parsedFrame['data']);
  642. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MLLT')) || // 4.6 MLLT MPEG location lookup table
  643. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MLL'))) { // 4.7 MLL MPEG location lookup table
  644. // There may only be one 'MLLT' frame in each tag
  645. // <Header for 'Location lookup table', ID: 'MLLT'>
  646. // MPEG frames between reference $xx xx
  647. // Bytes between reference $xx xx xx
  648. // Milliseconds between reference $xx xx xx
  649. // Bits for bytes deviation $xx
  650. // Bits for milliseconds dev. $xx
  651. // Then for every reference the following data is included;
  652. // Deviation in bytes %xxx....
  653. // Deviation in milliseconds %xxx....
  654. $frame_offset = 0;
  655. $parsedFrame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 2));
  656. $parsedFrame['bytesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 2, 3));
  657. $parsedFrame['msbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 5, 3));
  658. $parsedFrame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1));
  659. $parsedFrame['bitsformsdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1));
  660. $parsedFrame['data'] = substr($parsedFrame['data'], 10);
  661. while ($frame_offset < strlen($parsedFrame['data'])) {
  662. $deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1));
  663. }
  664. $reference_counter = 0;
  665. while (strlen($deviationbitstream) > 0) {
  666. $parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation']));
  667. $parsedFrame[$reference_counter]['msdeviation'] = bindec(substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'], $parsedFrame['bitsformsdeviation']));
  668. $deviationbitstream = substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']);
  669. $reference_counter++;
  670. }
  671. unset($parsedFrame['data']);
  672. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYTC')) || // 4.7 SYTC Synchronised tempo codes
  673. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'STC'))) { // 4.8 STC Synchronised tempo codes
  674. // There may only be one 'SYTC' frame in each tag
  675. // <Header for 'Synchronised tempo codes', ID: 'SYTC'>
  676. // Time stamp format $xx
  677. // Tempo data <binary data>
  678. // Where time stamp format is:
  679. // $01 (32-bit value) MPEG frames from beginning of file
  680. // $02 (32-bit value) milliseconds from beginning of file
  681. $frame_offset = 0;
  682. $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  683. $timestamp_counter = 0;
  684. while ($frame_offset < strlen($parsedFrame['data'])) {
  685. $parsedFrame[$timestamp_counter]['tempo'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  686. if ($parsedFrame[$timestamp_counter]['tempo'] == 255) {
  687. $parsedFrame[$timestamp_counter]['tempo'] += ord(substr($parsedFrame['data'], $frame_offset++, 1));
  688. }
  689. $parsedFrame[$timestamp_counter]['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
  690. $frame_offset += 4;
  691. $timestamp_counter++;
  692. }
  693. unset($parsedFrame['data']);
  694. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USLT')) || // 4.8 USLT Unsynchronised lyric/text transcription
  695. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ULT'))) { // 4.9 ULT Unsynchronised lyric/text transcription
  696. // There may be more than one 'Unsynchronised lyrics/text transcription' frame
  697. // in each tag, but only one with the same language and content descriptor.
  698. // <Header for 'Unsynchronised lyrics/text transcription', ID: 'USLT'>
  699. // Text encoding $xx
  700. // Language $xx xx xx
  701. // Content descriptor <text string according to encoding> $00 (00)
  702. // Lyrics/text <full text string according to encoding>
  703. $frame_offset = 0;
  704. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  705. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  706. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  707. }
  708. $frame_language = substr($parsedFrame['data'], $frame_offset, 3);
  709. $frame_offset += 3;
  710. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  711. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  712. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  713. }
  714. $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  715. if (ord($frame_description) === 0) {
  716. $frame_description = '';
  717. }
  718. $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
  719. $parsedFrame['encodingid'] = $frame_textencoding;
  720. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  721. $parsedFrame['data'] = $parsedFrame['data'];
  722. $parsedFrame['language'] = $frame_language;
  723. $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false);
  724. $parsedFrame['description'] = $frame_description;
  725. if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
  726. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
  727. }
  728. unset($parsedFrame['data']);
  729. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYLT')) || // 4.9 SYLT Synchronised lyric/text
  730. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'SLT'))) { // 4.10 SLT Synchronised lyric/text
  731. // There may be more than one 'SYLT' frame in each tag,
  732. // but only one with the same language and content descriptor.
  733. // <Header for 'Synchronised lyrics/text', ID: 'SYLT'>
  734. // Text encoding $xx
  735. // Language $xx xx xx
  736. // Time stamp format $xx
  737. // $01 (32-bit value) MPEG frames from beginning of file
  738. // $02 (32-bit value) milliseconds from beginning of file
  739. // Content type $xx
  740. // Content descriptor <text string according to encoding> $00 (00)
  741. // Terminated text to be synced (typically a syllable)
  742. // Sync identifier (terminator to above string) $00 (00)
  743. // Time stamp $xx (xx ...)
  744. $frame_offset = 0;
  745. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  746. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  747. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  748. }
  749. $frame_language = substr($parsedFrame['data'], $frame_offset, 3);
  750. $frame_offset += 3;
  751. $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  752. $parsedFrame['contenttypeid'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  753. $parsedFrame['contenttype'] = $this->SYTLContentTypeLookup($parsedFrame['contenttypeid']);
  754. $parsedFrame['encodingid'] = $frame_textencoding;
  755. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  756. $parsedFrame['language'] = $frame_language;
  757. $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false);
  758. $timestampindex = 0;
  759. $frame_remainingdata = substr($parsedFrame['data'], $frame_offset);
  760. while (strlen($frame_remainingdata)) {
  761. $frame_offset = 0;
  762. $frame_terminatorpos = strpos($frame_remainingdata, $this->TextEncodingTerminatorLookup($frame_textencoding));
  763. if ($frame_terminatorpos === false) {
  764. $frame_remainingdata = '';
  765. } else {
  766. if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  767. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  768. }
  769. $parsedFrame['lyrics'][$timestampindex]['data'] = substr($frame_remainingdata, $frame_offset, $frame_terminatorpos - $frame_offset);
  770. $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
  771. if (($timestampindex == 0) && (ord($frame_remainingdata{0}) != 0)) {
  772. // timestamp probably omitted for first data item
  773. } else {
  774. $parsedFrame['lyrics'][$timestampindex]['timestamp'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 4));
  775. $frame_remainingdata = substr($frame_remainingdata, 4);
  776. }
  777. $timestampindex++;
  778. }
  779. }
  780. unset($parsedFrame['data']);
  781. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMM')) || // 4.10 COMM Comments
  782. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'COM'))) { // 4.11 COM Comments
  783. // There may be more than one comment frame in each tag,
  784. // but only one with the same language and content descriptor.
  785. // <Header for 'Comment', ID: 'COMM'>
  786. // Text encoding $xx
  787. // Language $xx xx xx
  788. // Short content descrip. <text string according to encoding> $00 (00)
  789. // The actual text <full text string according to encoding>
  790. if (strlen($parsedFrame['data']) < 5) {
  791. $info['warning'][] = 'Invalid data (too short) for "'.$parsedFrame['frame_name'].'" frame at offset '.$parsedFrame['dataoffset'];
  792. } else {
  793. $frame_offset = 0;
  794. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  795. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  796. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  797. }
  798. $frame_language = substr($parsedFrame['data'], $frame_offset, 3);
  799. $frame_offset += 3;
  800. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  801. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  802. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  803. }
  804. $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  805. if (ord($frame_description) === 0) {
  806. $frame_description = '';
  807. }
  808. $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
  809. $parsedFrame['encodingid'] = $frame_textencoding;
  810. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  811. $parsedFrame['language'] = $frame_language;
  812. $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false);
  813. $parsedFrame['description'] = $frame_description;
  814. $parsedFrame['data'] = $frame_text;
  815. if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
  816. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
  817. }
  818. }
  819. } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'RVA2')) { // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only)
  820. // There may be more than one 'RVA2' frame in each tag,
  821. // but only one with the same identification string
  822. // <Header for 'Relative volume adjustment (2)', ID: 'RVA2'>
  823. // Identification <text string> $00
  824. // The 'identification' string is used to identify the situation and/or
  825. // device where this adjustment should apply. The following is then
  826. // repeated for every channel:
  827. // Type of channel $xx
  828. // Volume adjustment $xx xx
  829. // Bits representing peak $xx
  830. // Peak volume $xx (xx ...)
  831. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00");
  832. $frame_idstring = substr($parsedFrame['data'], 0, $frame_terminatorpos);
  833. if (ord($frame_idstring) === 0) {
  834. $frame_idstring = '';
  835. }
  836. $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00"));
  837. $parsedFrame['description'] = $frame_idstring;
  838. $RVA2channelcounter = 0;
  839. while (strlen($frame_remainingdata) >= 5) {
  840. $frame_offset = 0;
  841. $frame_channeltypeid = ord(substr($frame_remainingdata, $frame_offset++, 1));
  842. $parsedFrame[$RVA2channelcounter]['channeltypeid'] = $frame_channeltypeid;
  843. $parsedFrame[$RVA2channelcounter]['channeltype'] = $this->RVA2ChannelTypeLookup($frame_channeltypeid);
  844. $parsedFrame[$RVA2channelcounter]['volumeadjust'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, 2), false, true); // 16-bit signed
  845. $frame_offset += 2;
  846. $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] = ord(substr($frame_remainingdata, $frame_offset++, 1));
  847. if (($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] < 1) || ($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] > 4)) {
  848. $info['warning'][] = 'ID3v2::RVA2 frame['.$RVA2channelcounter.'] contains invalid '.$parsedFrame[$RVA2channelcounter]['bitspeakvolume'].'-byte bits-representing-peak value';
  849. break;
  850. }
  851. $frame_bytespeakvolume = ceil($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] / 8);
  852. $parsedFrame[$RVA2channelcounter]['peakvolume'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, $frame_bytespeakvolume));
  853. $frame_remainingdata = substr($frame_remainingdata, $frame_offset + $frame_bytespeakvolume);
  854. $RVA2channelcounter++;
  855. }
  856. unset($parsedFrame['data']);
  857. } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'RVAD')) || // 4.12 RVAD Relative volume adjustment (ID3v2.3 only)
  858. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'RVA'))) { // 4.12 RVA Relative volume adjustment (ID3v2.2 only)
  859. // There may only be one 'RVA' frame in each tag
  860. // <Header for 'Relative volume adjustment', ID: 'RVA'>
  861. // ID3v2.2 => Increment/decrement %000000ba
  862. // ID3v2.3 => Increment/decrement %00fedcba
  863. // Bits used for volume descr. $xx
  864. // Relative volume change, right $xx xx (xx ...) // a
  865. // Relative volume change, left $xx xx (xx ...) // b
  866. // Peak volume right $xx xx (xx ...)
  867. // Peak volume left $xx xx (xx ...)
  868. // ID3v2.3 only, optional (not present in ID3v2.2):
  869. // Relative volume change, right back $xx xx (xx ...) // c
  870. // Relative volume change, left back $xx xx (xx ...) // d
  871. // Peak volume right back $xx xx (xx ...)
  872. // Peak volume left back $xx xx (xx ...)
  873. // ID3v2.3 only, optional (not present in ID3v2.2):
  874. // Relative volume change, center $xx xx (xx ...) // e
  875. // Peak volume center $xx xx (xx ...)
  876. // ID3v2.3 only, optional (not present in ID3v2.2):
  877. // Relative volume change, bass $xx xx (xx ...) // f
  878. // Peak volume bass $xx xx (xx ...)
  879. $frame_offset = 0;
  880. $frame_incrdecrflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1));
  881. $parsedFrame['incdec']['right'] = (bool) substr($frame_incrdecrflags, 6, 1);
  882. $parsedFrame['incdec']['left'] = (bool) substr($frame_incrdecrflags, 7, 1);
  883. $parsedFrame['bitsvolume'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  884. $frame_bytesvolume = ceil($parsedFrame['bitsvolume'] / 8);
  885. $parsedFrame['volumechange']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  886. if ($parsedFrame['incdec']['right'] === false) {
  887. $parsedFrame['volumechange']['right'] *= -1;
  888. }
  889. $frame_offset += $frame_bytesvolume;
  890. $parsedFrame['volumechange']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  891. if ($parsedFrame['incdec']['left'] === false) {
  892. $parsedFrame['volumechange']['left'] *= -1;
  893. }
  894. $frame_offset += $frame_bytesvolume;
  895. $parsedFrame['peakvolume']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  896. $frame_offset += $frame_bytesvolume;
  897. $parsedFrame['peakvolume']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  898. $frame_offset += $frame_bytesvolume;
  899. if ($id3v2_majorversion == 3) {
  900. $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset);
  901. if (strlen($parsedFrame['data']) > 0) {
  902. $parsedFrame['incdec']['rightrear'] = (bool) substr($frame_incrdecrflags, 4, 1);
  903. $parsedFrame['incdec']['leftrear'] = (bool) substr($frame_incrdecrflags, 5, 1);
  904. $parsedFrame['volumechange']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  905. if ($parsedFrame['incdec']['rightrear'] === false) {
  906. $parsedFrame['volumechange']['rightrear'] *= -1;
  907. }
  908. $frame_offset += $frame_bytesvolume;
  909. $parsedFrame['volumechange']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  910. if ($parsedFrame['incdec']['leftrear'] === false) {
  911. $parsedFrame['volumechange']['leftrear'] *= -1;
  912. }
  913. $frame_offset += $frame_bytesvolume;
  914. $parsedFrame['peakvolume']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  915. $frame_offset += $frame_bytesvolume;
  916. $parsedFrame['peakvolume']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  917. $frame_offset += $frame_bytesvolume;
  918. }
  919. $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset);
  920. if (strlen($parsedFrame['data']) > 0) {
  921. $parsedFrame['incdec']['center'] = (bool) substr($frame_incrdecrflags, 3, 1);
  922. $parsedFrame['volumechange']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  923. if ($parsedFrame['incdec']['center'] === false) {
  924. $parsedFrame['volumechange']['center'] *= -1;
  925. }
  926. $frame_offset += $frame_bytesvolume;
  927. $parsedFrame['peakvolume']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  928. $frame_offset += $frame_bytesvolume;
  929. }
  930. $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset);
  931. if (strlen($parsedFrame['data']) > 0) {
  932. $parsedFrame['incdec']['bass'] = (bool) substr($frame_incrdecrflags, 2, 1);
  933. $parsedFrame['volumechange']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  934. if ($parsedFrame['incdec']['bass'] === false) {
  935. $parsedFrame['volumechange']['bass'] *= -1;
  936. }
  937. $frame_offset += $frame_bytesvolume;
  938. $parsedFrame['peakvolume']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
  939. $frame_offset += $frame_bytesvolume;
  940. }
  941. }
  942. unset($parsedFrame['data']);
  943. } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'EQU2')) { // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only)
  944. // There may be more than one 'EQU2' frame in each tag,
  945. // but only one with the same identification string
  946. // <Header of 'Equalisation (2)', ID: 'EQU2'>
  947. // Interpolation method $xx
  948. // $00 Band
  949. // $01 Linear
  950. // Identification <text string> $00
  951. // The following is then repeated for every adjustment point
  952. // Frequency $xx xx
  953. // Volume adjustment $xx xx
  954. $frame_offset = 0;
  955. $frame_interpolationmethod = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  956. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  957. $frame_idstring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  958. if (ord($frame_idstring) === 0) {
  959. $frame_idstring = '';
  960. }
  961. $parsedFrame['description'] = $frame_idstring;
  962. $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00"));
  963. while (strlen($frame_remainingdata)) {
  964. $frame_frequency = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 2)) / 2;
  965. $parsedFrame['data'][$frame_frequency] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, 2), false, true);
  966. $frame_remainingdata = substr($frame_remainingdata, 4);
  967. }
  968. $parsedFrame['interpolationmethod'] = $frame_interpolationmethod;
  969. unset($parsedFrame['data']);
  970. } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'EQUA')) || // 4.12 EQUA Equalisation (ID3v2.3 only)
  971. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'EQU'))) { // 4.13 EQU Equalisation (ID3v2.2 only)
  972. // There may only be one 'EQUA' frame in each tag
  973. // <Header for 'Relative volume adjustment', ID: 'EQU'>
  974. // Adjustment bits $xx
  975. // This is followed by 2 bytes + ('adjustment bits' rounded up to the
  976. // nearest byte) for every equalisation band in the following format,
  977. // giving a frequency range of 0 - 32767Hz:
  978. // Increment/decrement %x (MSB of the Frequency)
  979. // Frequency (lower 15 bits)
  980. // Adjustment $xx (xx ...)
  981. $frame_offset = 0;
  982. $parsedFrame['adjustmentbits'] = substr($parsedFrame['data'], $frame_offset++, 1);
  983. $frame_adjustmentbytes = ceil($parsedFrame['adjustmentbits'] / 8);
  984. $frame_remainingdata = (string) substr($parsedFrame['data'], $frame_offset);
  985. while (strlen($frame_remainingdata) > 0) {
  986. $frame_frequencystr = getid3_lib::BigEndian2Bin(substr($frame_remainingdata, 0, 2));
  987. $frame_incdec = (bool) substr($frame_frequencystr, 0, 1);
  988. $frame_frequency = bindec(substr($frame_frequencystr, 1, 15));
  989. $parsedFrame[$frame_frequency]['incdec'] = $frame_incdec;
  990. $parsedFrame[$frame_frequency]['adjustment'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, $frame_adjustmentbytes));
  991. if ($parsedFrame[$frame_frequency]['incdec'] === false) {
  992. $parsedFrame[$frame_frequency]['adjustment'] *= -1;
  993. }
  994. $frame_remainingdata = substr($frame_remainingdata, 2 + $frame_adjustmentbytes);
  995. }
  996. unset($parsedFrame['data']);
  997. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RVRB')) || // 4.13 RVRB Reverb
  998. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'REV'))) { // 4.14 REV Reverb
  999. // There may only be one 'RVRB' frame in each tag.
  1000. // <Header for 'Reverb', ID: 'RVRB'>
  1001. // Reverb left (ms) $xx xx
  1002. // Reverb right (ms) $xx xx
  1003. // Reverb bounces, left $xx
  1004. // Reverb bounces, right $xx
  1005. // Reverb feedback, left to left $xx
  1006. // Reverb feedback, left to right $xx
  1007. // Reverb feedback, right to right $xx
  1008. // Reverb feedback, right to left $xx
  1009. // Premix left to right $xx
  1010. // Premix right to left $xx
  1011. $frame_offset = 0;
  1012. $parsedFrame['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
  1013. $frame_offset += 2;
  1014. $parsedFrame['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
  1015. $frame_offset += 2;
  1016. $parsedFrame['bouncesL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1017. $parsedFrame['bouncesR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1018. $parsedFrame['feedbackLL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1019. $parsedFrame['feedbackLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1020. $parsedFrame['feedbackRR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1021. $parsedFrame['feedbackRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1022. $parsedFrame['premixLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1023. $parsedFrame['premixRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1024. unset($parsedFrame['data']);
  1025. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'APIC')) || // 4.14 APIC Attached picture
  1026. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'PIC'))) { // 4.15 PIC Attached picture
  1027. // There may be several pictures attached to one file,
  1028. // each in their individual 'APIC' frame, but only one
  1029. // with the same content descriptor
  1030. // <Header for 'Attached picture', ID: 'APIC'>
  1031. // Text encoding $xx
  1032. // ID3v2.3+ => MIME type <text string> $00
  1033. // ID3v2.2 => Image format $xx xx xx
  1034. // Picture type $xx
  1035. // Description <text string according to encoding> $00 (00)
  1036. // Picture data <binary data>
  1037. $frame_offset = 0;
  1038. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1039. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  1040. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  1041. }
  1042. if ($id3v2_majorversion == 2 && strlen($parsedFrame['data']) > $frame_offset) {
  1043. $frame_imagetype = substr($parsedFrame['data'], $frame_offset, 3);
  1044. if (strtolower($frame_imagetype) == 'ima') {
  1045. // complete hack for mp3Rage (www.chaoticsoftware.com) that puts ID3v2.3-formatted
  1046. // MIME type instead of 3-char ID3v2.2-format image type (thanks xbhoffŘpacbell*net)
  1047. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1048. $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1049. if (ord($frame_mimetype) === 0) {
  1050. $frame_mimetype = '';
  1051. }
  1052. $frame_imagetype = strtoupper(str_replace('image/', '', strtolower($frame_mimetype)));
  1053. if ($frame_imagetype == 'JPEG') {
  1054. $frame_imagetype = 'JPG';
  1055. }
  1056. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1057. } else {
  1058. $frame_offset += 3;
  1059. }
  1060. }
  1061. if ($id3v2_majorversion > 2 && strlen($parsedFrame['data']) > $frame_offset) {
  1062. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1063. $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1064. if (ord($frame_mimetype) === 0) {
  1065. $frame_mimetype = '';
  1066. }
  1067. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1068. }
  1069. $frame_picturetype = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1070. if ($frame_offset >= $parsedFrame['datalength']) {
  1071. $info['warning'][] = 'data portion of APIC frame is missing at offset '.($parsedFrame['dataoffset'] + 8 + $frame_offset);
  1072. } else {
  1073. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  1074. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  1075. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  1076. }
  1077. $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1078. if (ord($frame_description) === 0) {
  1079. $frame_description = '';
  1080. }
  1081. $parsedFrame['encodingid'] = $frame_textencoding;
  1082. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  1083. if ($id3v2_majorversion == 2) {
  1084. $parsedFrame['imagetype'] = $frame_imagetype;
  1085. } else {
  1086. $parsedFrame['mime'] = $frame_mimetype;
  1087. }
  1088. $parsedFrame['picturetypeid'] = $frame_picturetype;
  1089. $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype);
  1090. $parsedFrame['description'] = $frame_description;
  1091. $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
  1092. $parsedFrame['datalength'] = strlen($parsedFrame['data']);
  1093. $parsedFrame['image_mime'] = '';
  1094. $imageinfo = array();
  1095. $imagechunkcheck = getid3_lib::GetDataImageSize($parsedFrame['data'], $imageinfo);
  1096. if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) {
  1097. $parsedFrame['image_mime'] = 'image/'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]);
  1098. if ($imagechunkcheck[0]) {
  1099. $parsedFrame['image_width'] = $imagechunkcheck[0];
  1100. }
  1101. if ($imagechunkcheck[1]) {
  1102. $parsedFrame['image_height'] = $imagechunkcheck[1];
  1103. }
  1104. }
  1105. do {
  1106. if ($this->inline_attachments === false) {
  1107. // skip entirely
  1108. unset($parsedFrame['data']);
  1109. break;
  1110. }
  1111. if ($this->inline_attachments === true) {
  1112. // great
  1113. } elseif (is_int($this->inline_attachments)) {
  1114. if ($this->inline_attachments < $parsedFrame['data_length']) {
  1115. // too big, skip
  1116. $info['warning'][] = 'attachment at '.$frame_offset.' is too large to process inline ('.number_format($parsedFrame['data_length']).' bytes)';
  1117. unset($parsedFrame['data']);
  1118. break;
  1119. }
  1120. } elseif (is_string($this->inline_attachments)) {
  1121. $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
  1122. if (!is_dir($this->inline_attachments) || !is_writable($this->inline_attachments)) {
  1123. // cannot write, skip
  1124. $info['warning'][] = 'attachment at '.$frame_offset.' cannot be saved to "'.$this->inline_attachments.'" (not writable)';
  1125. unset($parsedFrame['data']);
  1126. break;
  1127. }
  1128. }
  1129. // if we get this far, must be OK
  1130. if (is_string($this->inline_attachments)) {
  1131. $destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$frame_offset;
  1132. if (!file_exists($destination_filename) || is_writable($destination_filename)) {
  1133. file_put_contents($destination_filename, $parsedFrame['data']);
  1134. } else {
  1135. $info['warning'][] = 'attachment at '.$frame_offset.' cannot be saved to "'.$destination_filename.'" (not writable)';
  1136. }
  1137. $parsedFrame['data_filename'] = $destination_filename;
  1138. unset($parsedFrame['data']);
  1139. } else {
  1140. if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
  1141. if (!isset($info['id3v2']['comments']['picture'])) {
  1142. $info['id3v2']['comments']['picture'] = array();
  1143. }
  1144. $info['id3v2']['comments']['picture'][] = array('data'=>$parsedFrame['data'], 'image_mime'=>$parsedFrame['image_mime']);
  1145. }
  1146. }
  1147. } while (false);
  1148. }
  1149. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GEOB')) || // 4.15 GEOB General encapsulated object
  1150. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'GEO'))) { // 4.16 GEO General encapsulated object
  1151. // There may be more than one 'GEOB' frame in each tag,
  1152. // but only one with the same content descriptor
  1153. // <Header for 'General encapsulated object', ID: 'GEOB'>
  1154. // Text encoding $xx
  1155. // MIME type <text string> $00
  1156. // Filename <text string according to encoding> $00 (00)
  1157. // Content description <text string according to encoding> $00 (00)
  1158. // Encapsulated object <binary data>
  1159. $frame_offset = 0;
  1160. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1161. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  1162. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  1163. }
  1164. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1165. $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1166. if (ord($frame_mimetype) === 0) {
  1167. $frame_mimetype = '';
  1168. }
  1169. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1170. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  1171. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  1172. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  1173. }
  1174. $frame_filename = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1175. if (ord($frame_filename) === 0) {
  1176. $frame_filename = '';
  1177. }
  1178. $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding));
  1179. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  1180. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  1181. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  1182. }
  1183. $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1184. if (ord($frame_description) === 0) {
  1185. $frame_description = '';
  1186. }
  1187. $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding));
  1188. $parsedFrame['objectdata'] = (string) substr($parsedFrame['data'], $frame_offset);
  1189. $parsedFrame['encodingid'] = $frame_textencoding;
  1190. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  1191. $parsedFrame['mime'] = $frame_mimetype;
  1192. $parsedFrame['filename'] = $frame_filename;
  1193. $parsedFrame['description'] = $frame_description;
  1194. unset($parsedFrame['data']);
  1195. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PCNT')) || // 4.16 PCNT Play counter
  1196. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CNT'))) { // 4.17 CNT Play counter
  1197. // There may only be one 'PCNT' frame in each tag.
  1198. // When the counter reaches all one's, one byte is inserted in
  1199. // front of the counter thus making the counter eight bits bigger
  1200. // <Header for 'Play counter', ID: 'PCNT'>
  1201. // Counter $xx xx xx xx (xx ...)
  1202. $parsedFrame['data'] = getid3_lib::BigEndian2Int($parsedFrame['data']);
  1203. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POPM')) || // 4.17 POPM Popularimeter
  1204. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'POP'))) { // 4.18 POP Popularimeter
  1205. // There may be more than one 'POPM' frame in each tag,
  1206. // but only one with the same email address
  1207. // <Header for 'Popularimeter', ID: 'POPM'>
  1208. // Email to user <text string> $00
  1209. // Rating $xx
  1210. // Counter $xx xx xx xx (xx ...)
  1211. $frame_offset = 0;
  1212. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1213. $frame_emailaddress = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1214. if (ord($frame_emailaddress) === 0) {
  1215. $frame_emailaddress = '';
  1216. }
  1217. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1218. $frame_rating = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1219. $parsedFrame['counter'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset));
  1220. $parsedFrame['email'] = $frame_emailaddress;
  1221. $parsedFrame['rating'] = $frame_rating;
  1222. unset($parsedFrame['data']);
  1223. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RBUF')) || // 4.18 RBUF Recommended buffer size
  1224. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'BUF'))) { // 4.19 BUF Recommended buffer size
  1225. // There may only be one 'RBUF' frame in each tag
  1226. // <Header for 'Recommended buffer size', ID: 'RBUF'>
  1227. // Buffer size $xx xx xx
  1228. // Embedded info flag %0000000x
  1229. // Offset to next tag $xx xx xx xx
  1230. $frame_offset = 0;
  1231. $parsedFrame['buffersize'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 3));
  1232. $frame_offset += 3;
  1233. $frame_embeddedinfoflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1));
  1234. $parsedFrame['flags']['embededinfo'] = (bool) substr($frame_embeddedinfoflags, 7, 1);
  1235. $parsedFrame['nexttagoffset'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
  1236. unset($parsedFrame['data']);
  1237. } elseif (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRM')) { // 4.20 Encrypted meta frame (ID3v2.2 only)
  1238. // There may be more than one 'CRM' frame in a tag,
  1239. // but only one with the same 'owner identifier'
  1240. // <Header for 'Encrypted meta frame', ID: 'CRM'>
  1241. // Owner identifier <textstring> $00 (00)
  1242. // Content/explanation <textstring> $00 (00)
  1243. // Encrypted datablock <binary data>
  1244. $frame_offset = 0;
  1245. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1246. $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1247. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1248. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1249. $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1250. if (ord($frame_description) === 0) {
  1251. $frame_description = '';
  1252. }
  1253. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1254. $parsedFrame['ownerid'] = $frame_ownerid;
  1255. $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
  1256. $parsedFrame['description'] = $frame_description;
  1257. unset($parsedFrame['data']);
  1258. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'AENC')) || // 4.19 AENC Audio encryption
  1259. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRA'))) { // 4.21 CRA Audio encryption
  1260. // There may be more than one 'AENC' frames in a tag,
  1261. // but only one with the same 'Owner identifier'
  1262. // <Header for 'Audio encryption', ID: 'AENC'>
  1263. // Owner identifier <text string> $00
  1264. // Preview start $xx xx
  1265. // Preview length $xx xx
  1266. // Encryption info <binary data>
  1267. $frame_offset = 0;
  1268. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1269. $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1270. if (ord($frame_ownerid) === 0) {
  1271. $frame_ownerid == '';
  1272. }
  1273. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1274. $parsedFrame['ownerid'] = $frame_ownerid;
  1275. $parsedFrame['previewstart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
  1276. $frame_offset += 2;
  1277. $parsedFrame['previewlength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
  1278. $frame_offset += 2;
  1279. $parsedFrame['encryptioninfo'] = (string) substr($parsedFrame['data'], $frame_offset);
  1280. unset($parsedFrame['data']);
  1281. } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'LINK')) || // 4.20 LINK Linked information
  1282. (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) { // 4.22 LNK Linked information
  1283. // There may be more than one 'LINK' frame in a tag,
  1284. // but only one with the same contents
  1285. // <Header for 'Linked information', ID: 'LINK'>
  1286. // ID3v2.3+ => Frame identifier $xx xx xx xx
  1287. // ID3v2.2 => Frame identifier $xx xx xx
  1288. // URL <text string> $00
  1289. // ID and additional data <text string(s)>
  1290. $frame_offset = 0;
  1291. if ($id3v2_majorversion == 2) {
  1292. $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 3);
  1293. $frame_offset += 3;
  1294. } else {
  1295. $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 4);
  1296. $frame_offset += 4;
  1297. }
  1298. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1299. $frame_url = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1300. if (ord($frame_url) === 0) {
  1301. $frame_url = '';
  1302. }
  1303. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1304. $parsedFrame['url'] = $frame_url;
  1305. $parsedFrame['additionaldata'] = (string) substr($parsedFrame['data'], $frame_offset);
  1306. if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) {
  1307. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = utf8_encode($parsedFrame['url']);
  1308. }
  1309. unset($parsedFrame['data']);
  1310. } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POSS')) { // 4.21 POSS Position synchronisation frame (ID3v2.3+ only)
  1311. // There may only be one 'POSS' frame in each tag
  1312. // <Head for 'Position synchronisation', ID: 'POSS'>
  1313. // Time stamp format $xx
  1314. // Position $xx (xx ...)
  1315. $frame_offset = 0;
  1316. $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1317. $parsedFrame['position'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset));
  1318. unset($parsedFrame['data']);
  1319. } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USER')) { // 4.22 USER Terms of use (ID3v2.3+ only)
  1320. // There may be more than one 'Terms of use' frame in a tag,
  1321. // but only one with the same 'Language'
  1322. // <Header for 'Terms of use frame', ID: 'USER'>
  1323. // Text encoding $xx
  1324. // Language $xx xx xx
  1325. // The actual text <text string according to encoding>
  1326. $frame_offset = 0;
  1327. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1328. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  1329. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  1330. }
  1331. $frame_language = substr($parsedFrame['data'], $frame_offset, 3);
  1332. $frame_offset += 3;
  1333. $parsedFrame['language'] = $frame_language;
  1334. $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false);
  1335. $parsedFrame['encodingid'] = $frame_textencoding;
  1336. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  1337. $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
  1338. if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
  1339. $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
  1340. }
  1341. unset($parsedFrame['data']);
  1342. } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'OWNE')) { // 4.23 OWNE Ownership frame (ID3v2.3+ only)
  1343. // There may only be one 'OWNE' frame in a tag
  1344. // <Header for 'Ownership frame', ID: 'OWNE'>
  1345. // Text encoding $xx
  1346. // Price paid <text string> $00
  1347. // Date of purch. <text string>
  1348. // Seller <text string according to encoding>
  1349. $frame_offset = 0;
  1350. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1351. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  1352. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  1353. }
  1354. $parsedFrame['encodingid'] = $frame_textencoding;
  1355. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  1356. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1357. $frame_pricepaid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1358. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1359. $parsedFrame['pricepaid']['currencyid'] = substr($frame_pricepaid, 0, 3);
  1360. $parsedFrame['pricepaid']['currency'] = $this->LookupCurrencyUnits($parsedFrame['pricepaid']['currencyid']);
  1361. $parsedFrame['pricepaid']['value'] = substr($frame_pricepaid, 3);
  1362. $parsedFrame['purchasedate'] = substr($parsedFrame['data'], $frame_offset, 8);
  1363. if (!$this->IsValidDateStampString($parsedFrame['purchasedate'])) {
  1364. $parsedFrame['purchasedateunix'] = mktime (0, 0, 0, substr($parsedFrame['purchasedate'], 4, 2), substr($parsedFrame['purchasedate'], 6, 2), substr($parsedFrame['purchasedate'], 0, 4));
  1365. }
  1366. $frame_offset += 8;
  1367. $parsedFrame['seller'] = (string) substr($parsedFrame['data'], $frame_offset);
  1368. unset($parsedFrame['data']);
  1369. } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMR')) { // 4.24 COMR Commercial frame (ID3v2.3+ only)
  1370. // There may be more than one 'commercial frame' in a tag,
  1371. // but no two may be identical
  1372. // <Header for 'Commercial frame', ID: 'COMR'>
  1373. // Text encoding $xx
  1374. // Price string <text string> $00
  1375. // Valid until <text string>
  1376. // Contact URL <text string> $00
  1377. // Received as $xx
  1378. // Name of seller <text string according to encoding> $00 (00)
  1379. // Description <text string according to encoding> $00 (00)
  1380. // Picture MIME type <string> $00
  1381. // Seller logo <binary data>
  1382. $frame_offset = 0;
  1383. $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1384. if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) {
  1385. $info['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding';
  1386. }
  1387. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1388. $frame_pricestring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1389. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1390. $frame_rawpricearray = explode('/', $frame_pricestring);
  1391. foreach ($frame_rawpricearray as $key => $val) {
  1392. $frame_currencyid = substr($val, 0, 3);
  1393. $parsedFrame['price'][$frame_currencyid]['currency'] = $this->LookupCurrencyUnits($frame_currencyid);
  1394. $parsedFrame['price'][$frame_currencyid]['value'] = substr($val, 3);
  1395. }
  1396. $frame_datestring = substr($parsedFrame['data'], $frame_offset, 8);
  1397. $frame_offset += 8;
  1398. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1399. $frame_contacturl = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1400. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1401. $frame_receivedasid = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1402. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  1403. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  1404. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  1405. }
  1406. $frame_sellername = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1407. if (ord($frame_sellername) === 0) {
  1408. $frame_sellername = '';
  1409. }
  1410. $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding));
  1411. $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
  1412. if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
  1413. $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00
  1414. }
  1415. $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1416. if (ord($frame_description) === 0) {
  1417. $frame_description = '';
  1418. }
  1419. $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding));
  1420. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1421. $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1422. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1423. $frame_sellerlogo = substr($parsedFrame['data'], $frame_offset);
  1424. $parsedFrame['encodingid'] = $frame_textencoding;
  1425. $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
  1426. $parsedFrame['pricevaliduntil'] = $frame_datestring;
  1427. $parsedFrame['contacturl'] = $frame_contacturl;
  1428. $parsedFrame['receivedasid'] = $frame_receivedasid;
  1429. $parsedFrame['receivedas'] = $this->COMRReceivedAsLookup($frame_receivedasid);
  1430. $parsedFrame['sellername'] = $frame_sellername;
  1431. $parsedFrame['description'] = $frame_description;
  1432. $parsedFrame['mime'] = $frame_mimetype;
  1433. $parsedFrame['logo'] = $frame_sellerlogo;
  1434. unset($parsedFrame['data']);
  1435. } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ENCR')) { // 4.25 ENCR Encryption method registration (ID3v2.3+ only)
  1436. // There may be several 'ENCR' frames in a tag,
  1437. // but only one containing the same symbol
  1438. // and only one containing the same owner identifier
  1439. // <Header for 'Encryption method registration', ID: 'ENCR'>
  1440. // Owner identifier <text string> $00
  1441. // Method symbol $xx
  1442. // Encryption data <binary data>
  1443. $frame_offset = 0;
  1444. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1445. $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1446. if (ord($frame_ownerid) === 0) {
  1447. $frame_ownerid = '';
  1448. }
  1449. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1450. $parsedFrame['ownerid'] = $frame_ownerid;
  1451. $parsedFrame['methodsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1452. $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
  1453. } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GRID')) { // 4.26 GRID Group identification registration (ID3v2.3+ only)
  1454. // There may be several 'GRID' frames in a tag,
  1455. // but only one containing the same symbol
  1456. // and only one containing the same owner identifier
  1457. // <Header for 'Group ID registration', ID: 'GRID'>
  1458. // Owner identifier <text string> $00
  1459. // Group symbol $xx
  1460. // Group dependent data <binary data>
  1461. $frame_offset = 0;
  1462. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1463. $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1464. if (ord($frame_ownerid) === 0) {
  1465. $frame_ownerid = '';
  1466. }
  1467. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1468. $parsedFrame['ownerid'] = $frame_ownerid;
  1469. $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1470. $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
  1471. } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PRIV')) { // 4.27 PRIV Private frame (ID3v2.3+ only)
  1472. // The tag may contain more than one 'PRIV' frame
  1473. // but only with different contents
  1474. // <Header for 'Private frame', ID: 'PRIV'>
  1475. // Owner identifier <text string> $00
  1476. // The private data <binary data>
  1477. $frame_offset = 0;
  1478. $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset);
  1479. $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
  1480. if (ord($frame_ownerid) === 0) {
  1481. $frame_ownerid = '';
  1482. }
  1483. $frame_offset = $frame_terminatorpos + strlen("\x00");
  1484. $parsedFrame['ownerid'] = $frame_ownerid;
  1485. $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
  1486. } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SIGN')) { // 4.28 SIGN Signature frame (ID3v2.4+ only)
  1487. // There may be more than one 'signature frame' in a tag,
  1488. // but no two may be identical
  1489. // <Header for 'Signature frame', ID: 'SIGN'>
  1490. // Group symbol $xx
  1491. // Signature <binary data>
  1492. $frame_offset = 0;
  1493. $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1494. $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
  1495. } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SEEK')) { // 4.29 SEEK Seek frame (ID3v2.4+ only)
  1496. // There may only be one 'seek frame' in a tag
  1497. // <Header for 'Seek frame', ID: 'SEEK'>
  1498. // Minimum offset to next tag $xx xx xx xx
  1499. $frame_offset = 0;
  1500. $parsedFrame['data'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
  1501. } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'ASPI')) { // 4.30 ASPI Audio seek point index (ID3v2.4+ only)
  1502. // There may only be one 'audio seek point index' frame in a tag
  1503. // <Header for 'Seek Point Index', ID: 'ASPI'>
  1504. // Indexed data start (S) $xx xx xx xx
  1505. // Indexed data length (L) $xx xx xx xx
  1506. // Number of index points (N) $xx xx
  1507. // Bits per index point (b) $xx
  1508. // Then for every index point the following data is included:
  1509. // Fraction at index (Fi) $xx (xx)
  1510. $frame_offset = 0;
  1511. $parsedFrame['datastart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
  1512. $frame_offset += 4;
  1513. $parsedFrame['indexeddatalength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
  1514. $frame_offset += 4;
  1515. $parsedFrame['indexpoints'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
  1516. $frame_offset += 2;
  1517. $parsedFrame['bitsperpoint'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
  1518. $frame_bytesperpoint = ceil($parsedFrame['bitsperpoint'] / 8);
  1519. for ($i = 0; $i < $frame_indexpoints; $i++) {
  1520. $parsedFrame['indexes'][$i] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesperpoint));
  1521. $frame_offset += $frame_bytesperpoint;
  1522. }
  1523. unset($parsedFrame['data']);
  1524. } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RGAD')) { // Replay Gain Adjustment
  1525. // http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html
  1526. // There may only be one 'RGAD' frame in a tag
  1527. // <Header for 'Replay Gain Adjustment', ID: 'RGAD'>
  1528. // Peak Amplitude $xx $xx $xx $xx
  1529. // Radio Replay Gain Adjustment %aaabbbcd %dddddddd
  1530. // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd
  1531. // a - name code
  1532. // b - originator code
  1533. // c - sign bit
  1534. // d - replay gain adjustment
  1535. $frame_offset = 0;
  1536. $parsedFrame['peakamplitude'] = getid3_lib::BigEndian2Float(substr($parsedFrame['data'], $frame_offset, 4));
  1537. $frame_offset += 4;
  1538. $rg_track_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2));
  1539. $frame_offset += 2;
  1540. $rg_album_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2));
  1541. $frame_offset += 2;
  1542. $parsedFrame['raw']['track']['name'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 0, 3));
  1543. $parsedFrame['raw']['track']['originator'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 3, 3));
  1544. $parsedFrame['raw']['track']['signbit'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 6, 1));
  1545. $parsedFrame['raw']['track']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 7, 9));
  1546. $parsedFrame['raw']['album']['name'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 0, 3));
  1547. $parsedFrame['raw']['album']['originator'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 3, 3));
  1548. $parsedFrame['raw']['album']['signbit'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 6, 1));
  1549. $parsedFrame['raw']['album']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 7, 9));
  1550. $parsedFrame['track']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['track']['name']);
  1551. $parsedFrame['track']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['track']['originator']);
  1552. $parsedFrame['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['track']['adjustment'], $parsedFrame['raw']['track']['signbit']);
  1553. $parsedFrame['album']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['album']['name']);
  1554. $parsedFrame['album']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['album']['originator']);
  1555. $parsedFrame['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['album']['adjustment'], $parsedFrame['raw']['album']['signbit']);
  1556. $info['replay_gain']['track']['peak'] = $parsedFrame['peakamplitude'];
  1557. $info['replay_gain']['track']['originator'] = $parsedFrame['track']['originator'];
  1558. $info['replay_gain']['track']['adjustment'] = $parsedFrame['track']['adjustment'];
  1559. $info['replay_gain']['album']['originator'] = $parsedFrame['album']['originator'];
  1560. $info['replay_gain']['album']['adjustment'] = $parsedFrame['album']['adjustment'];
  1561. unset($parsedFrame['data']);
  1562. }
  1563. return true;
  1564. }
  1565. function DeUnsynchronise($data) {
  1566. return str_replace("\xFF\x00", "\xFF", $data);
  1567. }
  1568. function LookupExtendedHeaderRestrictionsTagSizeLimits($index) {
  1569. static $LookupExtendedHeaderRestrictionsTagSizeLimits = array(
  1570. 0x00 => 'No more than 128 frames and 1 MB total tag size',
  1571. 0x01 => 'No more than 64 frames and 128 KB total tag size',
  1572. 0x02 => 'No more than 32 frames and 40 KB total tag size',
  1573. 0x03 => 'No more than 32 frames and 4 KB total tag size',
  1574. );
  1575. return (isset($LookupExtendedHeaderRestrictionsTagSizeLimits[$index]) ? $LookupExtendedHeaderRestrictionsTagSizeLimits[$index] : '');
  1576. }
  1577. function LookupExtendedHeaderRestrictionsTextEncodings($index) {
  1578. static $LookupExtendedHeaderRestrictionsTextEncodings = array(
  1579. 0x00 => 'No restrictions',
  1580. 0x01 => 'Strings are only encoded with ISO-8859-1 or UTF-8',
  1581. );
  1582. return (isset($LookupExtendedHeaderRestrictionsTextEncodings[$index]) ? $LookupExtendedHeaderRestrictionsTextEncodings[$index] : '');
  1583. }
  1584. function LookupExtendedHeaderRestrictionsTextFieldSize($index) {
  1585. static $LookupExtendedHeaderRestrictionsTextFieldSize = array(
  1586. 0x00 => 'No restrictions',
  1587. 0x01 => 'No string is longer than 1024 characters',
  1588. 0x02 => 'No string is longer than 128 characters',
  1589. 0x03 => 'No string is longer than 30 characters',
  1590. );
  1591. return (isset($LookupExtendedHeaderRestrictionsTextFieldSize[$index]) ? $LookupExtendedHeaderRestrictionsTextFieldSize[$index] : '');
  1592. }
  1593. function LookupExtendedHeaderRestrictionsImageEncoding($index) {
  1594. static $LookupExtendedHeaderRestrictionsImageEncoding = array(
  1595. 0x00 => 'No restrictions',
  1596. 0x01 => 'Images are encoded only with PNG or JPEG',
  1597. );
  1598. return (isset($LookupExtendedHeaderRestrictionsImageEncoding[$index]) ? $LookupExtendedHeaderRestrictionsImageEncoding[$index] : '');
  1599. }
  1600. function LookupExtendedHeaderRestrictionsImageSizeSize($index) {
  1601. static $LookupExtendedHeaderRestrictionsImageSizeSize = array(
  1602. 0x00 => 'No restrictions',
  1603. 0x01 => 'All images are 256x256 pixels or smaller',
  1604. 0x02 => 'All images are 64x64 pixels or smaller',
  1605. 0x03 => 'All images are exactly 64x64 pixels, unless required otherwise',
  1606. );
  1607. return (isset($LookupExtendedHeaderRestrictionsImageSizeSize[$index]) ? $LookupExtendedHeaderRestrictionsImageSizeSize[$index] : '');
  1608. }
  1609. function LookupCurrencyUnits($currencyid) {
  1610. $begin = __LINE__;
  1611. /** This is not a comment!
  1612. AED Dirhams
  1613. AFA Afghanis
  1614. ALL Leke
  1615. AMD Drams
  1616. ANG Guilders
  1617. AOA Kwanza
  1618. ARS Pesos
  1619. ATS Schillings
  1620. AUD Dollars
  1621. AWG Guilders
  1622. AZM Manats
  1623. BAM Convertible Marka
  1624. BBD Dollars
  1625. BDT Taka
  1626. BEF Francs
  1627. BGL Leva
  1628. BHD Dinars
  1629. BIF Francs
  1630. BMD Dollars
  1631. BND Dollars
  1632. BOB Bolivianos
  1633. BRL Brazil Real
  1634. BSD Dollars
  1635. BTN Ngultrum
  1636. BWP Pulas
  1637. BYR Rubles
  1638. BZD Dollars
  1639. CAD Dollars
  1640. CDF Congolese Francs
  1641. CHF Francs
  1642. CLP Pesos
  1643. CNY Yuan Renminbi
  1644. COP Pesos
  1645. CRC Colones
  1646. CUP Pesos
  1647. CVE Escudos
  1648. CYP Pounds
  1649. CZK Koruny
  1650. DEM Deutsche Marks
  1651. DJF Francs
  1652. DKK Kroner
  1653. DOP Pesos
  1654. DZD Algeria Dinars
  1655. EEK Krooni
  1656. EGP Pounds
  1657. ERN Nakfa
  1658. ESP Pesetas
  1659. ETB Birr
  1660. EUR Euro
  1661. FIM Markkaa
  1662. FJD Dollars
  1663. FKP Pounds
  1664. FRF Francs
  1665. GBP Pounds
  1666. GEL Lari
  1667. GGP Pounds
  1668. GHC Cedis
  1669. GIP Pounds
  1670. GMD Dalasi
  1671. GNF Francs
  1672. GRD Drachmae
  1673. GTQ Quetzales
  1674. GYD Dollars
  1675. HKD Dollars
  1676. HNL Lempiras
  1677. HRK Kuna
  1678. HTG Gourdes
  1679. HUF Forints
  1680. IDR Rupiahs
  1681. IEP Pounds
  1682. ILS New Shekels
  1683. IMP Pounds
  1684. INR Rupees
  1685. IQD Dinars
  1686. IRR Rials
  1687. ISK Kronur
  1688. ITL Lire
  1689. JEP Pounds
  1690. JMD Dollars
  1691. JOD Dinars
  1692. JPY Yen
  1693. KES Shillings
  1694. KGS Soms
  1695. KHR Riels
  1696. KMF Francs
  1697. KPW Won
  1698. KWD Dinars
  1699. KYD Dollars
  1700. KZT Tenge
  1701. LAK Kips
  1702. LBP Pounds
  1703. LKR Rupees
  1704. LRD Dollars
  1705. LSL Maloti
  1706. LTL Litai
  1707. LUF Francs
  1708. LVL Lati
  1709. LYD Dinars
  1710. MAD Dirhams
  1711. MDL Lei
  1712. MGF Malagasy Francs
  1713. MKD Denars
  1714. MMK Kyats
  1715. MNT Tugriks
  1716. MOP Patacas
  1717. MRO Ouguiyas
  1718. MTL Liri
  1719. MUR Rupees
  1720. MVR Rufiyaa
  1721. MWK Kwachas
  1722. MXN Pesos
  1723. MYR Ringgits
  1724. MZM Meticais
  1725. NAD Dollars
  1726. NGN Nairas
  1727. NIO Gold Cordobas
  1728. NLG Guilders
  1729. NOK Krone
  1730. NPR Nepal Rupees
  1731. NZD Dollars
  1732. OMR Rials
  1733. PAB Balboa
  1734. PEN Nuevos Soles
  1735. PGK Kina
  1736. PHP Pesos
  1737. PKR Rupees
  1738. PLN Zlotych
  1739. PTE Escudos
  1740. PYG Guarani
  1741. QAR Rials
  1742. ROL Lei
  1743. RUR Rubles
  1744. RWF Rwanda Francs
  1745. SAR Riyals
  1746. SBD Dollars
  1747. SCR Rupees
  1748. SDD Dinars
  1749. SEK Kronor
  1750. SGD Dollars
  1751. SHP Pounds
  1752. SIT Tolars
  1753. SKK Koruny
  1754. SLL Leones
  1755. SOS Shillings
  1756. SPL Luigini
  1757. SRG Guilders
  1758. STD Dobras
  1759. SVC Colones
  1760. SYP Pounds
  1761. SZL Emalangeni
  1762. THB Baht
  1763. TJR Rubles
  1764. TMM Manats
  1765. TND Dinars
  1766. TOP Pa'anga
  1767. TRL Liras
  1768. TTD Dollars
  1769. TVD Tuvalu Dollars
  1770. TWD New Dollars
  1771. TZS Shillings
  1772. UAH Hryvnia
  1773. UGX Shillings
  1774. USD Dollars
  1775. UYU Pesos
  1776. UZS Sums
  1777. VAL Lire
  1778. VEB Bolivares
  1779. VND Dong
  1780. VUV Vatu
  1781. WST Tala
  1782. XAF Francs
  1783. XAG Ounces
  1784. XAU Ounces
  1785. XCD Dollars
  1786. XDR Special Drawing Rights
  1787. XPD Ounces
  1788. XPF Francs
  1789. XPT Ounces
  1790. YER Rials
  1791. YUM New Dinars
  1792. ZAR Rand
  1793. ZMK Kwacha
  1794. ZWD Zimbabwe Dollars
  1795. */
  1796. return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-units');
  1797. }
  1798. function LookupCurrencyCountry($currencyid) {
  1799. $begin = __LINE__;
  1800. /** This is not a comment!
  1801. AED United Arab Emirates
  1802. AFA Afghanistan
  1803. ALL Albania
  1804. AMD Armenia
  1805. ANG Netherlands Antilles
  1806. AOA Angola
  1807. ARS Argentina
  1808. ATS Austria
  1809. AUD Australia
  1810. AWG Aruba
  1811. AZM Azerbaijan
  1812. BAM Bosnia and Herzegovina
  1813. BBD Barbados
  1814. BDT Bangladesh
  1815. BEF Belgium
  1816. BGL Bulgaria
  1817. BHD Bahrain
  1818. BIF Burundi
  1819. BMD Bermuda
  1820. BND Brunei Darussalam
  1821. BOB Bolivia
  1822. BRL Brazil
  1823. BSD Bahamas
  1824. BTN Bhutan
  1825. BWP Botswana
  1826. BYR Belarus
  1827. BZD Belize
  1828. CAD Canada
  1829. CDF Congo/Kinshasa
  1830. CHF Switzerland
  1831. CLP Chile
  1832. CNY China
  1833. COP Colombia
  1834. CRC Costa Rica
  1835. CUP Cuba
  1836. CVE Cape Verde
  1837. CYP Cyprus
  1838. CZK Czech Republic
  1839. DEM Germany
  1840. DJF Djibouti
  1841. DKK Denmark
  1842. DOP Dominican Republic
  1843. DZD Algeria
  1844. EEK Estonia
  1845. EGP Egypt
  1846. ERN Eritrea
  1847. ESP Spain
  1848. ETB Ethiopia
  1849. EUR Euro Member Countries
  1850. FIM Finland
  1851. FJD Fiji
  1852. FKP Falkland Islands (Malvinas)
  1853. FRF France
  1854. GBP United Kingdom
  1855. GEL Georgia
  1856. GGP Guernsey
  1857. GHC Ghana
  1858. GIP Gibraltar
  1859. GMD Gambia
  1860. GNF Guinea
  1861. GRD Greece
  1862. GTQ Guatemala
  1863. GYD Guyana
  1864. HKD Hong Kong
  1865. HNL Honduras
  1866. HRK Croatia
  1867. HTG Haiti
  1868. HUF Hungary
  1869. IDR Indonesia
  1870. IEP Ireland (Eire)
  1871. ILS Israel
  1872. IMP Isle of Man
  1873. INR India
  1874. IQD Iraq
  1875. IRR Iran
  1876. ISK Iceland
  1877. ITL Italy
  1878. JEP Jersey
  1879. JMD Jamaica
  1880. JOD Jordan
  1881. JPY Japan
  1882. KES Kenya
  1883. KGS Kyrgyzstan
  1884. KHR Cambodia
  1885. KMF Comoros
  1886. KPW Korea
  1887. KWD Kuwait
  1888. KYD Cayman Islands
  1889. KZT Kazakstan
  1890. LAK Laos
  1891. LBP Lebanon
  1892. LKR Sri Lanka
  1893. LRD Liberia
  1894. LSL Lesotho
  1895. LTL Lithuania
  1896. LUF Luxembourg
  1897. LVL Latvia
  1898. LYD Libya
  1899. MAD Morocco
  1900. MDL Moldova
  1901. MGF Madagascar
  1902. MKD Macedonia
  1903. MMK Myanmar (Burma)
  1904. MNT Mongolia
  1905. MOP Macau
  1906. MRO Mauritania
  1907. MTL Malta
  1908. MUR Mauritius
  1909. MVR Maldives (Maldive Islands)
  1910. MWK Malawi
  1911. MXN Mexico
  1912. MYR Malaysia
  1913. MZM Mozambique
  1914. NAD Namibia
  1915. NGN Nigeria
  1916. NIO Nicaragua
  1917. NLG Netherlands (Holland)
  1918. NOK Norway
  1919. NPR Nepal
  1920. NZD New Zealand
  1921. OMR Oman
  1922. PAB Panama
  1923. PEN Peru
  1924. PGK Papua New Guinea
  1925. PHP Philippines
  1926. PKR Pakistan
  1927. PLN Poland
  1928. PTE Portugal
  1929. PYG Paraguay
  1930. QAR Qatar
  1931. ROL Romania
  1932. RUR Russia
  1933. RWF Rwanda
  1934. SAR Saudi Arabia
  1935. SBD Solomon Islands
  1936. SCR Seychelles
  1937. SDD Sudan
  1938. SEK Sweden
  1939. SGD Singapore
  1940. SHP Saint Helena
  1941. SIT Slovenia
  1942. SKK Slovakia
  1943. SLL Sierra Leone
  1944. SOS Somalia
  1945. SPL Seborga
  1946. SRG Suriname
  1947. STD Săo Tome and Principe
  1948. SVC El Salvador
  1949. SYP Syria
  1950. SZL Swaziland
  1951. THB Thailand
  1952. TJR Tajikistan
  1953. TMM Turkmenistan
  1954. TND Tunisia
  1955. TOP Tonga
  1956. TRL Turkey
  1957. TTD Trinidad and Tobago
  1958. TVD Tuvalu
  1959. TWD Taiwan
  1960. TZS Tanzania
  1961. UAH Ukraine
  1962. UGX Uganda
  1963. USD United States of America
  1964. UYU Uruguay
  1965. UZS Uzbekistan
  1966. VAL Vatican City
  1967. VEB Venezuela
  1968. VND Viet Nam
  1969. VUV Vanuatu
  1970. WST Samoa
  1971. XAF Communauté Financičre Africaine
  1972. XAG Silver
  1973. XAU Gold
  1974. XCD East Caribbean
  1975. XDR International Monetary Fund
  1976. XPD Palladium
  1977. XPF Comptoirs Français du Pacifique
  1978. XPT Platinum
  1979. YER Yemen
  1980. YUM Yugoslavia
  1981. ZAR South Africa
  1982. ZMK Zambia
  1983. ZWD Zimbabwe
  1984. */
  1985. return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-country');
  1986. }
  1987. static function LanguageLookup($languagecode, $casesensitive=false) {
  1988. if (!$casesensitive) {
  1989. $languagecode = strtolower($languagecode);
  1990. }
  1991. // http://www.id3.org/id3v2.4.0-structure.txt
  1992. // [4. ID3v2 frame overview]
  1993. // The three byte language field, present in several frames, is used to
  1994. // describe the language of the frame's content, according to ISO-639-2
  1995. // [ISO-639-2]. The language should be represented in lower case. If the
  1996. // language is not known the string "XXX" should be used.
  1997. // ISO 639-2 - http://www.id3.org/iso639-2.html
  1998. $begin = __LINE__;
  1999. /** This is not a comment!
  2000. XXX unknown
  2001. xxx unknown
  2002. aar Afar
  2003. abk Abkhazian
  2004. ace Achinese
  2005. ach Acoli
  2006. ada Adangme
  2007. afa Afro-Asiatic (Other)
  2008. afh Afrihili
  2009. afr Afrikaans
  2010. aka Akan
  2011. akk Akkadian
  2012. alb Albanian
  2013. ale Aleut
  2014. alg Algonquian Languages
  2015. amh Amharic
  2016. ang English, Old (ca. 450-1100)
  2017. apa Apache Languages
  2018. ara Arabic
  2019. arc Aramaic
  2020. arm Armenian
  2021. arn Araucanian
  2022. arp Arapaho
  2023. art Artificial (Other)
  2024. arw Arawak
  2025. asm Assamese
  2026. ath Athapascan Languages
  2027. ava Avaric
  2028. ave Avestan
  2029. awa Awadhi
  2030. aym Aymara
  2031. aze Azerbaijani
  2032. bad Banda
  2033. bai Bamileke Languages
  2034. bak Bashkir
  2035. bal Baluchi
  2036. bam Bambara
  2037. ban Balinese
  2038. baq Basque
  2039. bas Basa
  2040. bat Baltic (Other)
  2041. bej Beja
  2042. bel Byelorussian
  2043. bem Bemba
  2044. ben Bengali
  2045. ber Berber (Other)
  2046. bho Bhojpuri
  2047. bih Bihari
  2048. bik Bikol
  2049. bin Bini
  2050. bis Bislama
  2051. bla Siksika
  2052. bnt Bantu (Other)
  2053. bod Tibetan
  2054. bra Braj
  2055. bre Breton
  2056. bua Buriat
  2057. bug Buginese
  2058. bul Bulgarian
  2059. bur Burmese
  2060. cad Caddo
  2061. cai Central American Indian (Other)
  2062. car Carib
  2063. cat Catalan
  2064. cau Caucasian (Other)
  2065. ceb Cebuano
  2066. cel Celtic (Other)
  2067. ces Czech
  2068. cha Chamorro
  2069. chb Chibcha
  2070. che Chechen
  2071. chg Chagatai
  2072. chi Chinese
  2073. chm Mari
  2074. chn Chinook jargon
  2075. cho Choctaw
  2076. chr Cherokee
  2077. chu Church Slavic
  2078. chv Chuvash
  2079. chy Cheyenne
  2080. cop Coptic
  2081. cor Cornish
  2082. cos Corsican
  2083. cpe Creoles and Pidgins, English-based (Other)
  2084. cpf Creoles and Pidgins, French-based (Other)
  2085. cpp Creoles and Pidgins, Portuguese-based (Other)
  2086. cre Cree
  2087. crp Creoles and Pidgins (Other)
  2088. cus Cushitic (Other)
  2089. cym Welsh
  2090. cze Czech
  2091. dak Dakota
  2092. dan Danish
  2093. del Delaware
  2094. deu German
  2095. din Dinka
  2096. div Divehi
  2097. doi Dogri
  2098. dra Dravidian (Other)
  2099. dua Duala
  2100. dum Dutch, Middle (ca. 1050-1350)
  2101. dut Dutch
  2102. dyu Dyula
  2103. dzo Dzongkha
  2104. efi Efik
  2105. egy Egyptian (Ancient)
  2106. eka Ekajuk
  2107. ell Greek, Modern (1453-)
  2108. elx Elamite
  2109. eng English
  2110. enm English, Middle (ca. 1100-1500)
  2111. epo Esperanto
  2112. esk Eskimo (Other)
  2113. esl Spanish
  2114. est Estonian
  2115. eus Basque
  2116. ewe Ewe
  2117. ewo Ewondo
  2118. fan Fang
  2119. fao Faroese
  2120. fas Persian
  2121. fat Fanti
  2122. fij Fijian
  2123. fin Finnish
  2124. fiu Finno-Ugrian (Other)
  2125. fon Fon
  2126. fra French
  2127. fre French
  2128. frm French, Middle (ca. 1400-1600)
  2129. fro French, Old (842- ca. 1400)
  2130. fry Frisian
  2131. ful Fulah
  2132. gaa Ga
  2133. gae Gaelic (Scots)
  2134. gai Irish
  2135. gay Gayo
  2136. gdh Gaelic (Scots)
  2137. gem Germanic (Other)
  2138. geo Georgian
  2139. ger German
  2140. gez Geez
  2141. gil Gilbertese
  2142. glg Gallegan
  2143. gmh German, Middle High (ca. 1050-1500)
  2144. goh German, Old High (ca. 750-1050)
  2145. gon Gondi
  2146. got Gothic
  2147. grb Grebo
  2148. grc Greek, Ancient (to 1453)
  2149. gre Greek, Modern (1453-)
  2150. grn Guarani
  2151. guj Gujarati
  2152. hai Haida
  2153. hau Hausa
  2154. haw Hawaiian
  2155. heb Hebrew
  2156. her Herero
  2157. hil Hiligaynon
  2158. him Himachali
  2159. hin Hindi
  2160. hmo Hiri Motu
  2161. hun Hungarian
  2162. hup Hupa
  2163. hye Armenian
  2164. iba Iban
  2165. ibo Igbo
  2166. ice Icelandic
  2167. ijo Ijo
  2168. iku Inuktitut
  2169. ilo Iloko
  2170. ina Interlingua (International Auxiliary language Association)
  2171. inc Indic (Other)
  2172. ind Indonesian
  2173. ine Indo-European (Other)
  2174. ine Interlingue
  2175. ipk Inupiak
  2176. ira Iranian (Other)
  2177. iri Irish
  2178. iro Iroquoian uages
  2179. isl Icelandic
  2180. ita Italian
  2181. jav Javanese
  2182. jaw Javanese
  2183. jpn Japanese
  2184. jpr Judeo-Persian
  2185. jrb Judeo-Arabic
  2186. kaa Kara-Kalpak
  2187. kab Kabyle
  2188. kac Kachin
  2189. kal Greenlandic
  2190. kam Kamba
  2191. kan Kannada
  2192. kar Karen
  2193. kas Kashmiri
  2194. kat Georgian
  2195. kau Kanuri
  2196. kaw Kawi
  2197. kaz Kazakh
  2198. kha Khasi
  2199. khi Khoisan (Other)
  2200. khm Khmer
  2201. kho Khotanese
  2202. kik Kikuyu
  2203. kin Kinyarwanda
  2204. kir Kirghiz
  2205. kok Konkani
  2206. kom Komi
  2207. kon Kongo
  2208. kor Korean
  2209. kpe Kpelle
  2210. kro Kru
  2211. kru Kurukh
  2212. kua Kuanyama
  2213. kum Kumyk
  2214. kur Kurdish
  2215. kus Kusaie
  2216. kut Kutenai
  2217. lad Ladino
  2218. lah Lahnda
  2219. lam Lamba
  2220. lao Lao
  2221. lat Latin
  2222. lav Latvian
  2223. lez Lezghian
  2224. lin Lingala
  2225. lit Lithuanian
  2226. lol Mongo
  2227. loz Lozi
  2228. ltz Letzeburgesch
  2229. lub Luba-Katanga
  2230. lug Ganda
  2231. lui Luiseno
  2232. lun Lunda
  2233. luo Luo (Kenya and Tanzania)
  2234. mac Macedonian
  2235. mad Madurese
  2236. mag Magahi
  2237. mah Marshall
  2238. mai Maithili
  2239. mak Macedonian
  2240. mak Makasar
  2241. mal Malayalam
  2242. man Mandingo
  2243. mao Maori
  2244. map Austronesian (Other)
  2245. mar Marathi
  2246. mas Masai
  2247. max Manx
  2248. may Malay
  2249. men Mende
  2250. mga Irish, Middle (900 - 1200)
  2251. mic Micmac
  2252. min Minangkabau
  2253. mis Miscellaneous (Other)
  2254. mkh Mon-Kmer (Other)
  2255. mlg Malagasy
  2256. mlt Maltese
  2257. mni Manipuri
  2258. mno Manobo Languages
  2259. moh Mohawk
  2260. mol Moldavian
  2261. mon Mongolian
  2262. mos Mossi
  2263. mri Maori
  2264. msa Malay
  2265. mul Multiple Languages
  2266. mun Munda Languages
  2267. mus Creek
  2268. mwr Marwari
  2269. mya Burmese
  2270. myn Mayan Languages
  2271. nah Aztec
  2272. nai North American Indian (Other)
  2273. nau Nauru
  2274. nav Navajo
  2275. nbl Ndebele, South
  2276. nde Ndebele, North
  2277. ndo Ndongo
  2278. nep Nepali
  2279. new Newari
  2280. nic Niger-Kordofanian (Other)
  2281. niu Niuean
  2282. nla Dutch
  2283. nno Norwegian (Nynorsk)
  2284. non Norse, Old
  2285. nor Norwegian
  2286. nso Sotho, Northern
  2287. nub Nubian Languages
  2288. nya Nyanja
  2289. nym Nyamwezi
  2290. nyn Nyankole
  2291. nyo Nyoro
  2292. nzi Nzima
  2293. oci Langue d'Oc (post 1500)
  2294. oji Ojibwa
  2295. ori Oriya
  2296. orm Oromo
  2297. osa Osage
  2298. oss Ossetic
  2299. ota Turkish, Ottoman (1500 - 1928)
  2300. oto Otomian Languages
  2301. paa Papuan-Australian (Other)
  2302. pag Pangasinan
  2303. pal Pahlavi
  2304. pam Pampanga
  2305. pan Panjabi
  2306. pap Papiamento
  2307. pau Palauan
  2308. peo Persian, Old (ca 600 - 400 B.C.)
  2309. per Persian
  2310. phn Phoenician
  2311. pli Pali
  2312. pol Polish
  2313. pon Ponape
  2314. por Portuguese
  2315. pra Prakrit uages
  2316. pro Provencal, Old (to 1500)
  2317. pus Pushto
  2318. que Quechua
  2319. raj Rajasthani
  2320. rar Rarotongan
  2321. roa Romance (Other)
  2322. roh Rhaeto-Romance
  2323. rom Romany
  2324. ron Romanian
  2325. rum Romanian
  2326. run Rundi
  2327. rus Russian
  2328. sad Sandawe
  2329. sag Sango
  2330. sah Yakut
  2331. sai South American Indian (Other)
  2332. sal Salishan Languages
  2333. sam Samaritan Aramaic
  2334. san Sanskrit
  2335. sco Scots
  2336. scr Serbo-Croatian
  2337. sel Selkup
  2338. sem Semitic (Other)
  2339. sga Irish, Old (to 900)
  2340. shn Shan
  2341. sid Sidamo
  2342. sin Singhalese
  2343. sio Siouan Languages
  2344. sit Sino-Tibetan (Other)
  2345. sla Slavic (Other)
  2346. slk Slovak
  2347. slo Slovak
  2348. slv Slovenian
  2349. smi Sami Languages
  2350. smo Samoan
  2351. sna Shona
  2352. snd Sindhi
  2353. sog Sogdian
  2354. som Somali
  2355. son Songhai
  2356. sot Sotho, Southern
  2357. spa Spanish
  2358. sqi Albanian
  2359. srd Sardinian
  2360. srr Serer
  2361. ssa Nilo-Saharan (Other)
  2362. ssw Siswant
  2363. ssw Swazi
  2364. suk Sukuma
  2365. sun Sudanese
  2366. sus Susu
  2367. sux Sumerian
  2368. sve Swedish
  2369. swa Swahili
  2370. swe Swedish
  2371. syr Syriac
  2372. tah Tahitian
  2373. tam Tamil
  2374. tat Tatar
  2375. tel Telugu
  2376. tem Timne
  2377. ter Tereno
  2378. tgk Tajik
  2379. tgl Tagalog
  2380. tha Thai
  2381. tib Tibetan
  2382. tig Tigre
  2383. tir Tigrinya
  2384. tiv Tivi
  2385. tli Tlingit
  2386. tmh Tamashek
  2387. tog Tonga (Nyasa)
  2388. ton Tonga (Tonga Islands)
  2389. tru Truk
  2390. tsi Tsimshian
  2391. tsn Tswana
  2392. tso Tsonga
  2393. tuk Turkmen
  2394. tum Tumbuka
  2395. tur Turkish
  2396. tut Altaic (Other)
  2397. twi Twi
  2398. tyv Tuvinian
  2399. uga Ugaritic
  2400. uig Uighur
  2401. ukr Ukrainian
  2402. umb Umbundu
  2403. und Undetermined
  2404. urd Urdu
  2405. uzb Uzbek
  2406. vai Vai
  2407. ven Venda
  2408. vie Vietnamese
  2409. vol Volapük
  2410. vot Votic
  2411. wak Wakashan Languages
  2412. wal Walamo
  2413. war Waray
  2414. was Washo
  2415. wel Welsh
  2416. wen Sorbian Languages
  2417. wol Wolof
  2418. xho Xhosa
  2419. yao Yao
  2420. yap Yap
  2421. yid Yiddish
  2422. yor Yoruba
  2423. zap Zapotec
  2424. zen Zenaga
  2425. zha Zhuang
  2426. zho Chinese
  2427. zul Zulu
  2428. zun Zuni
  2429. */
  2430. return getid3_lib::EmbeddedLookup($languagecode, $begin, __LINE__, __FILE__, 'id3v2-languagecode');
  2431. }
  2432. static function ETCOEventLookup($index) {
  2433. if (($index >= 0x17) && ($index <= 0xDF)) {
  2434. return 'reserved for future use';
  2435. }
  2436. if (($index >= 0xE0) && ($index <= 0xEF)) {
  2437. return 'not predefined synch 0-F';
  2438. }
  2439. if (($index >= 0xF0) && ($index <= 0xFC)) {
  2440. return 'reserved for future use';
  2441. }
  2442. static $EventLookup = array(
  2443. 0x00 => 'padding (has no meaning)',
  2444. 0x01 => 'end of initial silence',
  2445. 0x02 => 'intro start',
  2446. 0x03 => 'main part start',
  2447. 0x04 => 'outro start',
  2448. 0x05 => 'outro end',
  2449. 0x06 => 'verse start',
  2450. 0x07 => 'refrain start',
  2451. 0x08 => 'interlude start',
  2452. 0x09 => 'theme start',
  2453. 0x0A => 'variation start',
  2454. 0x0B => 'key change',
  2455. 0x0C => 'time change',
  2456. 0x0D => 'momentary unwanted noise (Snap, Crackle & Pop)',
  2457. 0x0E => 'sustained noise',
  2458. 0x0F => 'sustained noise end',
  2459. 0x10 => 'intro end',
  2460. 0x11 => 'main part end',
  2461. 0x12 => 'verse end',
  2462. 0x13 => 'refrain end',
  2463. 0x14 => 'theme end',
  2464. 0x15 => 'profanity',
  2465. 0x16 => 'profanity end',
  2466. 0xFD => 'audio end (start of silence)',
  2467. 0xFE => 'audio file ends',
  2468. 0xFF => 'one more byte of events follows'
  2469. );
  2470. return (isset($EventLookup[$index]) ? $EventLookup[$index] : '');
  2471. }
  2472. static function SYTLContentTypeLookup($index) {
  2473. static $SYTLContentTypeLookup = array(
  2474. 0x00 => 'other',
  2475. 0x01 => 'lyrics',
  2476. 0x02 => 'text transcription',
  2477. 0x03 => 'movement/part name', // (e.g. 'Adagio')
  2478. 0x04 => 'events', // (e.g. 'Don Quijote enters the stage')
  2479. 0x05 => 'chord', // (e.g. 'Bb F Fsus')
  2480. 0x06 => 'trivia/\'pop up\' information',
  2481. 0x07 => 'URLs to webpages',
  2482. 0x08 => 'URLs to images'
  2483. );
  2484. return (isset($SYTLContentTypeLookup[$index]) ? $SYTLContentTypeLookup[$index] : '');
  2485. }
  2486. static function APICPictureTypeLookup($index, $returnarray=false) {
  2487. static $APICPictureTypeLookup = array(
  2488. 0x00 => 'Other',
  2489. 0x01 => '32x32 pixels \'file icon\' (PNG only)',
  2490. 0x02 => 'Other file icon',
  2491. 0x03 => 'Cover (front)',
  2492. 0x04 => 'Cover (back)',
  2493. 0x05 => 'Leaflet page',
  2494. 0x06 => 'Media (e.g. label side of CD)',
  2495. 0x07 => 'Lead artist/lead performer/soloist',
  2496. 0x08 => 'Artist/performer',
  2497. 0x09 => 'Conductor',
  2498. 0x0A => 'Band/Orchestra',
  2499. 0x0B => 'Composer',
  2500. 0x0C => 'Lyricist/text writer',
  2501. 0x0D => 'Recording Location',
  2502. 0x0E => 'During recording',
  2503. 0x0F => 'During performance',
  2504. 0x10 => 'Movie/video screen capture',
  2505. 0x11 => 'A bright coloured fish',
  2506. 0x12 => 'Illustration',
  2507. 0x13 => 'Band/artist logotype',
  2508. 0x14 => 'Publisher/Studio logotype'
  2509. );
  2510. if ($returnarray) {
  2511. return $APICPictureTypeLookup;
  2512. }
  2513. return (isset($APICPictureTypeLookup[$index]) ? $APICPictureTypeLookup[$index] : '');
  2514. }
  2515. static function COMRReceivedAsLookup($index) {
  2516. static $COMRReceivedAsLookup = array(
  2517. 0x00 => 'Other',
  2518. 0x01 => 'Standard CD album with other songs',
  2519. 0x02 => 'Compressed audio on CD',
  2520. 0x03 => 'File over the Internet',
  2521. 0x04 => 'Stream over the Internet',
  2522. 0x05 => 'As note sheets',
  2523. 0x06 => 'As note sheets in a book with other sheets',
  2524. 0x07 => 'Music on other media',
  2525. 0x08 => 'Non-musical merchandise'
  2526. );
  2527. return (isset($COMRReceivedAsLookup[$index]) ? $COMRReceivedAsLookup[$index] : '');
  2528. }
  2529. static function RVA2ChannelTypeLookup($index) {
  2530. static $RVA2ChannelTypeLookup = array(
  2531. 0x00 => 'Other',
  2532. 0x01 => 'Master volume',
  2533. 0x02 => 'Front right',
  2534. 0x03 => 'Front left',
  2535. 0x04 => 'Back right',
  2536. 0x05 => 'Back left',
  2537. 0x06 => 'Front centre',
  2538. 0x07 => 'Back centre',
  2539. 0x08 => 'Subwoofer'
  2540. );
  2541. return (isset($RVA2ChannelTypeLookup[$index]) ? $RVA2ChannelTypeLookup[$index] : '');
  2542. }
  2543. static function FrameNameLongLookup($framename) {
  2544. $begin = __LINE__;
  2545. /** This is not a comment!
  2546. AENC Audio encryption
  2547. APIC Attached picture
  2548. ASPI Audio seek point index
  2549. BUF Recommended buffer size
  2550. CNT Play counter
  2551. COM Comments
  2552. COMM Comments
  2553. COMR Commercial frame
  2554. CRA Audio encryption
  2555. CRM Encrypted meta frame
  2556. ENCR Encryption method registration
  2557. EQU Equalisation
  2558. EQU2 Equalisation (2)
  2559. EQUA Equalisation
  2560. ETC Event timing codes
  2561. ETCO Event timing codes
  2562. GEO General encapsulated object
  2563. GEOB General encapsulated object
  2564. GRID Group identification registration
  2565. IPL Involved people list
  2566. IPLS Involved people list
  2567. LINK Linked information
  2568. LNK Linked information
  2569. MCDI Music CD identifier
  2570. MCI Music CD Identifier
  2571. MLL MPEG location lookup table
  2572. MLLT MPEG location lookup table
  2573. OWNE Ownership frame
  2574. PCNT Play counter
  2575. PIC Attached picture
  2576. POP Popularimeter
  2577. POPM Popularimeter
  2578. POSS Position synchronisation frame
  2579. PRIV Private frame
  2580. RBUF Recommended buffer size
  2581. REV Reverb
  2582. RVA Relative volume adjustment
  2583. RVA2 Relative volume adjustment (2)
  2584. RVAD Relative volume adjustment
  2585. RVRB Reverb
  2586. SEEK Seek frame
  2587. SIGN Signature frame
  2588. SLT Synchronised lyric/text
  2589. STC Synced tempo codes
  2590. SYLT Synchronised lyric/text
  2591. SYTC Synchronised tempo codes
  2592. TAL Album/Movie/Show title
  2593. TALB Album/Movie/Show title
  2594. TBP BPM (Beats Per Minute)
  2595. TBPM BPM (beats per minute)
  2596. TCM Composer
  2597. TCMP Part of a compilation
  2598. TCO Content type
  2599. TCOM Composer
  2600. TCON Content type
  2601. TCOP Copyright message
  2602. TCP Part of a compilation
  2603. TCR Copyright message
  2604. TDA Date
  2605. TDAT Date
  2606. TDEN Encoding time
  2607. TDLY Playlist delay
  2608. TDOR Original release time
  2609. TDRC Recording time
  2610. TDRL Release time
  2611. TDTG Tagging time
  2612. TDY Playlist delay
  2613. TEN Encoded by
  2614. TENC Encoded by
  2615. TEXT Lyricist/Text writer
  2616. TFLT File type
  2617. TFT File type
  2618. TIM Time
  2619. TIME Time
  2620. TIPL Involved people list
  2621. TIT1 Content group description
  2622. TIT2 Title/songname/content description
  2623. TIT3 Subtitle/Description refinement
  2624. TKE Initial key
  2625. TKEY Initial key
  2626. TLA Language(s)
  2627. TLAN Language(s)
  2628. TLE Length
  2629. TLEN Length
  2630. TMCL Musician credits list
  2631. TMED Media type
  2632. TMOO Mood
  2633. TMT Media type
  2634. TOA Original artist(s)/performer(s)
  2635. TOAL Original album/movie/show title
  2636. TOF Original filename
  2637. TOFN Original filename
  2638. TOL Original Lyricist(s)/text writer(s)
  2639. TOLY Original lyricist(s)/text writer(s)
  2640. TOPE Original artist(s)/performer(s)
  2641. TOR Original release year
  2642. TORY Original release year
  2643. TOT Original album/Movie/Show title
  2644. TOWN File owner/licensee
  2645. TP1 Lead artist(s)/Lead performer(s)/Soloist(s)/Performing group
  2646. TP2 Band/Orchestra/Accompaniment
  2647. TP3 Conductor/Performer refinement
  2648. TP4 Interpreted, remixed, or otherwise modified by
  2649. TPA Part of a set
  2650. TPB Publisher
  2651. TPE1 Lead performer(s)/Soloist(s)
  2652. TPE2 Band/orchestra/accompaniment
  2653. TPE3 Conductor/performer refinement
  2654. TPE4 Interpreted, remixed, or otherwise modified by
  2655. TPOS Part of a set
  2656. TPRO Produced notice
  2657. TPUB Publisher
  2658. TRC ISRC (International Standard Recording Code)
  2659. TRCK Track number/Position in set
  2660. TRD Recording dates
  2661. TRDA Recording dates
  2662. TRK Track number/Position in set
  2663. TRSN Internet radio station name
  2664. TRSO Internet radio station owner
  2665. TS2 Album-Artist sort order
  2666. TSA Album sort order
  2667. TSC Composer sort order
  2668. TSI Size
  2669. TSIZ Size
  2670. TSO2 Album-Artist sort order
  2671. TSOA Album sort order
  2672. TSOC Composer sort order
  2673. TSOP Performer sort order
  2674. TSOT Title sort order
  2675. TSP Performer sort order
  2676. TSRC ISRC (international standard recording code)
  2677. TSS Software/hardware and settings used for encoding
  2678. TSSE Software/Hardware and settings used for encoding
  2679. TSST Set subtitle
  2680. TST Title sort order
  2681. TT1 Content group description
  2682. TT2 Title/Songname/Content description
  2683. TT3 Subtitle/Description refinement
  2684. TXT Lyricist/text writer
  2685. TXX User defined text information frame
  2686. TXXX User defined text information frame
  2687. TYE Year
  2688. TYER Year
  2689. UFI Unique file identifier
  2690. UFID Unique file identifier
  2691. ULT Unsychronised lyric/text transcription
  2692. USER Terms of use
  2693. USLT Unsynchronised lyric/text transcription
  2694. WAF Official audio file webpage
  2695. WAR Official artist/performer webpage
  2696. WAS Official audio source webpage
  2697. WCM Commercial information
  2698. WCOM Commercial information
  2699. WCOP Copyright/Legal information
  2700. WCP Copyright/Legal information
  2701. WOAF Official audio file webpage
  2702. WOAR Official artist/performer webpage
  2703. WOAS Official audio source webpage
  2704. WORS Official Internet radio station homepage
  2705. WPAY Payment
  2706. WPB Publishers official webpage
  2707. WPUB Publishers official webpage
  2708. WXX User defined URL link frame
  2709. WXXX User defined URL link frame
  2710. TFEA Featured Artist
  2711. TSTU Recording Studio
  2712. rgad Replay Gain Adjustment
  2713. */
  2714. return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_long');
  2715. // Last three:
  2716. // from Helium2 [www.helium2.com]
  2717. // from http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html
  2718. }
  2719. static function FrameNameShortLookup($framename) {
  2720. $begin = __LINE__;
  2721. /** This is not a comment!
  2722. AENC audio_encryption
  2723. APIC attached_picture
  2724. ASPI audio_seek_point_index
  2725. BUF recommended_buffer_size
  2726. CNT play_counter
  2727. COM comment
  2728. COMM comment
  2729. COMR commercial_frame
  2730. CRA audio_encryption
  2731. CRM encrypted_meta_frame
  2732. ENCR encryption_method_registration
  2733. EQU equalisation
  2734. EQU2 equalisation
  2735. EQUA equalisation
  2736. ETC event_timing_codes
  2737. ETCO event_timing_codes
  2738. GEO general_encapsulated_object
  2739. GEOB general_encapsulated_object
  2740. GRID group_identification_registration
  2741. IPL involved_people_list
  2742. IPLS involved_people_list
  2743. LINK linked_information
  2744. LNK linked_information
  2745. MCDI music_cd_identifier
  2746. MCI music_cd_identifier
  2747. MLL mpeg_location_lookup_table
  2748. MLLT mpeg_location_lookup_table
  2749. OWNE ownership_frame
  2750. PCNT play_counter
  2751. PIC attached_picture
  2752. POP popularimeter
  2753. POPM popularimeter
  2754. POSS position_synchronisation_frame
  2755. PRIV private_frame
  2756. RBUF recommended_buffer_size
  2757. REV reverb
  2758. RVA relative_volume_adjustment
  2759. RVA2 relative_volume_adjustment
  2760. RVAD relative_volume_adjustment
  2761. RVRB reverb
  2762. SEEK seek_frame
  2763. SIGN signature_frame
  2764. SLT synchronised_lyric
  2765. STC synced_tempo_codes
  2766. SYLT synchronised_lyric
  2767. SYTC synchronised_tempo_codes
  2768. TAL album
  2769. TALB album
  2770. TBP bpm
  2771. TBPM bpm
  2772. TCM composer
  2773. TCMP part_of_a_compilation
  2774. TCO genre
  2775. TCOM composer
  2776. TCON genre
  2777. TCOP copyright_message
  2778. TCP part_of_a_compilation
  2779. TCR copyright_message
  2780. TDA date
  2781. TDAT date
  2782. TDEN encoding_time
  2783. TDLY playlist_delay
  2784. TDOR original_release_time
  2785. TDRC recording_time
  2786. TDRL release_time
  2787. TDTG tagging_time
  2788. TDY playlist_delay
  2789. TEN encoded_by
  2790. TENC encoded_by
  2791. TEXT lyricist
  2792. TFLT file_type
  2793. TFT file_type
  2794. TIM time
  2795. TIME time
  2796. TIPL involved_people_list
  2797. TIT1 content_group_description
  2798. TIT2 title
  2799. TIT3 subtitle
  2800. TKE initial_key
  2801. TKEY initial_key
  2802. TLA language
  2803. TLAN language
  2804. TLE length
  2805. TLEN length
  2806. TMCL musician_credits_list
  2807. TMED media_type
  2808. TMOO mood
  2809. TMT media_type
  2810. TOA original_artist
  2811. TOAL original_album
  2812. TOF original_filename
  2813. TOFN original_filename
  2814. TOL original_lyricist
  2815. TOLY original_lyricist
  2816. TOPE original_artist
  2817. TOR original_year
  2818. TORY original_year
  2819. TOT original_album
  2820. TOWN file_owner
  2821. TP1 artist
  2822. TP2 band
  2823. TP3 conductor
  2824. TP4 remixer
  2825. TPA part_of_a_set
  2826. TPB publisher
  2827. TPE1 artist
  2828. TPE2 band
  2829. TPE3 conductor
  2830. TPE4 remixer
  2831. TPOS part_of_a_set
  2832. TPRO produced_notice
  2833. TPUB publisher
  2834. TRC isrc
  2835. TRCK track_number
  2836. TRD recording_dates
  2837. TRDA recording_dates
  2838. TRK track_number
  2839. TRSN internet_radio_station_name
  2840. TRSO internet_radio_station_owner
  2841. TS2 album_artist_sort_order
  2842. TSA album_sort_order
  2843. TSC composer_sort_order
  2844. TSI size
  2845. TSIZ size
  2846. TSO2 album_artist_sort_order
  2847. TSOA album_sort_order
  2848. TSOC composer_sort_order
  2849. TSOP performer_sort_order
  2850. TSOT title_sort_order
  2851. TSP performer_sort_order
  2852. TSRC isrc
  2853. TSS encoder_settings
  2854. TSSE encoder_settings
  2855. TSST set_subtitle
  2856. TST title_sort_order
  2857. TT1 description
  2858. TT2 title
  2859. TT3 subtitle
  2860. TXT lyricist
  2861. TXX text
  2862. TXXX text
  2863. TYE year
  2864. TYER year
  2865. UFI unique_file_identifier
  2866. UFID unique_file_identifier
  2867. ULT unsychronised_lyric
  2868. USER terms_of_use
  2869. USLT unsynchronised_lyric
  2870. WAF url_file
  2871. WAR url_artist
  2872. WAS url_source
  2873. WCM commercial_information
  2874. WCOM commercial_information
  2875. WCOP copyright
  2876. WCP copyright
  2877. WOAF url_file
  2878. WOAR url_artist
  2879. WOAS url_source
  2880. WORS url_station
  2881. WPAY url_payment
  2882. WPB url_publisher
  2883. WPUB url_publisher
  2884. WXX url_user
  2885. WXXX url_user
  2886. TFEA featured_artist
  2887. TSTU recording_studio
  2888. rgad replay_gain_adjustment
  2889. */
  2890. return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_short');
  2891. }
  2892. static function TextEncodingTerminatorLookup($encoding) {
  2893. // http://www.id3.org/id3v2.4.0-structure.txt
  2894. // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings:
  2895. static $TextEncodingTerminatorLookup = array(
  2896. 0 => "\x00", // $00 ISO-8859-1. Terminated with $00.
  2897. 1 => "\x00\x00", // $01 UTF-16 encoded Unicode with BOM. All strings in the same frame SHALL have the same byteorder. Terminated with $00 00.
  2898. 2 => "\x00\x00", // $02 UTF-16BE encoded Unicode without BOM. Terminated with $00 00.
  2899. 3 => "\x00", // $03 UTF-8 encoded Unicode. Terminated with $00.
  2900. 255 => "\x00\x00"
  2901. );
  2902. return (isset($TextEncodingTerminatorLookup[$encoding]) ? $TextEncodingTerminatorLookup[$encoding] : '');
  2903. }
  2904. static function TextEncodingNameLookup($encoding) {
  2905. // http://www.id3.org/id3v2.4.0-structure.txt
  2906. // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings:
  2907. static $TextEncodingNameLookup = array(
  2908. 0 => 'ISO-8859-1', // $00 ISO-8859-1. Terminated with $00.
  2909. 1 => 'UTF-16', // $01 UTF-16 encoded Unicode with BOM. All strings in the same frame SHALL have the same byteorder. Terminated with $00 00.
  2910. 2 => 'UTF-16BE', // $02 UTF-16BE encoded Unicode without BOM. Terminated with $00 00.
  2911. 3 => 'UTF-8', // $03 UTF-8 encoded Unicode. Terminated with $00.
  2912. 255 => 'UTF-16BE'
  2913. );
  2914. return (isset($TextEncodingNameLookup[$encoding]) ? $TextEncodingNameLookup[$encoding] : 'ISO-8859-1');
  2915. }
  2916. static function IsValidID3v2FrameName($framename, $id3v2majorversion) {
  2917. switch ($id3v2majorversion) {
  2918. case 2:
  2919. return preg_match('#[A-Z][A-Z0-9]{2}#', $framename);
  2920. break;
  2921. case 3:
  2922. case 4:
  2923. return preg_match('#[A-Z][A-Z0-9]{3}#', $framename);
  2924. break;
  2925. }
  2926. return false;
  2927. }
  2928. static function IsANumber($numberstring, $allowdecimal=false, $allownegative=false) {
  2929. for ($i = 0; $i < strlen($numberstring); $i++) {
  2930. if ((chr($numberstring{$i}) < chr('0')) || (chr($numberstring{$i}) > chr('9'))) {
  2931. if (($numberstring{$i} == '.') && $allowdecimal) {
  2932. // allowed
  2933. } elseif (($numberstring{$i} == '-') && $allownegative && ($i == 0)) {
  2934. // allowed
  2935. } else {
  2936. return false;
  2937. }
  2938. }
  2939. }
  2940. return true;
  2941. }
  2942. static function IsValidDateStampString($datestamp) {
  2943. if (strlen($datestamp) != 8) {
  2944. return false;
  2945. }
  2946. if (!self::IsANumber($datestamp, false)) {
  2947. return false;
  2948. }
  2949. $year = substr($datestamp, 0, 4);
  2950. $month = substr($datestamp, 4, 2);
  2951. $day = substr($datestamp, 6, 2);
  2952. if (($year == 0) || ($month == 0) || ($day == 0)) {
  2953. return false;
  2954. }
  2955. if ($month > 12) {
  2956. return false;
  2957. }
  2958. if ($day > 31) {
  2959. return false;
  2960. }
  2961. if (($day > 30) && (($month == 4) || ($month == 6) || ($month == 9) || ($month == 11))) {
  2962. return false;
  2963. }
  2964. if (($day > 29) && ($month == 2)) {
  2965. return false;
  2966. }
  2967. return true;
  2968. }
  2969. static function ID3v2HeaderLength($majorversion) {
  2970. return (($majorversion == 2) ? 6 : 10);
  2971. }
  2972. }
  2973. ?>