PageRenderTime 29ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/music/class/getid3/getid3.putid3.php

http://nukeviet-music.googlecode.com/
PHP | 1647 lines | 1334 code | 30 blank | 283 comment | 522 complexity | 0070fdbfb91a3b05a06c6bfe9bb99d27 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. ////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <getid3@silisoftware.com> //
  4. // available at http://www.silisoftware.com ///
  5. ////////////////////////////////////////////////////////////
  6. // //
  7. // putid3.php - part of getID3() //
  8. // See getid3.readme.txt for more details //
  9. // //
  10. ////////////////////////////////////////////////////////////
  11. function GenerateID3v2TagFlags($majorversion=4, $Unsynchronisation=FALSE, $Compression=FALSE, $ExtendedHeader=FALSE, $Experimental=FALSE, $Footer=FALSE) {
  12. if ($majorversion == 4) {
  13. // %abcd0000
  14. $flag .= Bool2IntString($Unsynchronisation); // a - Unsynchronisation
  15. $flag .= Bool2IntString($ExtendedHeader); // b - Extended header
  16. $flag .= Bool2IntString($Experimental); // c - Experimental indicator
  17. $flag .= Bool2IntString($Footer); // d - Footer present
  18. $flag .= '0000';
  19. } else if ($majorversion == 3) {
  20. // %abc00000
  21. $flag .= Bool2IntString($Unsynchronisation); // a - Unsynchronisation
  22. $flag .= Bool2IntString($ExtendedHeader); // b - Extended header
  23. $flag .= Bool2IntString($Experimental); // c - Experimental indicator
  24. $flag .= '00000';
  25. } else if ($majorversion == 2) {
  26. // %ab000000
  27. $flag .= Bool2IntString($Unsynchronisation); // a - Unsynchronisation
  28. $flag .= Bool2IntString($Compression); // b - Compression
  29. $flag .= '000000';
  30. } else {
  31. return FALSE;
  32. }
  33. return chr(bindec($flag));
  34. }
  35. function GenerateID3v2FrameFlags($majorversion=4, $TagAlter=FALSE, $FileAlter=FALSE, $ReadOnly=FALSE, $Compression=FALSE, $Encryption=FALSE, $GroupingIdentity=FALSE, $Unsynchronisation=FALSE, $DataLengthIndicator=FALSE) {
  36. if ($majorversion == 4) {
  37. // %0abc0000 %0h00kmnp
  38. $flag1 .= '0';
  39. $flag1 .= Bool2IntString($TagAlter); // a - Tag alter preservation (TRUE == discard)
  40. $flag1 .= Bool2IntString($FileAlter); // b - File alter preservation (TRUE == discard)
  41. $flag1 .= Bool2IntString($ReadOnly); // c - Read only (TRUE == read only)
  42. $flag1 .= '0000';
  43. $flag2 .= '0';
  44. $flag2 .= Bool2IntString($GroupingIdentity); // h - Grouping identity (TRUE == contains group information)
  45. $flag2 .= '00';
  46. $flag2 .= Bool2IntString($Compression); // k - Compression (TRUE == compressed)
  47. $flag2 .= Bool2IntString($Encryption); // m - Encryption (TRUE == encrypted)
  48. $flag2 .= Bool2IntString($Unsynchronisation); // n - Unsynchronisation (TRUE == unsynchronised)
  49. $flag2 .= Bool2IntString($DataLengthIndicator); // p - Data length indicator (TRUE == data length indicator added)
  50. } else if ($majorversion == 3) {
  51. // %abc00000 %ijk00000
  52. $flag1 .= Bool2IntString($TagAlter); // a - Tag alter preservation (TRUE == discard)
  53. $flag1 .= Bool2IntString($FileAlter); // b - File alter preservation (TRUE == discard)
  54. $flag1 .= Bool2IntString($ReadOnly); // c - Read only (TRUE == read only)
  55. $flag1 .= '00000';
  56. $flag2 .= Bool2IntString($Compression); // i - Compression (TRUE == compressed)
  57. $flag2 .= Bool2IntString($Encryption); // j - Encryption (TRUE == encrypted)
  58. $flag2 .= Bool2IntString($GroupingIdentity); // k - Grouping identity (TRUE == contains group information)
  59. $flag2 .= '00000';
  60. } else {
  61. return FALSE;
  62. }
  63. return chr(bindec($flag1)).chr(bindec($flag2));
  64. }
  65. function GenerateID3v2FrameData($frame_name, $frame_data, $majorversion=4, $showerrors=FALSE) {
  66. if (!IsValidID3v2FrameName($frame_name, $majorversion)) {
  67. return FALSE;
  68. }
  69. if ($majorversion == 2) {
  70. ksort($frame_data);
  71. reset($frame_data);
  72. switch ($frame_name) {
  73. case 'TXX':
  74. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  75. break;
  76. case 'WXX':
  77. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  78. break;
  79. case 'IPL':
  80. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  81. break;
  82. case 'MCI':
  83. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  84. break;
  85. case 'ETC':
  86. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  87. break;
  88. case 'MLL':
  89. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  90. break;
  91. case 'STC':
  92. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  93. break;
  94. case 'ULT':
  95. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  96. break;
  97. case 'SLT':
  98. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  99. break;
  100. case 'COM':
  101. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  102. break;
  103. case 'RVA':
  104. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  105. break;
  106. case 'EQU':
  107. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  108. break;
  109. case 'REV':
  110. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  111. break;
  112. case 'PIC':
  113. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  114. break;
  115. case 'GEO':
  116. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  117. break;
  118. case 'CNT':
  119. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  120. break;
  121. case 'POP':
  122. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  123. break;
  124. case 'BUF':
  125. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  126. break;
  127. case 'CRM':
  128. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  129. break;
  130. case 'CRA':
  131. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  132. break;
  133. case 'LNK':
  134. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  135. break;
  136. default:
  137. if ($frame_name{0} == 'T') {
  138. // T??
  139. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  140. } else if ($frame_name{0} == 'W') {
  141. // W??
  142. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  143. } else {
  144. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  145. return FALSE;
  146. }
  147. }
  148. } else { // $majorversion > 2
  149. switch ($frame_name) {
  150. case 'UFID':
  151. // 4.1 UFID Unique file identifier
  152. // Owner identifier <text string> $00
  153. // Identifier <up to 64 bytes binary data>
  154. if (strlen($frame_data['data']) > 64) {
  155. $error .= 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($frame_data['data']).' bytes long)<BR>';
  156. } else {
  157. $framedata .= str_replace(chr(0), '', $frame_data['ownerid']).chr(0);
  158. $framedata .= substr($frame_data['data'], 0, 64); // max 64 bytes - truncate anything longer
  159. }
  160. break;
  161. case 'TXXX':
  162. // 4.2.2 TXXX User defined text information frame
  163. // Text encoding $xx
  164. // Description <text string according to encoding> $00 (00)
  165. // Value <text string according to encoding>
  166. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  167. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  168. } else {
  169. $framedata .= chr($frame_data['encodingid']);
  170. $framedata .= $frame_data['description'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  171. $framedata .= $frame_data['data'];
  172. }
  173. break;
  174. case 'WXXX':
  175. // 4.3.2 WXXX User defined URL link frame
  176. // Text encoding $xx
  177. // Description <text string according to encoding> $00 (00)
  178. // URL <text string>
  179. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  180. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  181. } else if (!IsValidURL($frame_data['url'], FALSE, FALSE)) {
  182. $error .= 'Invalid URL in '.$frame_name.' ('.$frame_data['url'].')<BR>';
  183. } else {
  184. $framedata .= chr($frame_data['encodingid']);
  185. $framedata .= $frame_data['description'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  186. $framedata .= $frame_data['url'];
  187. }
  188. break;
  189. case 'IPLS':
  190. // 4.4 IPLS Involved people list (ID3v2.3 only)
  191. // Text encoding $xx
  192. // People list strings <textstrings>
  193. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  194. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  195. } else {
  196. $framedata .= chr($frame_data['encodingid']);
  197. $framedata .= $frame_data['data'];
  198. }
  199. break;
  200. case 'MCDI':
  201. // 4.4 MCDI Music CD identifier
  202. // CD TOC <binary data>
  203. $framedata .= $frame_data['data'];
  204. break;
  205. case 'ETCO':
  206. // 4.5 ETCO Event timing codes
  207. // Time stamp format $xx
  208. // Where time stamp format is:
  209. // $01 (32-bit value) MPEG frames from beginning of file
  210. // $02 (32-bit value) milliseconds from beginning of file
  211. // Followed by a list of key events in the following format:
  212. // Type of event $xx
  213. // Time stamp $xx (xx ...)
  214. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  215. // or after the previous event. All events MUST be sorted in chronological order.
  216. if (($frame_data['timestampformat'] > 2) || ($frame_data['timestampformat'] < 1)) {
  217. $error .= 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$frame_data['timestampformat'].')<BR>';
  218. } else {
  219. $framedata .= chr($frame_data['timestampformat']);
  220. foreach ($frame_data as $key => $val) {
  221. if (!IsValidETCOevent($val['typeid'], $majorversion)) {
  222. $error .= 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')<BR>';
  223. } else if (($key != 'timestampformat') && ($key != 'flags')) {
  224. if (($val['timestamp'] > 0) && ($previousETCOtimestamp >= $val['timestamp'])) {
  225. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  226. // or after the previous event. All events MUST be sorted in chronological order.
  227. $error .= 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')<BR>';
  228. } else {
  229. $framedata .= chr($val['typeid']);
  230. $framedata .= BigEndian2String($val['timestamp'], 4, FALSE);
  231. }
  232. }
  233. }
  234. }
  235. break;
  236. case 'MLLT':
  237. // 4.6 MLLT MPEG location lookup table
  238. // MPEG frames between reference $xx xx
  239. // Bytes between reference $xx xx xx
  240. // Milliseconds between reference $xx xx xx
  241. // Bits for bytes deviation $xx
  242. // Bits for milliseconds dev. $xx
  243. // Then for every reference the following data is included;
  244. // Deviation in bytes %xxx....
  245. // Deviation in milliseconds %xxx....
  246. if (($frame_data['framesbetweenreferences'] > 0) && ($frame_data['framesbetweenreferences'] <= 65535)) {
  247. $framedata .= BigEndian2String($frame_data['framesbetweenreferences'], 2, FALSE);
  248. } else {
  249. $error .= 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$frame_data['framesbetweenreferences'].')<BR>';
  250. }
  251. if (($frame_data['bytesbetweenreferences'] > 0) && ($frame_data['bytesbetweenreferences'] <= 16777215)) {
  252. $framedata .= BigEndian2String($frame_data['bytesbetweenreferences'], 3, FALSE);
  253. } else {
  254. $error .= 'Invalid bytes Between References in '.$frame_name.' ('.$frame_data['bytesbetweenreferences'].')<BR>';
  255. }
  256. if (($frame_data['msbetweenreferences'] > 0) && ($frame_data['msbetweenreferences'] <= 16777215)) {
  257. $framedata .= BigEndian2String($frame_data['msbetweenreferences'], 3, FALSE);
  258. } else {
  259. $error .= 'Invalid Milliseconds Between References in '.$frame_name.' ('.$frame_data['msbetweenreferences'].')<BR>';
  260. }
  261. if (!IsWithinBitRange($frame_data['bitsforbytesdeviation'], 8, FALSE)) {
  262. if (($frame_data['bitsforbytesdeviation'] % 4) == 0) {
  263. $framedata .= chr($frame_data['bitsforbytesdeviation']);
  264. } else {
  265. $error .= 'Bits For Bytes Deviation in '.$frame_name.' ('.$frame_data['bitsforbytesdeviation'].') must be a multiple of 4.<BR>';
  266. }
  267. } else {
  268. $error .= 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$frame_data['bitsforbytesdeviation'].')<BR>';
  269. }
  270. if (!IsWithinBitRange($frame_data['bitsformsdeviation'], 8, FALSE)) {
  271. if (($frame_data['bitsformsdeviation'] % 4) == 0) {
  272. $framedata .= chr($frame_data['bitsformsdeviation']);
  273. } else {
  274. $error .= 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$frame_data['bitsforbytesdeviation'].') must be a multiple of 4.<BR>';
  275. }
  276. } else {
  277. $error .= 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$frame_data['bitsformsdeviation'].')<BR>';
  278. }
  279. foreach ($frame_data as $key => $val) {
  280. if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) {
  281. $unwrittenbitstream .= str_pad(Dec2Bin($val['bytedeviation']), $frame_data['bitsforbytesdeviation'], '0', STR_PAD_LEFT);
  282. $unwrittenbitstream .= str_pad(Dec2Bin($val['msdeviation']), $frame_data['bitsformsdeviation'], '0', STR_PAD_LEFT);
  283. }
  284. }
  285. for ($i=0;$i<strlen($unwrittenbitstream);$i+=8) {
  286. $highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4;
  287. $lownibble = bindec(substr($unwrittenbitstream, $i + 4, 4));
  288. $framedata .= chr($highnibble & $lownibble);
  289. }
  290. break;
  291. case 'SYTC':
  292. // 4.7 SYTC Synchronised tempo codes
  293. // Time stamp format $xx
  294. // Tempo data <binary data>
  295. // Where time stamp format is:
  296. // $01 (32-bit value) MPEG frames from beginning of file
  297. // $02 (32-bit value) milliseconds from beginning of file
  298. if (($frame_data['timestampformat'] > 2) || ($frame_data['timestampformat'] < 1)) {
  299. $error .= 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$frame_data['timestampformat'].')<BR>';
  300. } else {
  301. $framedata .= chr($frame_data['timestampformat']);
  302. foreach ($frame_data as $key => $val) {
  303. if (!IsValidETCOevent($val['typeid'], $majorversion)) {
  304. $error .= 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')<BR>';
  305. } else if (($key != 'timestampformat') && ($key != 'flags')) {
  306. if (($val['tempo'] < 0) || ($val['tempo'] > 510)) {
  307. $error .= 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')<BR>';
  308. } else {
  309. if ($val['tempo'] > 255) {
  310. $framedata .= chr(255);
  311. $val['tempo'] -= 255;
  312. }
  313. $framedata .= chr($val['tempo']);
  314. $framedata .= BigEndian2String($val['timestamp'], 4, FALSE);
  315. }
  316. }
  317. }
  318. }
  319. break;
  320. case 'USLT':
  321. // 4.8 USLT Unsynchronised lyric/text transcription
  322. // Text encoding $xx
  323. // Language $xx xx xx
  324. // Content descriptor <text string according to encoding> $00 (00)
  325. // Lyrics/text <full text string according to encoding>
  326. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  327. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  328. } else if (LanguageLookup($frame_data['language'], TRUE) == '') {
  329. $error .= 'Invalid Language in '.$frame_name.' ('.$frame_data['language'].')<BR>';
  330. } else {
  331. $framedata .= chr($frame_data['encodingid']);
  332. $framedata .= strtolower($frame_data['language']);
  333. $framedata .= $frame_data['description'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  334. $framedata .= $frame_data['data'];
  335. }
  336. break;
  337. case 'SYLT':
  338. // 4.9 SYLT Synchronised lyric/text
  339. // Text encoding $xx
  340. // Language $xx xx xx
  341. // Time stamp format $xx
  342. // $01 (32-bit value) MPEG frames from beginning of file
  343. // $02 (32-bit value) milliseconds from beginning of file
  344. // Content type $xx
  345. // Content descriptor <text string according to encoding> $00 (00)
  346. // Terminated text to be synced (typically a syllable)
  347. // Sync identifier (terminator to above string) $00 (00)
  348. // Time stamp $xx (xx ...)
  349. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  350. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  351. } else if (LanguageLookup($frame_data['language'], TRUE) == '') {
  352. $error .= 'Invalid Language in '.$frame_name.' ('.$frame_data['language'].')<BR>';
  353. } else if (($frame_data['timestampformat'] > 2) || ($frame_data['timestampformat'] < 1)) {
  354. $error .= 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$frame_data['timestampformat'].')<BR>';
  355. } else if (!IsValidSYLTtype($frame_data['contenttypeid'], $majorversion)) {
  356. $error .= 'Invalid Content Type byte in '.$frame_name.' ('.$frame_data['contenttypeid'].')<BR>';
  357. } else if (!is_array($frame_data['data'])) {
  358. $error .= 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)<BR>';
  359. } else {
  360. $framedata .= chr($frame_data['encodingid']);
  361. $framedata .= strtolower($frame_data['language']);
  362. $framedata .= chr($frame_data['timestampformat']);
  363. $framedata .= chr($frame_data['contenttypeid']);
  364. $framedata .= $frame_data['description'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  365. ksort($frame_data['data']);
  366. foreach ($frame_data['data'] as $key => $val) {
  367. $framedata .= $val['data'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  368. $framedata .= BigEndian2String($val['timestamp'], 4, FALSE);
  369. }
  370. }
  371. break;
  372. case 'COMM':
  373. // 4.10 COMM Comments
  374. // Text encoding $xx
  375. // Language $xx xx xx
  376. // Short content descrip. <text string according to encoding> $00 (00)
  377. // The actual text <full text string according to encoding>
  378. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  379. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  380. } else if (LanguageLookup($frame_data['language'], TRUE) == '') {
  381. $error .= 'Invalid Language in '.$frame_name.' ('.$frame_data['language'].')<BR>';
  382. } else {
  383. $framedata .= chr($frame_data['encodingid']);
  384. $framedata .= strtolower($frame_data['language']);
  385. $framedata .= $frame_data['description'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  386. $framedata .= $frame_data['data'];
  387. }
  388. break;
  389. case 'RVA2':
  390. // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only)
  391. // Identification <text string> $00
  392. // The 'identification' string is used to identify the situation and/or
  393. // device where this adjustment should apply. The following is then
  394. // repeated for every channel:
  395. // Type of channel $xx
  396. // Volume adjustment $xx xx
  397. // Bits representing peak $xx
  398. // Peak volume $xx (xx ...)
  399. $framedata .= str_replace(chr(0), '', $frame_data['description']).chr(0);
  400. foreach ($frame_data as $key => $val) {
  401. if ($key != 'description') {
  402. $framedata .= chr($val['channeltypeid']);
  403. $framedata .= substr(str_pad(dechex($val['volumeadjust']), 8, '0', STR_PAD_LEFT), 4, 4); // signed 16-bit
  404. if (!IsWithinBitRange($frame_data['bitspeakvolume'], 8, FALSE)) {
  405. $framedata .= chr($val['bitspeakvolume']);
  406. if ($val['bitspeakvolume'] > 0) {
  407. $framedata .= BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), FALSE);
  408. }
  409. } else {
  410. $error .= 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)<BR>';
  411. }
  412. }
  413. }
  414. break;
  415. case 'RVAD':
  416. // 4.12 RVAD Relative volume adjustment (ID3v2.3 only)
  417. // Increment/decrement %00fedcba
  418. // Bits used for volume descr. $xx
  419. // Relative volume change, right $xx xx (xx ...) // a
  420. // Relative volume change, left $xx xx (xx ...) // b
  421. // Peak volume right $xx xx (xx ...)
  422. // Peak volume left $xx xx (xx ...)
  423. // Relative volume change, right back $xx xx (xx ...) // c
  424. // Relative volume change, left back $xx xx (xx ...) // d
  425. // Peak volume right back $xx xx (xx ...)
  426. // Peak volume left back $xx xx (xx ...)
  427. // Relative volume change, center $xx xx (xx ...) // e
  428. // Peak volume center $xx xx (xx ...)
  429. // Relative volume change, bass $xx xx (xx ...) // f
  430. // Peak volume bass $xx xx (xx ...)
  431. if (!IsWithinBitRange($frame_data['bitsvolume'], 8, FALSE)) {
  432. $error .= 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$frame_data['bitsvolume'].') (range = 1 to 255)<BR>';
  433. } else {
  434. $incdecflag .= '00';
  435. $incdecflag .= Bool2IntString($frame_data['incdec']['right']); // a - Relative volume change, right
  436. $incdecflag .= Bool2IntString($frame_data['incdec']['left']); // b - Relative volume change, left
  437. $incdecflag .= Bool2IntString($frame_data['incdec']['rightrear']); // c - Relative volume change, right back
  438. $incdecflag .= Bool2IntString($frame_data['incdec']['leftrear']); // d - Relative volume change, left back
  439. $incdecflag .= Bool2IntString($frame_data['incdec']['center']); // e - Relative volume change, center
  440. $incdecflag .= Bool2IntString($frame_data['incdec']['bass']); // f - Relative volume change, bass
  441. $framedata .= chr(bindec($incdecflag));
  442. $framedata .= chr($frame_data['bitsvolume']);
  443. $framedata .= BigEndian2String($frame_data['volumechange']['right'], ceil($frame_data['bitsvolume'] / 8), FALSE);
  444. $framedata .= BigEndian2String($frame_data['volumechange']['left'], ceil($frame_data['bitsvolume'] / 8), FALSE);
  445. $framedata .= BigEndian2String($frame_data['peakvolume']['right'], ceil($frame_data['bitsvolume'] / 8), FALSE);
  446. $framedata .= BigEndian2String($frame_data['peakvolume']['left'], ceil($frame_data['bitsvolume'] / 8), FALSE);
  447. if ($frame_data['volumechange']['rightrear'] || $frame_data['volumechange']['leftrear'] ||
  448. $frame_data['peakvolume']['rightrear'] || $frame_data['peakvolume']['leftrear'] ||
  449. $frame_data['volumechange']['center'] || $frame_data['peakvolume']['center'] ||
  450. $frame_data['volumechange']['bass'] || $frame_data['peakvolume']['bass']) {
  451. $framedata .= BigEndian2String($frame_data['volumechange']['rightrear'], ceil($frame_data['bitsvolume']/8), FALSE);
  452. $framedata .= BigEndian2String($frame_data['volumechange']['leftrear'], ceil($frame_data['bitsvolume']/8), FALSE);
  453. $framedata .= BigEndian2String($frame_data['peakvolume']['rightrear'], ceil($frame_data['bitsvolume']/8), FALSE);
  454. $framedata .= BigEndian2String($frame_data['peakvolume']['leftrear'], ceil($frame_data['bitsvolume']/8), FALSE);
  455. }
  456. if ($frame_data['volumechange']['center'] || $frame_data['peakvolume']['center'] ||
  457. $frame_data['volumechange']['bass'] || $frame_data['peakvolume']['bass']) {
  458. $framedata .= BigEndian2String($frame_data['volumechange']['center'], ceil($frame_data['bitsvolume']/8), FALSE);
  459. $framedata .= BigEndian2String($frame_data['peakvolume']['center'], ceil($frame_data['bitsvolume']/8), FALSE);
  460. }
  461. if ($frame_data['volumechange']['bass'] || $frame_data['peakvolume']['bass']) {
  462. $framedata .= BigEndian2String($frame_data['volumechange']['bass'], ceil($frame_data['bitsvolume']/8), FALSE);
  463. $framedata .= BigEndian2String($frame_data['peakvolume']['bass'], ceil($frame_data['bitsvolume']/8), FALSE);
  464. }
  465. }
  466. break;
  467. case 'EQU2':
  468. // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only)
  469. // Interpolation method $xx
  470. // $00 Band
  471. // $01 Linear
  472. // Identification <text string> $00
  473. // The following is then repeated for every adjustment point
  474. // Frequency $xx xx
  475. // Volume adjustment $xx xx
  476. if (($frame_data['interpolationmethod'] < 0) || ($frame_data['interpolationmethod'] > 1)) {
  477. $error .= 'Invalid Interpolation Method byte in '.$frame_name.' ('.$frame_data['interpolationmethod'].') (valid = 0 or 1)<BR>';
  478. } else {
  479. $framedata .= chr($frame_data['interpolationmethod']);
  480. $framedata .= str_replace(chr(0), '', $frame_data['description']).chr(0);
  481. foreach ($frame_data['data'] as $key => $val) {
  482. $framedata .= BigEndian2String(round($key * 2), 2, FALSE);
  483. $framedata .= substr(str_pad(dechex($val), 4, '0', STR_PAD_LEFT), 4, 4); // signed 16-bit
  484. }
  485. }
  486. break;
  487. case 'EQUA':
  488. // 4.12 EQUA Equalisation (ID3v2.3 only)
  489. // Adjustment bits $xx
  490. // This is followed by 2 bytes + ('adjustment bits' rounded up to the
  491. // nearest byte) for every equalisation band in the following format,
  492. // giving a frequency range of 0 - 32767Hz:
  493. // Increment/decrement %x (MSB of the Frequency)
  494. // Frequency (lower 15 bits)
  495. // Adjustment $xx (xx ...)
  496. if (!IsWithinBitRange($frame_data['bitsvolume'], 8, FALSE)) {
  497. $error .= 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$frame_data['bitsvolume'].') (range = 1 to 255)<BR>';
  498. } else {
  499. $framedata .= chr($frame_data['adjustmentbits']);
  500. foreach ($frame_data as $key => $val) {
  501. if ($key != 'bitsvolume') {
  502. if (($key > 32767) || ($key < 0)) {
  503. $error .= 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)<BR>';
  504. } else {
  505. if ($val >= 0) {
  506. // put MSB of frequency to 1 if increment, 0 if decrement
  507. $key |= 0x8000;
  508. }
  509. $framedata .= BigEndian2String($key, 2, FALSE);
  510. $framedata .= BigEndian2String($val, ceil($frame_data['adjustmentbits'] / 8), FALSE);
  511. }
  512. }
  513. }
  514. }
  515. break;
  516. case 'RVRB':
  517. // 4.13 RVRB Reverb
  518. // Reverb left (ms) $xx xx
  519. // Reverb right (ms) $xx xx
  520. // Reverb bounces, left $xx
  521. // Reverb bounces, right $xx
  522. // Reverb feedback, left to left $xx
  523. // Reverb feedback, left to right $xx
  524. // Reverb feedback, right to right $xx
  525. // Reverb feedback, right to left $xx
  526. // Premix left to right $xx
  527. // Premix right to left $xx
  528. if (!IsWithinBitRange($frame_data['left'], 16, FALSE)) {
  529. $error .= 'Invalid Reverb Left in '.$frame_name.' ('.$frame_data['left'].') (range = 0 to 65535)<BR>';
  530. } else if (!IsWithinBitRange($frame_data['right'], 16, FALSE)) {
  531. $error .= 'Invalid Reverb Left in '.$frame_name.' ('.$frame_data['right'].') (range = 0 to 65535)<BR>';
  532. } else if (!IsWithinBitRange($frame_data['bouncesL'], 8, FALSE)) {
  533. $error .= 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$frame_data['bouncesL'].') (range = 0 to 255)<BR>';
  534. } else if (!IsWithinBitRange($frame_data['bouncesR'], 8, FALSE)) {
  535. $error .= 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$frame_data['bouncesR'].') (range = 0 to 255)<BR>';
  536. } else if (!IsWithinBitRange($frame_data['feedbackLL'], 8, FALSE)) {
  537. $error .= 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$frame_data['feedbackLL'].') (range = 0 to 255)<BR>';
  538. } else if (!IsWithinBitRange($frame_data['feedbackLR'], 8, FALSE)) {
  539. $error .= 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$frame_data['feedbackLR'].') (range = 0 to 255)<BR>';
  540. } else if (!IsWithinBitRange($frame_data['feedbackRR'], 8, FALSE)) {
  541. $error .= 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$frame_data['feedbackRR'].') (range = 0 to 255)<BR>';
  542. } else if (!IsWithinBitRange($frame_data['feedbackRL'], 8, FALSE)) {
  543. $error .= 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$frame_data['feedbackRL'].') (range = 0 to 255)<BR>';
  544. } else if (!IsWithinBitRange($frame_data['premixLR'], 8, FALSE)) {
  545. $error .= 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$frame_data['premixLR'].') (range = 0 to 255)<BR>';
  546. } else if (!IsWithinBitRange($frame_data['premixRL'], 8, FALSE)) {
  547. $error .= 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$frame_data['premixRL'].') (range = 0 to 255)<BR>';
  548. } else {
  549. $framedata .= BigEndian2String($frame_data['left'], 2, FALSE);
  550. $framedata .= BigEndian2String($frame_data['right'], 2, FALSE);
  551. $framedata .= chr($frame_data['bouncesL']);
  552. $framedata .= chr($frame_data['bouncesR']);
  553. $framedata .= chr($frame_data['feedbackLL']);
  554. $framedata .= chr($frame_data['feedbackLR']);
  555. $framedata .= chr($frame_data['feedbackRR']);
  556. $framedata .= chr($frame_data['feedbackRL']);
  557. $framedata .= chr($frame_data['premixLR']);
  558. $framedata .= chr($frame_data['premixRL']);
  559. }
  560. break;
  561. case 'APIC':
  562. // 4.14 APIC Attached picture
  563. // Text encoding $xx
  564. // MIME type <text string> $00
  565. // Picture type $xx
  566. // Description <text string according to encoding> $00 (00)
  567. // Picture data <binary data>
  568. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  569. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  570. } else if (!IsValidAPICpicturetype($frame_data['picturetypeid'], $majorversion)) {
  571. $error .= 'Invalid Picture Type byte in '.$frame_name.' ('.$frame_data['picturetypeid'].') for ID3v2.'.$majorversion.'<BR>';
  572. } else if (($majorversion >= 3) && (!IsValidAPICimageformat($frame_data['mime'], $majorversion))) {
  573. $error .= 'Invalid MIME Type in '.$frame_name.' ('.$frame_data['mime'].') for ID3v2.'.$majorversion.'<BR>';
  574. } else if (($frame_data['mime'] == '-->') && (!IsValidURL($frame_data['data'], FALSE, FALSE))) {
  575. $error .= 'Invalid URL in '.$frame_name.' ('.$frame_data['data'].')<BR>';
  576. } else {
  577. $framedata .= chr($frame_data['encodingid']);
  578. $framedata .= str_replace(chr(0), '', $frame_data['mime']).chr(0);
  579. $framedata .= chr($frame_data['picturetypeid']);
  580. $framedata .= $frame_data['description'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  581. $framedata .= $frame_data['data'];
  582. }
  583. break;
  584. case 'GEOB':
  585. // 4.15 GEOB General encapsulated object
  586. // Text encoding $xx
  587. // MIME type <text string> $00
  588. // Filename <text string according to encoding> $00 (00)
  589. // Content description <text string according to encoding> $00 (00)
  590. // Encapsulated object <binary data>
  591. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  592. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  593. } else if (!IsValidMIMEstring($frame_data['mime'])) {
  594. $error .= 'Invalid MIME Type in '.$frame_name.' ('.$frame_data['mime'].')<BR>';
  595. } else if (!$frame_data['description']) {
  596. $error .= 'Missing Description in '.$frame_name.'<BR>';
  597. } else {
  598. $framedata .= chr($frame_data['encodingid']);
  599. $framedata .= str_replace(chr(0), '', $frame_data['mime']).chr(0);
  600. $framedata .= $frame_data['filename'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  601. $framedata .= $frame_data['description'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  602. $framedata .= $frame_data['data'];
  603. }
  604. break;
  605. case 'PCNT':
  606. // 4.16 PCNT Play counter
  607. // When the counter reaches all one's, one byte is inserted in
  608. // front of the counter thus making the counter eight bits bigger
  609. // Counter $xx xx xx xx (xx ...)
  610. $framedata .= BigEndian2String($frame_data['data'], 4, FALSE);
  611. break;
  612. case 'POPM':
  613. // 4.17 POPM Popularimeter
  614. // When the counter reaches all one's, one byte is inserted in
  615. // front of the counter thus making the counter eight bits bigger
  616. // Email to user <text string> $00
  617. // Rating $xx
  618. // Counter $xx xx xx xx (xx ...)
  619. if (!IsWithinBitRange($frame_data['rating'], 8, FALSE)) {
  620. $error .= 'Invalid Rating byte in '.$frame_name.' ('.$frame_data['rating'].') (range = 0 to 255)<BR>';
  621. } else if (!IsValidEmail($frame_data['email'])) {
  622. $error .= 'Invalid Email in '.$frame_name.' ('.$frame_data['email'].')<BR>';
  623. } else {
  624. $framedata .= str_replace(chr(0), '', $frame_data['email']).chr(0);
  625. $framedata .= chr($frame_data['rating']);
  626. $framedata .= BigEndian2String($frame_data['data'], 4, FALSE);
  627. }
  628. break;
  629. case 'RBUF':
  630. // 4.18 RBUF Recommended buffer size
  631. // Buffer size $xx xx xx
  632. // Embedded info flag %0000000x
  633. // Offset to next tag $xx xx xx xx
  634. if (!IsWithinBitRange($frame_data['buffersize'], 24, FALSE)) {
  635. $error .= 'Invalid Buffer Size in '.$frame_name.'<BR>';
  636. } else if (!IsWithinBitRange($frame_data['nexttagoffset'], 32, FALSE)) {
  637. $error .= 'Invalid Offset To Next Tag in '.$frame_name.'<BR>';
  638. } else {
  639. $framedata .= BigEndian2String($frame_data['buffersize'], 3, FALSE);
  640. $flag .= '0000000';
  641. $flag .= Bool2IntString($frame_data['flags']['embededinfo']);
  642. $framedata .= chr(bindec($flag));
  643. $framedata .= BigEndian2String($frame_data['nexttagoffset'], 4, FALSE);
  644. }
  645. break;
  646. case 'AENC':
  647. // 4.19 AENC Audio encryption
  648. // Owner identifier <text string> $00
  649. // Preview start $xx xx
  650. // Preview length $xx xx
  651. // Encryption info <binary data>
  652. if (!IsWithinBitRange($frame_data['previewstart'], 16, FALSE)) {
  653. $error .= 'Invalid Preview Start in '.$frame_name.' ('.$frame_data['previewstart'].')<BR>';
  654. } else if (!IsWithinBitRange($frame_data['previewlength'], 16, FALSE)) {
  655. $error .= 'Invalid Preview Length in '.$frame_name.' ('.$frame_data['previewlength'].')<BR>';
  656. } else {
  657. $framedata .= str_replace(chr(0), '', $frame_data['ownerid']).chr(0);
  658. $framedata .= BigEndian2String($frame_data['previewstart'], 2, FALSE);
  659. $framedata .= BigEndian2String($frame_data['previewlength'], 2, FALSE);
  660. $framedata .= $frame_data['encryptioninfo'];
  661. }
  662. break;
  663. case 'LINK':
  664. // 4.20 LINK Linked information
  665. // Frame identifier $xx xx xx xx
  666. // URL <text string> $00
  667. // ID and additional data <text string(s)>
  668. if (!IsValidID3v2FrameName($frame_data['frameid'], $majorversion)) {
  669. $error .= 'Invalid Frame Identifier in '.$frame_name.' ('.$frame_data['frameid'].')<BR>';
  670. } else if (!IsValidURL($frame_data['url'], TRUE, FALSE)) {
  671. $error .= 'Invalid URL in '.$frame_name.' ('.$frame_data['url'].')<BR>';
  672. } else if ((($frame_data['frameid'] == 'AENC') || ($frame_data['frameid'] == 'APIC') || ($frame_data['frameid'] == 'GEOB') || ($frame_data['frameid'] == 'TXXX')) && ($frame_data['additionaldata'] == '')) {
  673. $error .= 'Content Descriptor must be specified as additional data for Frame Identifier of '.$frame_data['frameid'].' in '.$frame_name.'<BR>';
  674. } else if (($frame_data['frameid'] == 'USER') && (LanguageLookup($frame_data['additionaldata'], TRUE) == '')) {
  675. $error .= 'Language must be specified as additional data for Frame Identifier of '.$frame_data['frameid'].' in '.$frame_name.'<BR>';
  676. } else if (($frame_data['frameid'] == 'PRIV') && ($frame_data['additionaldata'] == '')) {
  677. $error .= 'Owner Identifier must be specified as additional data for Frame Identifier of '.$frame_data['frameid'].' in '.$frame_name.'<BR>';
  678. } else if ((($frame_data['frameid'] == 'COMM') || ($frame_data['frameid'] == 'SYLT') || ($frame_data['frameid'] == 'USLT')) && ((LanguageLookup(substr($frame_data['additionaldata'], 0, 3), TRUE) == '') || (substr($frame_data['additionaldata'], 3) == ''))) {
  679. $error .= 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$frame_data['frameid'].' in '.$frame_name.'<BR>';
  680. } else {
  681. $framedata .= $frame_data['frameid'];
  682. $framedata .= str_replace(chr(0), '', $frame_data['url']).chr(0);
  683. switch ($frame_data['frameid']) {
  684. case 'COMM':
  685. case 'SYLT':
  686. case 'USLT':
  687. case 'PRIV':
  688. case 'USER':
  689. case 'AENC':
  690. case 'APIC':
  691. case 'GEOB':
  692. case 'TXXX':
  693. $framedata .= $frame_data['additionaldata'];
  694. break;
  695. case 'ASPI':
  696. case 'ETCO':
  697. case 'EQU2':
  698. case 'MCID':
  699. case 'MLLT':
  700. case 'OWNE':
  701. case 'RVA2':
  702. case 'RVRB':
  703. case 'SYTC':
  704. case 'IPLS':
  705. case 'RVAD':
  706. case 'EQUA':
  707. // no additional data required
  708. break;
  709. case 'RBUF':
  710. if ($majorversion == 3) {
  711. // no additional data required
  712. } else {
  713. $error .= $frame_data['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$majorversion.')<BR>';
  714. }
  715. default:
  716. if ((substr($frame_data['frameid'], 0, 1) == 'T') || (substr($frame_data['frameid'], 0, 1) == 'W')) {
  717. // no additional data required
  718. } else {
  719. $error .= $frame_data['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$majorversion.')<BR>';
  720. }
  721. break;
  722. }
  723. }
  724. break;
  725. case 'POSS':
  726. // 4.21 POSS Position synchronisation frame (ID3v2.3+ only)
  727. // Time stamp format $xx
  728. // Position $xx (xx ...)
  729. if (($frame_data['timestampformat'] < 1) || ($frame_data['timestampformat'] > 2)) {
  730. $error .= 'Invalid Time Stamp Format in '.$frame_name.' ('.$frame_data['timestampformat'].') (valid = 1 or 2)<BR>';
  731. } else if (!IsWithinBitRange($frame_data['position'], 32, FALSE)) {
  732. $error .= 'Invalid Position in '.$frame_name.' ('.$frame_data['position'].') (range = 0 to 4294967295)<BR>';
  733. } else {
  734. $framedata .= chr($frame_data['timestampformat']);
  735. $framedata .= BigEndian2String($frame_data['position'], 4, FALSE);
  736. }
  737. break;
  738. case 'USER':
  739. // 4.22 USER Terms of use (ID3v2.3+ only)
  740. // Text encoding $xx
  741. // Language $xx xx xx
  742. // The actual text <text string according to encoding>
  743. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  744. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].')<BR>';
  745. } else if (LanguageLookup($frame_data['language'], TRUE) == '') {
  746. $error .= 'Invalid Language in '.$frame_name.' ('.$frame_data['language'].')<BR>';
  747. } else {
  748. $framedata .= chr($frame_data['encodingid']);
  749. $framedata .= strtolower($frame_data['language']);
  750. $framedata .= $frame_data['data'];
  751. }
  752. break;
  753. case 'OWNE':
  754. // 4.23 OWNE Ownership frame (ID3v2.3+ only)
  755. // Text encoding $xx
  756. // Price paid <text string> $00
  757. // Date of purch. <text string>
  758. // Seller <text string according to encoding>
  759. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  760. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].')<BR>';
  761. } else if (!IsANumber($frame_data['pricepaid']['value'], FALSE)) {
  762. $error .= 'Invalid Price Paid in '.$frame_name.' ('.$frame_data['pricepaid']['value'].')<BR>';
  763. } else if (!IsValidDateStampString($frame_data['purchasedate'])) {
  764. $error .= 'Invalid Date Of Purchase in '.$frame_name.' ('.$frame_data['purchasedate'].') (format = YYYYMMDD)<BR>';
  765. } else {
  766. $framedata .= chr($frame_data['encodingid']);
  767. $framedata .= str_replace(chr(0), '', $frame_data['pricepaid']['value']).chr(0);
  768. $framedata .= $frame_data['purchasedate'];
  769. $framedata .= $frame_data['seller'];
  770. }
  771. break;
  772. case 'COMR':
  773. // 4.24 COMR Commercial frame (ID3v2.3+ only)
  774. // Text encoding $xx
  775. // Price string <text string> $00
  776. // Valid until <text string>
  777. // Contact URL <text string> $00
  778. // Received as $xx
  779. // Name of seller <text string according to encoding> $00 (00)
  780. // Description <text string according to encoding> $00 (00)
  781. // Picture MIME type <string> $00
  782. // Seller logo <binary data>
  783. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  784. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].')<BR>';
  785. } else if (!IsValidDateStampString($frame_data['pricevaliduntil'])) {
  786. $error .= 'Invalid Valid Until date in '.$frame_name.' ('.$frame_data['pricevaliduntil'].') (format = YYYYMMDD)<BR>';
  787. } else if (!IsValidURL($frame_data['contacturl'], FALSE, TRUE)) {
  788. $error .= 'Invalid Contact URL in '.$frame_name.' ('.$frame_data['contacturl'].') (allowed schemes: http, https, ftp, mailto)<BR>';
  789. } else if (!IsValidCOMRreceivedas($frame_data['receivedasid'], $majorversion)) {
  790. $error .= 'Invalid Received As byte in '.$frame_name.' ('.$frame_data['contacturl'].') (range = 0 to 8)<BR>';
  791. } else if (!IsValidMIMEstring($frame_data['mime'])) {
  792. $error .= 'Invalid MIME Type in '.$frame_name.' ('.$frame_data['mime'].')<BR>';
  793. } else {
  794. $framedata .= chr($frame_data['encodingid']);
  795. unset($pricestring);
  796. foreach ($frame_data['price'] as $key => $val) {
  797. if (IsValidPriceString($key.$val['value'])) {
  798. $pricestrings[] = $key.$val['value'];
  799. } else {
  800. $error .= 'Invalid Price String in '.$frame_name.' ('.$key.$val['value'].')<BR>';
  801. }
  802. }
  803. $framedata .= implode('/', $pricestrings);
  804. $framedata .= $frame_data['pricevaliduntil'];
  805. $framedata .= str_replace(chr(0), '', $frame_data['contacturl']).chr(0);
  806. $framedata .= chr($frame_data['receivedasid']);
  807. $framedata .= $frame_data['sellername'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  808. $framedata .= $frame_data['description'].TextEncodingLookup('terminator', $frame_data['encodingid']);
  809. $framedata .= $frame_data['mime'].chr(0);
  810. $framedata .= $frame_data['logo'];
  811. }
  812. break;
  813. case 'ENCR':
  814. // 4.25 ENCR Encryption method registration (ID3v2.3+ only)
  815. // Owner identifier <text string> $00
  816. // Method symbol $xx
  817. // Encryption data <binary data>
  818. if (!IsWithinBitRange($frame_data['methodsymbol'], 8, FALSE)) {
  819. $error .= 'Invalid Group Symbol in '.$frame_name.' ('.$frame_data['methodsymbol'].') (range = 0 to 255)<BR>';
  820. } else {
  821. $framedata .= str_replace(chr(0), '', $frame_data['ownerid']).chr(0);
  822. $framedata .= ord($frame_data['methodsymbol']);
  823. $framedata .= $frame_data['data'];
  824. }
  825. break;
  826. case 'GRID':
  827. // 4.26 GRID Group identification registration (ID3v2.3+ only)
  828. // Owner identifier <text string> $00
  829. // Group symbol $xx
  830. // Group dependent data <binary data>
  831. if (!IsWithinBitRange($frame_data['groupsymbol'], 8, FALSE)) {
  832. $error .= 'Invalid Group Symbol in '.$frame_name.' ('.$frame_data['groupsymbol'].') (range = 0 to 255)<BR>';
  833. } else {
  834. $framedata .= str_replace(chr(0), '', $frame_data['ownerid']).chr(0);
  835. $framedata .= ord($frame_data['groupsymbol']);
  836. $framedata .= $frame_data['data'];
  837. }
  838. break;
  839. case 'PRIV':
  840. // 4.27 PRIV Private frame (ID3v2.3+ only)
  841. // Owner identifier <text string> $00
  842. // The private data <binary data>
  843. $framedata .= str_replace(chr(0), '', $frame_data['ownerid']).chr(0);
  844. $framedata .= $frame_data['data'];
  845. break;
  846. case 'SIGN':
  847. // 4.28 SIGN Signature frame (ID3v2.4+ only)
  848. // Group symbol $xx
  849. // Signature <binary data>
  850. if (!IsWithinBitRange($frame_data['groupsymbol'], 8, FALSE)) {
  851. $error .= 'Invalid Group Symbol in '.$frame_name.' ('.$frame_data['groupsymbol'].') (range = 0 to 255)<BR>';
  852. } else {
  853. $framedata .= ord($frame_data['groupsymbol']);
  854. $framedata .= $frame_data['data'];
  855. }
  856. break;
  857. case 'SEEK':
  858. // 4.29 SEEK Seek frame (ID3v2.4+ only)
  859. // Minimum offset to next tag $xx xx xx xx
  860. if (!IsWithinBitRange($frame_data['data'], 32, FALSE)) {
  861. $error .= 'Invalid Minimum Offset in '.$frame_name.' ('.$frame_data['data'].') (range = 0 to 4294967295)<BR>';
  862. } else {
  863. $framedata .= BigEndian2String($frame_data['data'], 4, FALSE);
  864. }
  865. break;
  866. case 'ASPI':
  867. // 4.30 ASPI Audio seek point index (ID3v2.4+ only)
  868. // Indexed data start (S) $xx xx xx xx
  869. // Indexed data length (L) $xx xx xx xx
  870. // Number of index points (N) $xx xx
  871. // Bits per index point (b) $xx
  872. // Then for every index point the following data is included:
  873. // Fraction at index (Fi) $xx (xx)
  874. if (!IsWithinBitRange($frame_data['datastart'], 32, FALSE)) {
  875. $error .= 'Invalid Indexed Data Start in '.$frame_name.' ('.$frame_data['datastart'].') (range = 0 to 4294967295)<BR>';
  876. } else if (!IsWithinBitRange($frame_data['datalength'], 32, FALSE)) {
  877. $error .= 'Invalid Indexed Data Length in '.$frame_name.' ('.$frame_data['datalength'].') (range = 0 to 4294967295)<BR>';
  878. } else if (!IsWithinBitRange($frame_data['indexpoints'], 16, FALSE)) {
  879. $error .= 'Invalid Number Of Index Points in '.$frame_name.' ('.$frame_data['indexpoints'].') (range = 0 to 65535)<BR>';
  880. } else if (!IsWithinBitRange($frame_data['bitsperpoint'], 8, FALSE)) {
  881. $error .= 'Invalid Bits Per Index Point in '.$frame_name.' ('.$frame_data['bitsperpoint'].') (range = 0 to 255)<BR>';
  882. } else if ($frame_data['indexpoints'] != count($frame_data['indexes'])) {
  883. $error .= 'Number Of Index Points does not match actual supplied data in '.$frame_name.'<BR>';
  884. } else {
  885. $framedata .= BigEndian2String($frame_data['datastart'], 4, FALSE);
  886. $framedata .= BigEndian2String($frame_data['datalength'], 4, FALSE);
  887. $framedata .= BigEndian2String($frame_data['indexpoints'], 2, FALSE);
  888. $framedata .= BigEndian2String($frame_data['bitsperpoint'], 1, FALSE);
  889. foreach ($frame_data['indexes'] as $key => $val) {
  890. $framedata .= BigEndian2String($val, ceil($frame_data['bitsperpoint'] / 8), FALSE);
  891. }
  892. }
  893. break;
  894. case 'RGAD':
  895. // RGAD Replay Gain Adjustment
  896. // http://privatewww.essex.ac.uk/~djmrob/replaygain/
  897. // Peak Amplitude $xx $xx $xx $xx
  898. // Radio Replay Gain Adjustment %aaabbbcd %dddddddd
  899. // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd
  900. // a - name code
  901. // b - originator code
  902. // c - sign bit
  903. // d - replay gain adjustment
  904. if (($frame_data['radio_adjustment'] > 51) || ($frame_data['radio_adjustment'] < -51)) {
  905. $error .= 'Invalid Radio Adjustment in '.$frame_name.' ('.$frame_data['radio_adjustment'].') (range = -51.0 to +51.0)<BR>';
  906. } else if (($frame_data['audiophile_adjustment'] > 51) || ($frame_data['audiophile_adjustment'] < -51)) {
  907. $error .= 'Invalid Audiophile Adjustment in '.$frame_name.' ('.$frame_data['audiophile_adjustment'].') (range = -51.0 to +51.0)<BR>';
  908. } else if (!IsValidRGADname($frame_data['raw']['radio_name'], $majorversion)) {
  909. $error .= 'Invalid Radio Name Code in '.$frame_name.' ('.$frame_data['raw']['radio_name'].') (range = 0 to 2)<BR>';
  910. } else if (!IsValidRGADname($frame_data['raw']['audiophile_name'], $majorversion)) {
  911. $error .= 'Invalid Audiophile Name Code in '.$frame_name.' ('.$frame_data['raw']['audiophile_name'].') (range = 0 to 2)<BR>';
  912. } else if (!IsValidRGADoriginator($frame_data['raw']['radio_originator'], $majorversion)) {
  913. $error .= 'Invalid Radio Originator Code in '.$frame_name.' ('.$frame_data['raw']['radio_originator'].') (range = 0 to 3)<BR>';
  914. } else if (!IsValidRGADoriginator($frame_data['raw']['audiophile_originator'], $majorversion)) {
  915. $error .= 'Invalid Audiophile Originator Code in '.$frame_name.' ('.$frame_data['raw']['audiophile_originator'].') (range = 0 to 3)<BR>';
  916. } else {
  917. $framedata .= Float2String($frame_data['peakamplitude'], 32);
  918. $framedata .= RGADgainString($frame_data['raw']['radio_name'], $frame_data['raw']['radio_originator'], $frame_data['radio_adjustment']);
  919. $framedata .= RGADgainString($frame_data['raw']['audiophile_name'], $frame_data['raw']['audiophile_originator'], $frame_data['audiophile_adjustment']);
  920. }
  921. break;
  922. default:
  923. if ($frame_name{0} == 'T') {
  924. // 4.2. T??? Text information frames
  925. // Text encoding $xx
  926. // Information <text string(s) according to encoding>
  927. if (!IsValidTextEncoding($frame_data['encodingid'], $majorversion)) {
  928. $error .= 'Invalid Text Encoding in '.$frame_name.' ('.$frame_data['encodingid'].') for ID3v2.'.$majorversion.'<BR>';
  929. } else {
  930. $framedata .= chr($frame_data['encodingid']);
  931. $framedata .= $frame_data['data'];
  932. }
  933. } else if ($frame_name{0} == 'W') {
  934. // 4.3. W??? URL link frames
  935. // URL <text string>
  936. if (!IsValidURL($frame_data['url'], FALSE, FALSE)) {
  937. $error .= 'Invalid URL in '.$frame_name.' ('.$frame_data['url'].')<BR>';
  938. } else {
  939. $framedata .= $frame_data['url'];
  940. }
  941. } else {
  942. $error .= $frame_name.' not yet supported in putid3.php<BR>';
  943. }
  944. break;
  945. }
  946. }
  947. if ($error) {
  948. if ($showerrors) {
  949. echo $error;
  950. }
  951. return FALSE;
  952. } else {
  953. return $framedata;
  954. }
  955. }
  956. function ID3v2FrameIsAllowed($frame_name, $frame_data, $majorversion, $showerrors=FALSE) {
  957. static $PreviousFrames = array();
  958. if ($frame_name === NULL) {
  959. // if the writing functions are called multiple times, the static array needs to be
  960. // cleared - this can be done by calling ID3v2FrameIsAllowed(NULL, '', '')
  961. $PreviousFrames = array();
  962. return TRUE;
  963. }
  964. if ($majorversion == 4) {
  965. switch ($frame_name) {
  966. case

Large files files are truncated, but you can click here to view the full file