• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/MediaObjects/getid3/getid3/write.id3v1.php

Go to the documentation of this file.
00001 <?php
00004 //  available at http://getid3.sourceforge.net                 //
00005 //            or http://www.getid3.org                         //
00007 // See readme.txt for more details                             //
00009 //                                                             //
00010 // write.id3v1.php                                             //
00011 // module for writing ID3v1 tags                               //
00012 // dependencies: module.tag.id3v1.php                          //
00013 //                                                            ///
00015 
00016 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
00017 
00018 class getid3_write_id3v1
00019 {
00020         var $filename;
00021         var $tag_data;
00022         var $warnings = array(); // any non-critical errors will be stored here
00023         var $errors   = array(); // any critical errors will be stored here
00024 
00025         function getid3_write_id3v1() {
00026                 return true;
00027         }
00028 
00029         function WriteID3v1() {
00030                 // File MUST be writeable - CHMOD(646) at least
00031                 if (is_writeable($this->filename)) {
00032                         if ($fp_source = @fopen($this->filename, 'r+b')) {
00033 
00034                                 fseek($fp_source, -128, SEEK_END);
00035                                 if (fread($fp_source, 3) == 'TAG') {
00036                                         fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag
00037                                 } else {
00038                                         fseek($fp_source, 0, SEEK_END);    // append new ID3v1 tag
00039                                 }
00040 
00041                                 $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag(
00042                                                                                                                 @$this->tag_data['title'],
00043                                                                                                                 @$this->tag_data['artist'],
00044                                                                                                                 @$this->tag_data['album'],
00045                                                                                                                 @$this->tag_data['year'],
00046                                                                                                                 @$this->tag_data['genreid'],
00047                                                                                                                 @$this->tag_data['comment'],
00048                                                                                                                 @$this->tag_data['track']);
00049                                 fwrite($fp_source, $new_id3v1_tag_data, 128);
00050                                 fclose($fp_source);
00051                                 return true;
00052 
00053                         } else {
00054                                 $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
00055                                 return false;
00056                         }
00057                 }
00058                 $this->errors[] = 'File is not writeable: '.$this->filename;
00059                 return false;
00060         }
00061 
00062         function FixID3v1Padding() {
00063                 // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces
00064                 // This function rewrites the ID3v1 tag with correct padding
00065 
00066                 // Initialize getID3 engine
00067                 $getID3 = new getID3;
00068                 $ThisFileInfo = $getID3->analyze($this->filename);
00069                 if (isset($ThisFileInfo['tags']['id3v1'])) {
00070                         foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) {
00071                                 $id3v1data[$key] = implode(',', $value);
00072                         }
00073                         $this->tag_data = $id3v1data;
00074                         return $this->WriteID3v1();
00075                 }
00076                 return false;
00077         }
00078 
00079         function RemoveID3v1() {
00080                 // File MUST be writeable - CHMOD(646) at least
00081                 if (is_writeable($this->filename)) {
00082                         if ($fp_source = @fopen($this->filename, 'r+b')) {
00083 
00084                                 fseek($fp_source, -128, SEEK_END);
00085                                 if (fread($fp_source, 3) == 'TAG') {
00086                                         ftruncate($fp_source, filesize($this->filename) - 128);
00087                                 } else {
00088                                         // no ID3v1 tag to begin with - do nothing
00089                                 }
00090                                 fclose($fp_source);
00091                                 return true;
00092 
00093                         } else {
00094                                 $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
00095                         }
00096                 } else {
00097                         $this->errors[] = $this->filename.' is not writeable';
00098                 }
00099                 return false;
00100         }
00101 
00102 }
00103 
00104 ?>

Generated on Fri Dec 13 2013 17:56:59 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1