write.lyrics3.php 2.6 KB

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