PageRenderTime 49ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/vendor/getid3-1.9.0/getid3/write.id3v2.php

http://streeme.googlecode.com/
PHP | 1230 lines | 882 code | 94 blank | 254 comment | 278 complexity | cfccc1e1b07fee2303968da292fb7c7a MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, ISC, AGPL-3.0, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full 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. // write.id3v2.php //
  11. // module for writing ID3v2 tags //
  12. // dependencies: module.tag.id3v2.php //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
  16. class getid3_write_id3v2
  17. {
  18. var $filename;
  19. var $tag_data;
  20. var $fread_buffer_size = 32768; // read buffer size in bytes
  21. var $paddedlength = 4096; // minimum length of ID3v2 tag in bytes
  22. var $majorversion = 3; // ID3v2 major version (2, 3 (recommended), 4)
  23. var $minorversion = 0; // ID3v2 minor version - always 0
  24. var $merge_existing_data = false; // if true, merge new data with existing tags; if false, delete old tag data and only write new tags
  25. var $id3v2_default_encodingid = 0; // default text encoding (ISO-8859-1) if not explicitly passed
  26. var $id3v2_use_unsynchronisation = false; // the specs say it should be TRUE, but most other ID3v2-aware programs are broken if unsynchronization is used, so by default don't use it.
  27. var $warnings = array(); // any non-critical errors will be stored here
  28. var $errors = array(); // any critical errors will be stored here
  29. function getid3_write_id3v2() {
  30. return true;
  31. }
  32. function WriteID3v2() {
  33. // File MUST be writeable - CHMOD(646) at least. It's best if the
  34. // directory is also writeable, because that method is both faster and less susceptible to errors.
  35. if (!empty($this->filename) && (is_writeable($this->filename) || (!file_exists($this->filename) && is_writeable(dirname($this->filename))))) {
  36. // Initialize getID3 engine
  37. $getID3 = new getID3;
  38. $OldThisFileInfo = $getID3->analyze($this->filename);
  39. if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
  40. $this->errors[] = 'Unable to write ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
  41. fclose($fp_source);
  42. return false;
  43. }
  44. if ($this->merge_existing_data) {
  45. // merge with existing data
  46. if (!empty($OldThisFileInfo['id3v2'])) {
  47. $this->tag_data = $this->array_join_merge($OldThisFileInfo['id3v2'], $this->tag_data);
  48. }
  49. }
  50. $this->paddedlength = (isset($OldThisFileInfo['id3v2']['headerlength']) ? max($OldThisFileInfo['id3v2']['headerlength'], $this->paddedlength) : $this->paddedlength);
  51. if ($NewID3v2Tag = $this->GenerateID3v2Tag()) {
  52. if (file_exists($this->filename) && is_writeable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) {
  53. // best and fastest method - insert-overwrite existing tag (padded to length of old tag if neccesary)
  54. if (file_exists($this->filename)) {
  55. if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'r+b'))) {
  56. rewind($fp);
  57. fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
  58. fclose($fp);
  59. } else {
  60. $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")';
  61. }
  62. } else {
  63. if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'wb'))) {
  64. rewind($fp);
  65. fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
  66. fclose($fp);
  67. } else {
  68. $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")';
  69. }
  70. }
  71. } else {
  72. if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) {
  73. if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
  74. if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) {
  75. fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag));
  76. rewind($fp_source);
  77. if (!empty($OldThisFileInfo['avdataoffset'])) {
  78. fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET);
  79. }
  80. while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
  81. fwrite($fp_temp, $buffer, strlen($buffer));
  82. }
  83. fclose($fp_temp);
  84. fclose($fp_source);
  85. copy($tempfilename, $this->filename);
  86. unlink($tempfilename);
  87. return true;
  88. } else {
  89. $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")';
  90. }
  91. fclose($fp_source);
  92. } else {
  93. $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
  94. }
  95. }
  96. return false;
  97. }
  98. } else {
  99. $this->errors[] = '$this->GenerateID3v2Tag() failed';
  100. }
  101. if (!empty($this->errors)) {
  102. return false;
  103. }
  104. return true;
  105. } else {
  106. $this->errors[] = 'WriteID3v2() failed: !is_writeable('.$this->filename.')';
  107. }
  108. return false;
  109. }
  110. function RemoveID3v2() {
  111. // File MUST be writeable - CHMOD(646) at least. It's best if the
  112. // directory is also writeable, because that method is both faster and less susceptible to errors.
  113. if (is_writeable(dirname($this->filename))) {
  114. // preferred method - only one copying operation, minimal chance of corrupting
  115. // original file if script is interrupted, but required directory to be writeable
  116. if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
  117. // Initialize getID3 engine
  118. $getID3 = new getID3;
  119. $OldThisFileInfo = $getID3->analyze($this->filename);
  120. if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
  121. $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
  122. fclose($fp_source);
  123. return false;
  124. }
  125. rewind($fp_source);
  126. if ($OldThisFileInfo['avdataoffset'] !== false) {
  127. fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET);
  128. }
  129. if (is_writable($this->filename) && is_file($this->filename) && ($fp_temp = fopen($this->filename.'getid3tmp', 'w+b'))) {
  130. while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
  131. fwrite($fp_temp, $buffer, strlen($buffer));
  132. }
  133. fclose($fp_temp);
  134. } else {
  135. $this->errors[] = 'Could not fopen("'.$this->filename.'getid3tmp", "w+b")';
  136. }
  137. fclose($fp_source);
  138. } else {
  139. $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
  140. }
  141. if (file_exists($this->filename)) {
  142. unlink($this->filename);
  143. }
  144. rename($this->filename.'getid3tmp', $this->filename);
  145. } elseif (is_writable($this->filename)) {
  146. // less desirable alternate method - double-copies the file, overwrites original file
  147. // and could corrupt source file if the script is interrupted or an error occurs.
  148. if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
  149. // Initialize getID3 engine
  150. $getID3 = new getID3;
  151. $OldThisFileInfo = $getID3->analyze($this->filename);
  152. if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
  153. $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
  154. fclose($fp_source);
  155. return false;
  156. }
  157. rewind($fp_source);
  158. if ($OldThisFileInfo['avdataoffset'] !== false) {
  159. fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET);
  160. }
  161. if ($fp_temp = tmpfile()) {
  162. while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
  163. fwrite($fp_temp, $buffer, strlen($buffer));
  164. }
  165. fclose($fp_source);
  166. if (is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'wb'))) {
  167. rewind($fp_temp);
  168. while ($buffer = fread($fp_temp, $this->fread_buffer_size)) {
  169. fwrite($fp_source, $buffer, strlen($buffer));
  170. }
  171. fseek($fp_temp, -128, SEEK_END);
  172. fclose($fp_source);
  173. } else {
  174. $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")';
  175. }
  176. fclose($fp_temp);
  177. } else {
  178. $this->errors[] = 'Could not create tmpfile()';
  179. }
  180. } else {
  181. $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
  182. }
  183. } else {
  184. $this->errors[] = 'Directory and file both not writeable';
  185. }
  186. if (!empty($this->errors)) {
  187. return false;
  188. }
  189. return true;
  190. }
  191. function GenerateID3v2TagFlags($flags) {
  192. switch ($this->majorversion) {
  193. case 4:
  194. // %abcd0000
  195. $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
  196. $flag .= (!empty($flags['extendedheader'] ) ? '1' : '0'); // b - Extended header
  197. $flag .= (!empty($flags['experimental'] ) ? '1' : '0'); // c - Experimental indicator
  198. $flag .= (!empty($flags['footer'] ) ? '1' : '0'); // d - Footer present
  199. $flag .= '0000';
  200. break;
  201. case 3:
  202. // %abc00000
  203. $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
  204. $flag .= (!empty($flags['extendedheader'] ) ? '1' : '0'); // b - Extended header
  205. $flag .= (!empty($flags['experimental'] ) ? '1' : '0'); // c - Experimental indicator
  206. $flag .= '00000';
  207. break;
  208. case 2:
  209. // %ab000000
  210. $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
  211. $flag .= (!empty($flags['compression'] ) ? '1' : '0'); // b - Compression
  212. $flag .= '000000';
  213. break;
  214. default:
  215. return false;
  216. break;
  217. }
  218. return chr(bindec($flag));
  219. }
  220. function GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false) {
  221. switch ($this->majorversion) {
  222. case 4:
  223. // %0abc0000 %0h00kmnp
  224. $flag1 = '0';
  225. $flag1 .= $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard)
  226. $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard)
  227. $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only)
  228. $flag1 .= '0000';
  229. $flag2 = '0';
  230. $flag2 .= $GroupingIdentity ? '1' : '0'; // h - Grouping identity (true == contains group information)
  231. $flag2 .= '00';
  232. $flag2 .= $Compression ? '1' : '0'; // k - Compression (true == compressed)
  233. $flag2 .= $Encryption ? '1' : '0'; // m - Encryption (true == encrypted)
  234. $flag2 .= $Unsynchronisation ? '1' : '0'; // n - Unsynchronisation (true == unsynchronised)
  235. $flag2 .= $DataLengthIndicator ? '1' : '0'; // p - Data length indicator (true == data length indicator added)
  236. break;
  237. case 3:
  238. // %abc00000 %ijk00000
  239. $flag1 = $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard)
  240. $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard)
  241. $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only)
  242. $flag1 .= '00000';
  243. $flag2 = $Compression ? '1' : '0'; // i - Compression (true == compressed)
  244. $flag2 .= $Encryption ? '1' : '0'; // j - Encryption (true == encrypted)
  245. $flag2 .= $GroupingIdentity ? '1' : '0'; // k - Grouping identity (true == contains group information)
  246. $flag2 .= '00000';
  247. break;
  248. default:
  249. return false;
  250. break;
  251. }
  252. return chr(bindec($flag1)).chr(bindec($flag2));
  253. }
  254. function GenerateID3v2FrameData($frame_name, $source_data_array) {
  255. if (!getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
  256. return false;
  257. }
  258. $framedata = '';
  259. if (($this->majorversion < 3) || ($this->majorversion > 4)) {
  260. $this->errors[] = 'Only ID3v2.3 and ID3v2.4 are supported in GenerateID3v2FrameData()';
  261. } else { // $this->majorversion 3 or 4
  262. switch ($frame_name) {
  263. case 'UFID':
  264. // 4.1 UFID Unique file identifier
  265. // Owner identifier <text string> $00
  266. // Identifier <up to 64 bytes binary data>
  267. if (strlen($source_data_array['data']) > 64) {
  268. $this->errors[] = 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($source_data_array['data']).' bytes long)';
  269. } else {
  270. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  271. $framedata .= substr($source_data_array['data'], 0, 64); // max 64 bytes - truncate anything longer
  272. }
  273. break;
  274. case 'TXXX':
  275. // 4.2.2 TXXX User defined text information frame
  276. // Text encoding $xx
  277. // Description <text string according to encoding> $00 (00)
  278. // Value <text string according to encoding>
  279. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  280. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  281. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  282. } else {
  283. $framedata .= chr($source_data_array['encodingid']);
  284. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  285. $framedata .= $source_data_array['data'];
  286. }
  287. break;
  288. case 'WXXX':
  289. // 4.3.2 WXXX User defined URL link frame
  290. // Text encoding $xx
  291. // Description <text string according to encoding> $00 (00)
  292. // URL <text string>
  293. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  294. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  295. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  296. } elseif (!isset($source_data_array['data']) || !$this->IsValidURL($source_data_array['data'], false, false)) {
  297. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  298. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  299. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  300. } else {
  301. $framedata .= chr($source_data_array['encodingid']);
  302. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  303. $framedata .= $source_data_array['data'];
  304. }
  305. break;
  306. case 'IPLS':
  307. // 4.4 IPLS Involved people list (ID3v2.3 only)
  308. // Text encoding $xx
  309. // People list strings <textstrings>
  310. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  311. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  312. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  313. } else {
  314. $framedata .= chr($source_data_array['encodingid']);
  315. $framedata .= $source_data_array['data'];
  316. }
  317. break;
  318. case 'MCDI':
  319. // 4.4 MCDI Music CD identifier
  320. // CD TOC <binary data>
  321. $framedata .= $source_data_array['data'];
  322. break;
  323. case 'ETCO':
  324. // 4.5 ETCO Event timing codes
  325. // Time stamp format $xx
  326. // Where time stamp format is:
  327. // $01 (32-bit value) MPEG frames from beginning of file
  328. // $02 (32-bit value) milliseconds from beginning of file
  329. // Followed by a list of key events in the following format:
  330. // Type of event $xx
  331. // Time stamp $xx (xx ...)
  332. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  333. // or after the previous event. All events MUST be sorted in chronological order.
  334. if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  335. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  336. } else {
  337. $framedata .= chr($source_data_array['timestampformat']);
  338. foreach ($source_data_array as $key => $val) {
  339. if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
  340. $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
  341. } elseif (($key != 'timestampformat') && ($key != 'flags')) {
  342. if (($val['timestamp'] > 0) && ($previousETCOtimestamp >= $val['timestamp'])) {
  343. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  344. // or after the previous event. All events MUST be sorted in chronological order.
  345. $this->errors[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')';
  346. } else {
  347. $framedata .= chr($val['typeid']);
  348. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  349. }
  350. }
  351. }
  352. }
  353. break;
  354. case 'MLLT':
  355. // 4.6 MLLT MPEG location lookup table
  356. // MPEG frames between reference $xx xx
  357. // Bytes between reference $xx xx xx
  358. // Milliseconds between reference $xx xx xx
  359. // Bits for bytes deviation $xx
  360. // Bits for milliseconds dev. $xx
  361. // Then for every reference the following data is included;
  362. // Deviation in bytes %xxx....
  363. // Deviation in milliseconds %xxx....
  364. if (($source_data_array['framesbetweenreferences'] > 0) && ($source_data_array['framesbetweenreferences'] <= 65535)) {
  365. $framedata .= getid3_lib::BigEndian2String($source_data_array['framesbetweenreferences'], 2, false);
  366. } else {
  367. $this->errors[] = 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$source_data_array['framesbetweenreferences'].')';
  368. }
  369. if (($source_data_array['bytesbetweenreferences'] > 0) && ($source_data_array['bytesbetweenreferences'] <= 16777215)) {
  370. $framedata .= getid3_lib::BigEndian2String($source_data_array['bytesbetweenreferences'], 3, false);
  371. } else {
  372. $this->errors[] = 'Invalid bytes Between References in '.$frame_name.' ('.$source_data_array['bytesbetweenreferences'].')';
  373. }
  374. if (($source_data_array['msbetweenreferences'] > 0) && ($source_data_array['msbetweenreferences'] <= 16777215)) {
  375. $framedata .= getid3_lib::BigEndian2String($source_data_array['msbetweenreferences'], 3, false);
  376. } else {
  377. $this->errors[] = 'Invalid Milliseconds Between References in '.$frame_name.' ('.$source_data_array['msbetweenreferences'].')';
  378. }
  379. if (!$this->IsWithinBitRange($source_data_array['bitsforbytesdeviation'], 8, false)) {
  380. if (($source_data_array['bitsforbytesdeviation'] % 4) == 0) {
  381. $framedata .= chr($source_data_array['bitsforbytesdeviation']);
  382. } else {
  383. $this->errors[] = 'Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
  384. }
  385. } else {
  386. $this->errors[] = 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].')';
  387. }
  388. if (!$this->IsWithinBitRange($source_data_array['bitsformsdeviation'], 8, false)) {
  389. if (($source_data_array['bitsformsdeviation'] % 4) == 0) {
  390. $framedata .= chr($source_data_array['bitsformsdeviation']);
  391. } else {
  392. $this->errors[] = 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
  393. }
  394. } else {
  395. $this->errors[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')';
  396. }
  397. foreach ($source_data_array as $key => $val) {
  398. if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) {
  399. $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT);
  400. $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['msdeviation']), $source_data_array['bitsformsdeviation'], '0', STR_PAD_LEFT);
  401. }
  402. }
  403. for ($i = 0; $i < strlen($unwrittenbitstream); $i += 8) {
  404. $highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4;
  405. $lownibble = bindec(substr($unwrittenbitstream, $i + 4, 4));
  406. $framedata .= chr($highnibble & $lownibble);
  407. }
  408. break;
  409. case 'SYTC':
  410. // 4.7 SYTC Synchronised tempo codes
  411. // Time stamp format $xx
  412. // Tempo data <binary data>
  413. // Where time stamp format is:
  414. // $01 (32-bit value) MPEG frames from beginning of file
  415. // $02 (32-bit value) milliseconds from beginning of file
  416. if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  417. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  418. } else {
  419. $framedata .= chr($source_data_array['timestampformat']);
  420. foreach ($source_data_array as $key => $val) {
  421. if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
  422. $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
  423. } elseif (($key != 'timestampformat') && ($key != 'flags')) {
  424. if (($val['tempo'] < 0) || ($val['tempo'] > 510)) {
  425. $this->errors[] = 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')';
  426. } else {
  427. if ($val['tempo'] > 255) {
  428. $framedata .= chr(255);
  429. $val['tempo'] -= 255;
  430. }
  431. $framedata .= chr($val['tempo']);
  432. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  433. }
  434. }
  435. }
  436. }
  437. break;
  438. case 'USLT':
  439. // 4.8 USLT Unsynchronised lyric/text transcription
  440. // Text encoding $xx
  441. // Language $xx xx xx
  442. // Content descriptor <text string according to encoding> $00 (00)
  443. // Lyrics/text <full text string according to encoding>
  444. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  445. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  446. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  447. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  448. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  449. } else {
  450. $framedata .= chr($source_data_array['encodingid']);
  451. $framedata .= strtolower($source_data_array['language']);
  452. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  453. $framedata .= $source_data_array['data'];
  454. }
  455. break;
  456. case 'SYLT':
  457. // 4.9 SYLT Synchronised lyric/text
  458. // Text encoding $xx
  459. // Language $xx xx xx
  460. // Time stamp format $xx
  461. // $01 (32-bit value) MPEG frames from beginning of file
  462. // $02 (32-bit value) milliseconds from beginning of file
  463. // Content type $xx
  464. // Content descriptor <text string according to encoding> $00 (00)
  465. // Terminated text to be synced (typically a syllable)
  466. // Sync identifier (terminator to above string) $00 (00)
  467. // Time stamp $xx (xx ...)
  468. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  469. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  470. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  471. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  472. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  473. } elseif (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  474. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  475. } elseif (!$this->ID3v2IsValidSYLTtype($source_data_array['contenttypeid'])) {
  476. $this->errors[] = 'Invalid Content Type byte in '.$frame_name.' ('.$source_data_array['contenttypeid'].')';
  477. } elseif (!is_array($source_data_array['data'])) {
  478. $this->errors[] = 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)';
  479. } else {
  480. $framedata .= chr($source_data_array['encodingid']);
  481. $framedata .= strtolower($source_data_array['language']);
  482. $framedata .= chr($source_data_array['timestampformat']);
  483. $framedata .= chr($source_data_array['contenttypeid']);
  484. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  485. ksort($source_data_array['data']);
  486. foreach ($source_data_array['data'] as $key => $val) {
  487. $framedata .= $val['data'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  488. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  489. }
  490. }
  491. break;
  492. case 'COMM':
  493. // 4.10 COMM Comments
  494. // Text encoding $xx
  495. // Language $xx xx xx
  496. // Short content descrip. <text string according to encoding> $00 (00)
  497. // The actual text <full text string according to encoding>
  498. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  499. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  500. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  501. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  502. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  503. } else {
  504. $framedata .= chr($source_data_array['encodingid']);
  505. $framedata .= strtolower($source_data_array['language']);
  506. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  507. $framedata .= $source_data_array['data'];
  508. }
  509. break;
  510. case 'RVA2':
  511. // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only)
  512. // Identification <text string> $00
  513. // The 'identification' string is used to identify the situation and/or
  514. // device where this adjustment should apply. The following is then
  515. // repeated for every channel:
  516. // Type of channel $xx
  517. // Volume adjustment $xx xx
  518. // Bits representing peak $xx
  519. // Peak volume $xx (xx ...)
  520. $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
  521. foreach ($source_data_array as $key => $val) {
  522. if ($key != 'description') {
  523. $framedata .= chr($val['channeltypeid']);
  524. $framedata .= getid3_lib::BigEndian2String($val['volumeadjust'], 2, false, true); // signed 16-bit
  525. if (!$this->IsWithinBitRange($source_data_array['bitspeakvolume'], 8, false)) {
  526. $framedata .= chr($val['bitspeakvolume']);
  527. if ($val['bitspeakvolume'] > 0) {
  528. $framedata .= getid3_lib::BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), false, false);
  529. }
  530. } else {
  531. $this->errors[] = 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)';
  532. }
  533. }
  534. }
  535. break;
  536. case 'RVAD':
  537. // 4.12 RVAD Relative volume adjustment (ID3v2.3 only)
  538. // Increment/decrement %00fedcba
  539. // Bits used for volume descr. $xx
  540. // Relative volume change, right $xx xx (xx ...) // a
  541. // Relative volume change, left $xx xx (xx ...) // b
  542. // Peak volume right $xx xx (xx ...)
  543. // Peak volume left $xx xx (xx ...)
  544. // Relative volume change, right back $xx xx (xx ...) // c
  545. // Relative volume change, left back $xx xx (xx ...) // d
  546. // Peak volume right back $xx xx (xx ...)
  547. // Peak volume left back $xx xx (xx ...)
  548. // Relative volume change, center $xx xx (xx ...) // e
  549. // Peak volume center $xx xx (xx ...)
  550. // Relative volume change, bass $xx xx (xx ...) // f
  551. // Peak volume bass $xx xx (xx ...)
  552. if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
  553. $this->errors[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
  554. } else {
  555. $incdecflag .= '00';
  556. $incdecflag .= $source_data_array['incdec']['right'] ? '1' : '0'; // a - Relative volume change, right
  557. $incdecflag .= $source_data_array['incdec']['left'] ? '1' : '0'; // b - Relative volume change, left
  558. $incdecflag .= $source_data_array['incdec']['rightrear'] ? '1' : '0'; // c - Relative volume change, right back
  559. $incdecflag .= $source_data_array['incdec']['leftrear'] ? '1' : '0'; // d - Relative volume change, left back
  560. $incdecflag .= $source_data_array['incdec']['center'] ? '1' : '0'; // e - Relative volume change, center
  561. $incdecflag .= $source_data_array['incdec']['bass'] ? '1' : '0'; // f - Relative volume change, bass
  562. $framedata .= chr(bindec($incdecflag));
  563. $framedata .= chr($source_data_array['bitsvolume']);
  564. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
  565. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
  566. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
  567. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
  568. if ($source_data_array['volumechange']['rightrear'] || $source_data_array['volumechange']['leftrear'] ||
  569. $source_data_array['peakvolume']['rightrear'] || $source_data_array['peakvolume']['leftrear'] ||
  570. $source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
  571. $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  572. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
  573. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
  574. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
  575. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
  576. }
  577. if ($source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
  578. $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  579. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['center'], ceil($source_data_array['bitsvolume']/8), false);
  580. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['center'], ceil($source_data_array['bitsvolume']/8), false);
  581. }
  582. if ($source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  583. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['bass'], ceil($source_data_array['bitsvolume']/8), false);
  584. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['bass'], ceil($source_data_array['bitsvolume']/8), false);
  585. }
  586. }
  587. break;
  588. case 'EQU2':
  589. // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only)
  590. // Interpolation method $xx
  591. // $00 Band
  592. // $01 Linear
  593. // Identification <text string> $00
  594. // The following is then repeated for every adjustment point
  595. // Frequency $xx xx
  596. // Volume adjustment $xx xx
  597. if (($source_data_array['interpolationmethod'] < 0) || ($source_data_array['interpolationmethod'] > 1)) {
  598. $this->errors[] = 'Invalid Interpolation Method byte in '.$frame_name.' ('.$source_data_array['interpolationmethod'].') (valid = 0 or 1)';
  599. } else {
  600. $framedata .= chr($source_data_array['interpolationmethod']);
  601. $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
  602. foreach ($source_data_array['data'] as $key => $val) {
  603. $framedata .= getid3_lib::BigEndian2String(intval(round($key * 2)), 2, false);
  604. $framedata .= getid3_lib::BigEndian2String($val, 2, false, true); // signed 16-bit
  605. }
  606. }
  607. break;
  608. case 'EQUA':
  609. // 4.12 EQUA Equalisation (ID3v2.3 only)
  610. // Adjustment bits $xx
  611. // This is followed by 2 bytes + ('adjustment bits' rounded up to the
  612. // nearest byte) for every equalisation band in the following format,
  613. // giving a frequency range of 0 - 32767Hz:
  614. // Increment/decrement %x (MSB of the Frequency)
  615. // Frequency (lower 15 bits)
  616. // Adjustment $xx (xx ...)
  617. if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
  618. $this->errors[] = 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
  619. } else {
  620. $framedata .= chr($source_data_array['adjustmentbits']);
  621. foreach ($source_data_array as $key => $val) {
  622. if ($key != 'bitsvolume') {
  623. if (($key > 32767) || ($key < 0)) {
  624. $this->errors[] = 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)';
  625. } else {
  626. if ($val >= 0) {
  627. // put MSB of frequency to 1 if increment, 0 if decrement
  628. $key |= 0x8000;
  629. }
  630. $framedata .= getid3_lib::BigEndian2String($key, 2, false);
  631. $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['adjustmentbits'] / 8), false);
  632. }
  633. }
  634. }
  635. }
  636. break;
  637. case 'RVRB':
  638. // 4.13 RVRB Reverb
  639. // Reverb left (ms) $xx xx
  640. // Reverb right (ms) $xx xx
  641. // Reverb bounces, left $xx
  642. // Reverb bounces, right $xx
  643. // Reverb feedback, left to left $xx
  644. // Reverb feedback, left to right $xx
  645. // Reverb feedback, right to right $xx
  646. // Reverb feedback, right to left $xx
  647. // Premix left to right $xx
  648. // Premix right to left $xx
  649. if (!$this->IsWithinBitRange($source_data_array['left'], 16, false)) {
  650. $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['left'].') (range = 0 to 65535)';
  651. } elseif (!$this->IsWithinBitRange($source_data_array['right'], 16, false)) {
  652. $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['right'].') (range = 0 to 65535)';
  653. } elseif (!$this->IsWithinBitRange($source_data_array['bouncesL'], 8, false)) {
  654. $this->errors[] = 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$source_data_array['bouncesL'].') (range = 0 to 255)';
  655. } elseif (!$this->IsWithinBitRange($source_data_array['bouncesR'], 8, false)) {
  656. $this->errors[] = 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$source_data_array['bouncesR'].') (range = 0 to 255)';
  657. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLL'], 8, false)) {
  658. $this->errors[] = 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$source_data_array['feedbackLL'].') (range = 0 to 255)';
  659. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLR'], 8, false)) {
  660. $this->errors[] = 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$source_data_array['feedbackLR'].') (range = 0 to 255)';
  661. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRR'], 8, false)) {
  662. $this->errors[] = 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$source_data_array['feedbackRR'].') (range = 0 to 255)';
  663. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRL'], 8, false)) {
  664. $this->errors[] = 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$source_data_array['feedbackRL'].') (range = 0 to 255)';
  665. } elseif (!$this->IsWithinBitRange($source_data_array['premixLR'], 8, false)) {
  666. $this->errors[] = 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$source_data_array['premixLR'].') (range = 0 to 255)';
  667. } elseif (!$this->IsWithinBitRange($source_data_array['premixRL'], 8, false)) {
  668. $this->errors[] = 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$source_data_array['premixRL'].') (range = 0 to 255)';
  669. } else {
  670. $framedata .= getid3_lib::BigEndian2String($source_data_array['left'], 2, false);
  671. $framedata .= getid3_lib::BigEndian2String($source_data_array['right'], 2, false);
  672. $framedata .= chr($source_data_array['bouncesL']);
  673. $framedata .= chr($source_data_array['bouncesR']);
  674. $framedata .= chr($source_data_array['feedbackLL']);
  675. $framedata .= chr($source_data_array['feedbackLR']);
  676. $framedata .= chr($source_data_array['feedbackRR']);
  677. $framedata .= chr($source_data_array['feedbackRL']);
  678. $framedata .= chr($source_data_array['premixLR']);
  679. $framedata .= chr($source_data_array['premixRL']);
  680. }
  681. break;
  682. case 'APIC':
  683. // 4.14 APIC Attached picture
  684. // Text encoding $xx
  685. // MIME type <text string> $00
  686. // Picture type $xx
  687. // Description <text string according to encoding> $00 (00)
  688. // Picture data <binary data>
  689. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  690. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  691. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  692. } elseif (!$this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) {
  693. $this->errors[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion;
  694. } elseif (($this->majorversion >= 3) && (!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) {
  695. $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion;
  696. } elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false, false))) {
  697. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  698. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  699. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  700. } else {
  701. $framedata .= chr($source_data_array['encodingid']);
  702. $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
  703. $framedata .= chr($source_data_array['picturetypeid']);
  704. $framedata .= (!empty($source_data_array['description']) ? $source_data_array['description'] : '').getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  705. $framedata .= $source_data_array['data'];
  706. }
  707. break;
  708. case 'GEOB':
  709. // 4.15 GEOB General encapsulated object
  710. // Text encoding $xx
  711. // MIME type <text string> $00
  712. // Filename <text string according to encoding> $00 (00)
  713. // Content description <text string according to encoding> $00 (00)
  714. // Encapsulated object <binary data>
  715. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  716. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  717. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  718. } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
  719. $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
  720. } elseif (!$source_data_array['description']) {
  721. $this->errors[] = 'Missing Description in '.$frame_name;
  722. } else {
  723. $framedata .= chr($source_data_array['encodingid']);
  724. $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
  725. $framedata .= $source_data_array['filename'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  726. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  727. $framedata .= $source_data_array['data'];
  728. }
  729. break;
  730. case 'PCNT':
  731. // 4.16 PCNT Play counter
  732. // When the counter reaches all one's, one byte is inserted in
  733. // front of the counter thus making the counter eight bits bigger
  734. // Counter $xx xx xx xx (xx ...)
  735. $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
  736. break;
  737. case 'POPM':
  738. // 4.17 POPM Popularimeter
  739. // When the counter reaches all one's, one byte is inserted in
  740. // front of the counter thus making the counter eight bits bigger
  741. // Email to user <text string> $00
  742. // Rating $xx
  743. // Counter $xx xx xx xx (xx ...)
  744. if (!$this->IsWithinBitRange($source_data_array['rating'], 8, false)) {
  745. $this->errors[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)';
  746. } elseif (!IsValidEmail($source_data_array['email'])) {
  747. $this->errors[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')';
  748. } else {
  749. $framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00";
  750. $framedata .= chr($source_data_array['rating']);
  751. $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
  752. }
  753. break;
  754. case 'RBUF':
  755. // 4.18 RBUF Recommended buffer size
  756. // Buffer size $xx xx xx
  757. // Embedded info flag %0000000x
  758. // Offset to next tag $xx xx xx xx
  759. if (!$this->IsWithinBitRange($source_data_array['buffersize'], 24, false)) {
  760. $this->errors[] = 'Invalid Buffer Size in '.$frame_name;
  761. } elseif (!$this->IsWithinBitRange($source_data_array['nexttagoffset'], 32, false)) {
  762. $this->errors[] = 'Invalid Offset To Next Tag in '.$frame_name;
  763. } else {
  764. $framedata .= getid3_lib::BigEndian2String($source_data_array['buffersize'], 3, false);
  765. $flag .= '0000000';
  766. $flag .= $source_data_array['flags']['embededinfo'] ? '1' : '0';
  767. $framedata .= chr(bindec($flag));
  768. $framedata .= getid3_lib::BigEndian2String($source_data_array['nexttagoffset'], 4, false);
  769. }
  770. break;
  771. case 'AENC':
  772. // 4.19 AENC Audio encryption
  773. // Owner identifier <text string> $00
  774. // Preview start $xx xx
  775. // Preview length $xx xx
  776. // Encryption info <binary data>
  777. if (!$this->IsWithinBitRange($source_data_array['previewstart'], 16, false)) {
  778. $this->errors[] = 'Invalid Preview Start in '.$frame_name.' ('.$source_data_array['previewstart'].')';
  779. } elseif (!$this->IsWithinBitRange($source_data_array['previewlength'], 16, false)) {
  780. $this->errors[] = 'Invalid Preview Length in '.$frame_name.' ('.$source_data_array['previewlength'].')';
  781. } else {
  782. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  783. $framedata .= getid3_lib::BigEndian2String($source_data_array['previewstart'], 2, false);
  784. $framedata .= getid3_lib::BigEndian2String($source_data_array['previewlength'], 2, false);
  785. $framedata .= $source_data_array['encryptioninfo'];
  786. }
  787. break;
  788. case 'LINK':
  789. // 4.20 LINK Linked information
  790. // Frame identifier $xx xx xx xx
  791. // URL <text string> $00
  792. // ID and additional data <text string(s)>
  793. if (!getid3_id3v2::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion)) {
  794. $this->errors[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')';
  795. } elseif (!$this->IsValidURL($source_data_array['data'], true, false)) {
  796. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  797. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  798. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  799. } elseif ((($source_data_array['frameid'] == 'AENC') || ($source_data_array['frameid'] == 'APIC') || ($source_data_array['frameid'] == 'GEOB') || ($source_data_array['frameid'] == 'TXXX')) && ($source_data_array['additionaldata'] == '')) {
  800. $this->errors[] = 'Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  801. } elseif (($source_data_array['frameid'] == 'USER') && (getid3_id3v2::LanguageLookup($source_data_array['additionaldata'], true) == '')) {
  802. $this->errors[] = 'Language must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  803. } elseif (($source_data_array['frameid'] == 'PRIV') && ($source_data_array['additionaldata'] == '')) {
  804. $this->errors[] = 'Owner Identifier must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  805. } elseif ((($source_data_array['frameid'] == 'COMM') || ($source_data_array['frameid'] == 'SYLT') || ($source_data_array['frameid'] == 'USLT')) && ((getid3_id3v2::LanguageLookup(substr($source_data_array['additionaldata'], 0, 3), true) == '') || (substr($source_data_array['additionaldata'], 3) == ''))) {
  806. $this->errors[] = 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  807. } else {
  808. $framedata .= $source_data_array['frameid'];
  809. $framedata .= str_replace("\x00", '', $source_data_array['data'])."\x00";
  810. switch ($source_data_array['frameid']) {
  811. case 'COMM':
  812. case 'SYLT':
  813. case 'USLT':
  814. case 'PRIV':
  815. case 'USER':
  816. case 'AENC':
  817. case 'APIC':
  818. case 'GEOB':
  819. case 'TXXX':
  820. $framedata .= $source_data_array['additionaldata'];
  821. break;
  822. case 'ASPI':
  823. case 'ETCO':
  824. case 'EQU2':
  825. case 'MCID':
  826. case 'MLLT':
  827. case 'OWNE':
  828. case 'RVA2':
  829. case 'RVRB':
  830. case 'SYTC':
  831. case 'IPLS':
  832. case 'RVAD':
  833. case 'EQUA':
  834. // no additional data required
  835. break;
  836. case 'RBUF':
  837. if ($this->majorversion == 3) {
  838. // no additional data required
  839. } else {
  840. $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
  841. }
  842. default:
  843. if ((substr($source_data_array['frameid'], 0, 1) == 'T') || (substr($source_data_array['frameid'], 0, 1) == 'W')) {
  844. // no additional data required
  845. } else {
  846. $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
  847. }
  848. break;
  849. }
  850. }
  851. break;
  852. case 'POSS':
  853. // 4.21 POSS Position synchronisation frame (ID3v2.3+ only)
  854. // Time stamp format $xx
  855. // Position $xx (xx ...)
  856. if (($source_data_array['timestampformat'] < 1) || ($source_data_array['timestampformat'] > 2)) {
  857. $this->errors[] = 'Invalid Time Stamp Format in '.$frame_name.' ('.$source_data_array['timestampformat'].') (valid = 1 or 2)';
  858. } elseif (!$this->IsWithinBitRange($source_data_array['position'], 32, false)) {
  859. $this->errors[] = 'Invalid Position in '.$frame_name.' ('.$source_data_array['position'].') (range = 0 to 4294967295)';
  860. } else {
  861. $framedata .= chr($source_data_array['timestampformat']);
  862. $framedata .= getid3_lib::BigEndian2String($source_data_array['position'], 4, false);
  863. }
  864. break;
  865. case 'USER':
  866. // 4.22 USER Terms of use (ID3v2.3+ only…

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