write.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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.php //
  11. // module for writing tags (APEv2, ID3v1, ID3v2) //
  12. // dependencies: getid3.lib.php //
  13. // write.apetag.php (optional) //
  14. // write.id3v1.php (optional) //
  15. // write.id3v2.php (optional) //
  16. // write.vorbiscomment.php (optional) //
  17. // write.metaflac.php (optional) //
  18. // write.lyrics3.php (optional) //
  19. // ///
  20. /////////////////////////////////////////////////////////////////
  21. if (!defined('GETID3_INCLUDEPATH')) {
  22. die('getid3.php MUST be included before calling getid3_writetags');
  23. }
  24. if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
  25. die('write.php depends on getid3.lib.php, which is missing.');
  26. }
  27. // NOTES:
  28. //
  29. // You should pass data here with standard field names as follows:
  30. // * TITLE
  31. // * ARTIST
  32. // * ALBUM
  33. // * TRACKNUMBER
  34. // * COMMENT
  35. // * GENRE
  36. // * YEAR
  37. // * ATTACHED_PICTURE (ID3v2 only)
  38. //
  39. // http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html
  40. // The APEv2 Tag Items Keys definition says "TRACK" is correct but foobar2000 uses "TRACKNUMBER" instead
  41. // Pass data here as "TRACKNUMBER" for compatability with all formats
  42. class getid3_writetags
  43. {
  44. // public
  45. var $filename; // absolute filename of file to write tags to
  46. var $tagformats = array(); // array of tag formats to write ('id3v1', 'id3v2.2', 'id2v2.3', 'id3v2.4', 'ape', 'vorbiscomment', 'metaflac', 'real')
  47. var $tag_data = array(array()); // 2-dimensional array of tag data (ex: $data['ARTIST'][0] = 'Elvis')
  48. var $tag_encoding = 'ISO-8859-1'; // text encoding used for tag data ('ISO-8859-1', 'UTF-8', 'UTF-16', 'UTF-16LE', 'UTF-16BE', )
  49. var $overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data
  50. var $remove_other_tags = false; // if true will erase remove all existing tags and only write those passed in $tagformats; if false will ignore any tags not mentioned in $tagformats
  51. var $id3v2_tag_language = 'eng'; // ISO-639-2 3-character language code needed for some ID3v2 frames (http://www.id3.org/iso639-2.html)
  52. var $id3v2_paddedlength = 4096; // minimum length of ID3v2 tags (will be padded to this length if tag data is shorter)
  53. var $warnings = array(); // any non-critical errors will be stored here
  54. var $errors = array(); // any critical errors will be stored here
  55. // private
  56. var $ThisFileInfo; // analysis of file before writing
  57. function getid3_writetags() {
  58. return true;
  59. }
  60. function WriteTags() {
  61. if (empty($this->filename)) {
  62. $this->errors[] = 'filename is undefined in getid3_writetags';
  63. return false;
  64. } elseif (!file_exists($this->filename)) {
  65. $this->errors[] = 'filename set to non-existant file "'.$this->filename.'" in getid3_writetags';
  66. return false;
  67. }
  68. if (!is_array($this->tagformats)) {
  69. $this->errors[] = 'tagformats must be an array in getid3_writetags';
  70. return false;
  71. }
  72. $TagFormatsToRemove = array();
  73. if (filesize($this->filename) == 0) {
  74. // empty file special case - allow any tag format, don't check existing format
  75. // could be useful if you want to generate tag data for a non-existant file
  76. $this->ThisFileInfo = array('fileformat'=>'');
  77. $AllowedTagFormats = array('id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3');
  78. } else {
  79. $getID3 = new getID3;
  80. $getID3->encoding = $this->tag_encoding;
  81. $this->ThisFileInfo = $getID3->analyze($this->filename);
  82. // check for what file types are allowed on this fileformat
  83. switch (@$this->ThisFileInfo['fileformat']) {
  84. case 'mp3':
  85. case 'mp2':
  86. case 'mp1':
  87. case 'riff': // maybe not officially, but people do it anyway
  88. $AllowedTagFormats = array('id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3');
  89. break;
  90. case 'mpc':
  91. $AllowedTagFormats = array('ape');
  92. break;
  93. case 'flac':
  94. $AllowedTagFormats = array('metaflac');
  95. break;
  96. case 'real':
  97. $AllowedTagFormats = array('real');
  98. break;
  99. case 'ogg':
  100. switch (@$this->ThisFileInfo['audio']['dataformat']) {
  101. case 'flac':
  102. //$AllowedTagFormats = array('metaflac');
  103. $this->errors[] = 'metaflac is not (yet) compatible with OggFLAC files';
  104. return false;
  105. break;
  106. case 'vorbis':
  107. $AllowedTagFormats = array('vorbiscomment');
  108. break;
  109. default:
  110. $this->errors[] = 'metaflac is not (yet) compatible with Ogg files other than OggVorbis';
  111. return false;
  112. break;
  113. }
  114. break;
  115. default:
  116. $AllowedTagFormats = array();
  117. break;
  118. }
  119. foreach ($this->tagformats as $requested_tag_format) {
  120. if (!in_array($requested_tag_format, $AllowedTagFormats)) {
  121. $errormessage = 'Tag format "'.$requested_tag_format.'" is not allowed on "'.@$this->ThisFileInfo['fileformat'];
  122. if (@$this->ThisFileInfo['fileformat'] != @$this->ThisFileInfo['audio']['dataformat']) {
  123. $errormessage .= '.'.@$this->ThisFileInfo['audio']['dataformat'];
  124. }
  125. $errormessage .= '" files';
  126. $this->errors[] = $errormessage;
  127. return false;
  128. }
  129. }
  130. // List of other tag formats, removed if requested
  131. if ($this->remove_other_tags) {
  132. foreach ($AllowedTagFormats as $AllowedTagFormat) {
  133. switch ($AllowedTagFormat) {
  134. case 'id3v2.2':
  135. case 'id3v2.3':
  136. case 'id3v2.4':
  137. if (!in_array('id3v2', $TagFormatsToRemove) && !in_array('id3v2.2', $this->tagformats) && !in_array('id3v2.3', $this->tagformats) && !in_array('id3v2.4', $this->tagformats)) {
  138. $TagFormatsToRemove[] = 'id3v2';
  139. }
  140. break;
  141. default:
  142. if (!in_array($AllowedTagFormat, $this->tagformats)) {
  143. $TagFormatsToRemove[] = $AllowedTagFormat;
  144. }
  145. break;
  146. }
  147. }
  148. }
  149. }
  150. $WritingFilesToInclude = array_merge($this->tagformats, $TagFormatsToRemove);
  151. // Check for required include files and include them
  152. foreach ($WritingFilesToInclude as $tagformat) {
  153. switch ($tagformat) {
  154. case 'ape':
  155. $GETID3_ERRORARRAY = &$this->errors;
  156. if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.apetag.php', __FILE__, false)) {
  157. return false;
  158. }
  159. break;
  160. case 'id3v1':
  161. case 'lyrics3':
  162. case 'vorbiscomment':
  163. case 'metaflac':
  164. case 'real':
  165. $GETID3_ERRORARRAY = &$this->errors;
  166. if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.'.$tagformat.'.php', __FILE__, false)) {
  167. return false;
  168. }
  169. break;
  170. case 'id3v2.2':
  171. case 'id3v2.3':
  172. case 'id3v2.4':
  173. case 'id3v2':
  174. $GETID3_ERRORARRAY = &$this->errors;
  175. if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v2.php', __FILE__, false)) {
  176. return false;
  177. }
  178. break;
  179. default:
  180. $this->errors[] = 'unknown tag format "'.$tagformat.'" in $tagformats in WriteTags()';
  181. return false;
  182. break;
  183. }
  184. }
  185. // Validation of supplied data
  186. if (!is_array($this->tag_data)) {
  187. $this->errors[] = '$tag_data is not an array in WriteTags()';
  188. return false;
  189. }
  190. // convert supplied data array keys to upper case, if they're not already
  191. foreach ($this->tag_data as $tag_key => $tag_array) {
  192. if (strtoupper($tag_key) !== $tag_key) {
  193. $this->tag_data[strtoupper($tag_key)] = $this->tag_data[$tag_key];
  194. unset($this->tag_data[$tag_key]);
  195. }
  196. }
  197. // convert source data array keys to upper case, if they're not already
  198. if (!empty($this->ThisFileInfo['tags'])) {
  199. foreach ($this->ThisFileInfo['tags'] as $tag_format => $tag_data_array) {
  200. foreach ($tag_data_array as $tag_key => $tag_array) {
  201. if (strtoupper($tag_key) !== $tag_key) {
  202. $this->ThisFileInfo['tags'][$tag_format][strtoupper($tag_key)] = $this->ThisFileInfo['tags'][$tag_format][$tag_key];
  203. unset($this->ThisFileInfo['tags'][$tag_format][$tag_key]);
  204. }
  205. }
  206. }
  207. }
  208. // Convert "TRACK" to "TRACKNUMBER" (if needed) for compatability with all formats
  209. if (isset($this->tag_data['TRACK']) && !isset($this->tag_data['TRACKNUMBER'])) {
  210. $this->tag_data['TRACKNUMBER'] = $this->tag_data['TRACK'];
  211. unset($this->tag_data['TRACK']);
  212. }
  213. // Remove all other tag formats, if requested
  214. if ($this->remove_other_tags) {
  215. $this->DeleteTags($TagFormatsToRemove);
  216. }
  217. // Write data for each tag format
  218. foreach ($this->tagformats as $tagformat) {
  219. $success = false; // overridden if tag writing is successful
  220. switch ($tagformat) {
  221. case 'ape':
  222. $ape_writer = new getid3_write_apetag;
  223. if (($ape_writer->tag_data = $this->FormatDataForAPE()) !== false) {
  224. $ape_writer->filename = $this->filename;
  225. if (($success = $ape_writer->WriteAPEtag()) === false) {
  226. $this->errors[] = 'WriteAPEtag() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $ape_writer->errors)).'</LI></UL></PRE>';
  227. }
  228. } else {
  229. $this->errors[] = 'FormatDataForAPE() failed';
  230. }
  231. break;
  232. case 'id3v1':
  233. $id3v1_writer = new getid3_write_id3v1;
  234. if (($id3v1_writer->tag_data = $this->FormatDataForID3v1()) !== false) {
  235. $id3v1_writer->filename = $this->filename;
  236. if (($success = $id3v1_writer->WriteID3v1()) === false) {
  237. $this->errors[] = 'WriteID3v1() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $id3v1_writer->errors)).'</LI></UL></PRE>';
  238. }
  239. } else {
  240. $this->errors[] = 'FormatDataForID3v1() failed';
  241. }
  242. break;
  243. case 'id3v2.2':
  244. case 'id3v2.3':
  245. case 'id3v2.4':
  246. $id3v2_writer = new getid3_write_id3v2;
  247. $id3v2_writer->majorversion = intval(substr($tagformat, -1));
  248. $id3v2_writer->paddedlength = $this->id3v2_paddedlength;
  249. if (($id3v2_writer->tag_data = $this->FormatDataForID3v2($id3v2_writer->majorversion)) !== false) {
  250. $id3v2_writer->filename = $this->filename;
  251. if (($success = $id3v2_writer->WriteID3v2()) === false) {
  252. $this->errors[] = 'WriteID3v2() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $id3v2_writer->errors)).'</LI></UL></PRE>';
  253. }
  254. } else {
  255. $this->errors[] = 'FormatDataForID3v2() failed';
  256. }
  257. break;
  258. case 'vorbiscomment':
  259. $vorbiscomment_writer = new getid3_write_vorbiscomment;
  260. if (($vorbiscomment_writer->tag_data = $this->FormatDataForVorbisComment()) !== false) {
  261. $vorbiscomment_writer->filename = $this->filename;
  262. if (($success = $vorbiscomment_writer->WriteVorbisComment()) === false) {
  263. $this->errors[] = 'WriteVorbisComment() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $vorbiscomment_writer->errors)).'</LI></UL></PRE>';
  264. }
  265. } else {
  266. $this->errors[] = 'FormatDataForVorbisComment() failed';
  267. }
  268. break;
  269. case 'metaflac':
  270. $metaflac_writer = new getid3_write_metaflac;
  271. if (($metaflac_writer->tag_data = $this->FormatDataForMetaFLAC()) !== false) {
  272. $metaflac_writer->filename = $this->filename;
  273. if (($success = $metaflac_writer->WriteMetaFLAC()) === false) {
  274. $this->errors[] = 'WriteMetaFLAC() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $metaflac_writer->errors)).'</LI></UL></PRE>';
  275. }
  276. } else {
  277. $this->errors[] = 'FormatDataForMetaFLAC() failed';
  278. }
  279. break;
  280. case 'real':
  281. $real_writer = new getid3_write_real;
  282. if (($real_writer->tag_data = $this->FormatDataForReal()) !== false) {
  283. $real_writer->filename = $this->filename;
  284. if (($success = $real_writer->WriteReal()) === false) {
  285. $this->errors[] = 'WriteReal() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $real_writer->errors)).'</LI></UL></PRE>';
  286. }
  287. } else {
  288. $this->errors[] = 'FormatDataForReal() failed';
  289. }
  290. break;
  291. default:
  292. $this->errors[] = 'Invalid tag format to write: "'.$tagformat.'"';
  293. return false;
  294. break;
  295. }
  296. if (!$success) {
  297. return false;
  298. }
  299. }
  300. return true;
  301. }
  302. function DeleteTags($TagFormatsToDelete) {
  303. foreach ($TagFormatsToDelete as $DeleteTagFormat) {
  304. $success = false; // overridden if tag deletion is successful
  305. switch ($DeleteTagFormat) {
  306. case 'id3v1':
  307. $id3v1_writer = new getid3_write_id3v1;
  308. $id3v1_writer->filename = $this->filename;
  309. if (($success = $id3v1_writer->RemoveID3v1()) === false) {
  310. $this->errors[] = 'RemoveID3v1() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $id3v1_writer->errors)).'</LI></UL></PRE>';
  311. }
  312. break;
  313. case 'id3v2':
  314. $id3v2_writer = new getid3_write_id3v2;
  315. $id3v2_writer->filename = $this->filename;
  316. if (($success = $id3v2_writer->RemoveID3v2()) === false) {
  317. $this->errors[] = 'RemoveID3v2() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $id3v2_writer->errors)).'</LI></UL></PRE>';
  318. }
  319. break;
  320. case 'ape':
  321. $ape_writer = new getid3_write_apetag;
  322. $ape_writer->filename = $this->filename;
  323. if (($success = $ape_writer->DeleteAPEtag()) === false) {
  324. $this->errors[] = 'DeleteAPEtag() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $ape_writer->errors)).'</LI></UL></PRE>';
  325. }
  326. break;
  327. case 'vorbiscomment':
  328. $vorbiscomment_writer = new getid3_write_vorbiscomment;
  329. $vorbiscomment_writer->filename = $this->filename;
  330. if (($success = $vorbiscomment_writer->DeleteVorbisComment()) === false) {
  331. $this->errors[] = 'DeleteVorbisComment() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $vorbiscomment_writer->errors)).'</LI></UL></PRE>';
  332. }
  333. break;
  334. case 'metaflac':
  335. $metaflac_writer = new getid3_write_metaflac;
  336. $metaflac_writer->filename = $this->filename;
  337. if (($success = $metaflac_writer->DeleteMetaFLAC()) === false) {
  338. $this->errors[] = 'DeleteMetaFLAC() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $metaflac_writer->errors)).'</LI></UL></PRE>';
  339. }
  340. break;
  341. case 'lyrics3':
  342. $lyrics3_writer = new getid3_write_lyrics3;
  343. $lyrics3_writer->filename = $this->filename;
  344. if (($success = $lyrics3_writer->DeleteLyrics3()) === false) {
  345. $this->errors[] = 'DeleteLyrics3() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $lyrics3_writer->errors)).'</LI></UL></PRE>';
  346. }
  347. break;
  348. case 'real':
  349. $real_writer = new getid3_write_real;
  350. $real_writer->filename = $this->filename;
  351. if (($success = $real_writer->RemoveReal()) === false) {
  352. $this->errors[] = 'RemoveReal() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $real_writer->errors)).'</LI></UL></PRE>';
  353. }
  354. break;
  355. default:
  356. $this->errors[] = 'Invalid tag format to delete: "'.$tagformat.'"';
  357. return false;
  358. break;
  359. }
  360. if (!$success) {
  361. return false;
  362. }
  363. }
  364. return true;
  365. }
  366. function MergeExistingTagData($TagFormat, &$tag_data) {
  367. // Merge supplied data with existing data, if requested
  368. if ($this->overwrite_tags) {
  369. // do nothing - ignore previous data
  370. } else {
  371. if (!isset($this->ThisFileInfo['tags'][$TagFormat])) {
  372. return false;
  373. }
  374. $tag_data = array_merge_recursive($tag_data, $this->ThisFileInfo['tags'][$TagFormat]);
  375. }
  376. return true;
  377. }
  378. function FormatDataForAPE() {
  379. $ape_tag_data = array();
  380. foreach ($this->tag_data as $tag_key => $valuearray) {
  381. switch ($tag_key) {
  382. case 'ATTACHED_PICTURE':
  383. // ATTACHED_PICTURE is ID3v2 only - ignore
  384. $this->warnings[] = '$data['.$tag_key.'] is assumed to be ID3v2 APIC data - NOT written to APE tag';
  385. break;
  386. default:
  387. foreach ($valuearray as $key => $value) {
  388. if (is_string($value) || is_numeric($value)) {
  389. $ape_tag_data[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value);
  390. } else {
  391. $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to APE tag';
  392. unset($ape_tag_data[$tag_key]);
  393. break;
  394. }
  395. }
  396. break;
  397. }
  398. }
  399. $this->MergeExistingTagData('ape', $ape_tag_data);
  400. return $ape_tag_data;
  401. }
  402. function FormatDataForID3v1() {
  403. $tag_data_id3v1['genreid'] = 255;
  404. if (!empty($this->tag_data['GENRE'])) {
  405. foreach ($this->tag_data['GENRE'] as $key => $value) {
  406. if (getid3_id3v1::LookupGenreID($value) !== false) {
  407. $tag_data_id3v1['genreid'] = getid3_id3v1::LookupGenreID($value);
  408. break;
  409. }
  410. }
  411. }
  412. $tag_data_id3v1['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['TITLE']));
  413. $tag_data_id3v1['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['ARTIST']));
  414. $tag_data_id3v1['album'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['ALBUM']));
  415. $tag_data_id3v1['year'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['YEAR']));
  416. $tag_data_id3v1['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['COMMENT']));
  417. $tag_data_id3v1['track'] = intval(getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['TRACKNUMBER'])));
  418. if ($tag_data_id3v1['track'] <= 0) {
  419. $tag_data_id3v1['track'] = '';
  420. }
  421. $this->MergeExistingTagData('id3v1', $tag_data_id3v1);
  422. return $tag_data_id3v1;
  423. }
  424. function FormatDataForID3v2($id3v2_majorversion) {
  425. $tag_data_id3v2 = array();
  426. $ID3v2_text_encoding_lookup[2] = array('ISO-8859-1'=>0, 'UTF-16'=>1);
  427. $ID3v2_text_encoding_lookup[3] = array('ISO-8859-1'=>0, 'UTF-16'=>1);
  428. $ID3v2_text_encoding_lookup[4] = array('ISO-8859-1'=>0, 'UTF-16'=>1, 'UTF-16BE'=>2, 'UTF-8'=>3);
  429. foreach ($this->tag_data as $tag_key => $valuearray) {
  430. $ID3v2_framename = getid3_write_id3v2::ID3v2ShortFrameNameLookup($id3v2_majorversion, $tag_key);
  431. switch ($ID3v2_framename) {
  432. case 'APIC':
  433. foreach ($valuearray as $key => $apic_data_array) {
  434. if (isset($apic_data_array['data']) &&
  435. isset($apic_data_array['picturetypeid']) &&
  436. isset($apic_data_array['description']) &&
  437. isset($apic_data_array['mime'])) {
  438. $tag_data_id3v2['APIC'][] = $apic_data_array;
  439. } else {
  440. $this->errors[] = 'ID3v2 APIC data is not properly structured';
  441. return false;
  442. }
  443. }
  444. break;
  445. case '':
  446. $this->errors[] = 'ID3v2: Skipping "'.$tag_key.'" because cannot match it to a known ID3v2 frame type';
  447. // some other data type, don't know how to handle it, ignore it
  448. break;
  449. default:
  450. // most other (text) frames can be copied over as-is
  451. foreach ($valuearray as $key => $value) {
  452. if (isset($ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding])) {
  453. // source encoding is valid in ID3v2 - use it with no conversion
  454. $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = $ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding];
  455. $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value;
  456. } else {
  457. // source encoding is NOT valid in ID3v2 - convert it to an ID3v2-valid encoding first
  458. if ($id3v2_majorversion < 4) {
  459. // convert data from other encoding to UTF-16
  460. $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 1;
  461. $tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16', $value);
  462. } else {
  463. // convert data from other encoding to UTF-8
  464. $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 3;
  465. $tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value);
  466. }
  467. }
  468. // These values are not needed for all frame types, but if they're not used no matter
  469. $tag_data_id3v2[$ID3v2_framename][$key]['description'] = '';
  470. $tag_data_id3v2[$ID3v2_framename][$key]['language'] = $this->id3v2_tag_language;
  471. }
  472. break;
  473. }
  474. }
  475. $this->MergeExistingTagData('id3v2', $tag_data_id3v2);
  476. return $tag_data_id3v2;
  477. }
  478. function FormatDataForVorbisComment() {
  479. $tag_data_vorbiscomment = $this->tag_data;
  480. // check for multi-line comment values - split out to multiple comments if neccesary
  481. // and convert data to UTF-8 strings
  482. foreach ($tag_data_vorbiscomment as $tag_key => $valuearray) {
  483. foreach ($valuearray as $key => $value) {
  484. str_replace("\r", "\n", $value);
  485. if (strstr($value, "\n")) {
  486. unset($tag_data_vorbiscomment[$tag_key][$key]);
  487. $multilineexploded = explode("\n", $value);
  488. foreach ($multilineexploded as $newcomment) {
  489. if (strlen(trim($newcomment)) > 0) {
  490. $tag_data_vorbiscomment[$tag_key][] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $newcomment);
  491. }
  492. }
  493. } elseif (is_string($value) || is_numeric($value)) {
  494. $tag_data_vorbiscomment[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value);
  495. } else {
  496. $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to VorbisComment tag';
  497. unset($tag_data_vorbiscomment[$tag_key]);
  498. break;
  499. }
  500. }
  501. }
  502. $this->MergeExistingTagData('vorbiscomment', $tag_data_vorbiscomment);
  503. return $tag_data_vorbiscomment;
  504. }
  505. function FormatDataForMetaFLAC() {
  506. // FLAC & OggFLAC use VorbisComments same as OggVorbis
  507. // but require metaflac to do the writing rather than vorbiscomment
  508. return $this->FormatDataForVorbisComment();
  509. }
  510. function FormatDataForReal() {
  511. $tag_data_real['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['TITLE']));
  512. $tag_data_real['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['ARTIST']));
  513. $tag_data_real['copyright'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['COPYRIGHT']));
  514. $tag_data_real['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['COMMENT']));
  515. $this->MergeExistingTagData('real', $tag_data_real);
  516. return $tag_data_real;
  517. }
  518. }
  519. ?>