PageRenderTime 64ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/sys/plugins/id3/getid3/write.id3v2.php

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

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