PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/getid3/write.id3v2.php

https://bitbucket.org/holyfield/getid3
PHP | 2057 lines | 1581 code | 164 blank | 312 comment | 467 complexity | 0efe812a51911e5ca68e164e06d929bc MD5 | raw file
Possible License(s): GPL-2.0

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

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