write.lyrics3.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.lyrics3.php //
  11. // module for writing Lyrics3 tags //
  12. // dependencies: module.tag.lyrics3.php //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. class getid3_write_lyrics3
  16. {
  17. var $filename;
  18. var $tag_data;
  19. //var $lyrics3_version = 2; // 1 or 2
  20. var $warnings = array(); // any non-critical errors will be stored here
  21. var $errors = array(); // any critical errors will be stored here
  22. function getid3_write_lyrics3() {
  23. return true;
  24. }
  25. function WriteLyrics3() {
  26. $this->errors[] = 'WriteLyrics3() not yet functional - cannot write Lyrics3';
  27. return false;
  28. }
  29. function DeleteLyrics3() {
  30. // Initialize getID3 engine
  31. $getID3 = new getID3;
  32. $ThisFileInfo = $getID3->analyze($this->filename);
  33. if (isset($ThisFileInfo['lyrics3']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) {
  34. if ($fp = @fopen($this->filename, 'a+b')) {
  35. flock($fp, LOCK_EX);
  36. $oldignoreuserabort = ignore_user_abort(true);
  37. fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_end'], SEEK_SET);
  38. $DataAfterLyrics3 = '';
  39. if ($ThisFileInfo['filesize'] > $ThisFileInfo['lyrics3']['tag_offset_end']) {
  40. $DataAfterLyrics3 = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['lyrics3']['tag_offset_end']);
  41. }
  42. ftruncate($fp, $ThisFileInfo['lyrics3']['tag_offset_start']);
  43. if (!empty($DataAfterLyrics3)) {
  44. fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_start'], SEEK_SET);
  45. fwrite($fp, $DataAfterLyrics3, strlen($DataAfterLyrics3));
  46. }
  47. flock($fp, LOCK_UN);
  48. fclose($fp);
  49. ignore_user_abort($oldignoreuserabort);
  50. return true;
  51. } else {
  52. $this->errors[] = 'Cannot open "'.$this->filename.'" in "a+b" mode';
  53. return false;
  54. }
  55. }
  56. // no Lyrics3 present
  57. return true;
  58. }
  59. }
  60. ?>