ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GetId3\Write\Id3v1 Class Reference

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //. More...

+ Collaboration diagram for GetId3\Write\Id3v1:

Public Member Functions

 __construct ()
 
 WriteID3v1 ()
 
 FixID3v1Padding ()
 
 RemoveID3v1 ()
 
 setRealFileSize ()
 

Data Fields

 $filename
 
 $filesize
 
 $tag_data
 
 $warnings = array()
 
 $errors = array()
 

Detailed Description

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //.

module for writing ID3v1 tags

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g http://www.getid3.org GetId3

Definition at line 31 of file Id3v1.php.

Constructor & Destructor Documentation

◆ __construct()

GetId3\Write\Id3v1::__construct ( )
Returns
boolean

Definition at line 51 of file Id3v1.php.

52  {
53  return true;
54  }

Member Function Documentation

◆ FixID3v1Padding()

GetId3\Write\Id3v1::FixID3v1Padding ( )
Returns
boolean

Definition at line 107 of file Id3v1.php.

References GetId3\Write\Id3v1\WriteID3v1().

108  {
109  // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces
110  // This function rewrites the ID3v1 tag with correct padding
111 
112  // Initialize GetId3 engine
113  $getID3 = new GetId3Core();
114  $getID3->option_tag_id3v2 = false;
115  $getID3->option_tag_apetag = false;
116  $getID3->option_tags_html = false;
117  $getID3->option_extra_info = false;
118  $getID3->option_tag_id3v1 = true;
119  $ThisFileInfo = $getID3->analyze($this->filename);
120  if (isset($ThisFileInfo['tags']['id3v1'])) {
121  foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) {
122  $id3v1data[$key] = implode(',', $value);
123  }
124  $this->tag_data = $id3v1data;
125 
126  return $this->WriteID3v1();
127  }
128 
129  return false;
130  }
+ Here is the call graph for this function:

◆ RemoveID3v1()

GetId3\Write\Id3v1::RemoveID3v1 ( )

Definition at line 132 of file Id3v1.php.

References GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Lib\Helper\intValueSupported(), and GetId3\Write\Id3v1\setRealFileSize().

133  {
134  // File MUST be writeable - CHMOD(646) at least
135  if (!empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) {
136  $this->setRealFileSize();
137  if (($this->filesize <= 0) || !Helper::intValueSupported($this->filesize)) {
138  $this->errors[] = 'Unable to RemoveID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
139 
140  return false;
141  }
142  if ($fp_source = fopen($this->filename, 'r+b')) {
143 
144  fseek($fp_source, -128, SEEK_END);
145  if (fread($fp_source, 3) == 'TAG') {
146  ftruncate($fp_source, $this->filesize - 128);
147  } else {
148  // no ID3v1 tag to begin with - do nothing
149  }
150  fclose($fp_source);
151 
152  return true;
153 
154  } else {
155  $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")';
156  }
157  } else {
158  $this->errors[] = $this->filename.' is not writeable';
159  }
160 
161  return false;
162  }
fseek($bytes, $whence=SEEK_SET)
static intValueSupported($num)
null $hasINT64
Definition: Helper.php:130
+ Here is the call graph for this function:

◆ setRealFileSize()

GetId3\Write\Id3v1::setRealFileSize ( )
Returns
boolean

Definition at line 168 of file Id3v1.php.

Referenced by GetId3\Write\Id3v1\RemoveID3v1(), and GetId3\Write\Id3v1\WriteID3v1().

169  {
170  if (PHP_INT_MAX > 2147483647) {
171  $this->filesize = filesize($this->filename);
172 
173  return true;
174  }
175  // 32-bit PHP will not return correct values for filesize() if file is >=2GB
176  // but GetId3->analyze() has workarounds to get actual filesize
177  $getID3 = new GetId3Core();
178  $getID3->option_tag_id3v1 = false;
179  $getID3->option_tag_id3v2 = false;
180  $getID3->option_tag_apetag = false;
181  $getID3->option_tags_html = false;
182  $getID3->option_extra_info = false;
183  $ThisFileInfo = $getID3->analyze($this->filename);
184  $this->filesize = $ThisFileInfo['filesize'];
185 
186  return true;
187  }
+ Here is the caller graph for this function:

◆ WriteID3v1()

GetId3\Write\Id3v1::WriteID3v1 ( )
Returns
boolean

Definition at line 60 of file Id3v1.php.

References GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Lib\Helper\intValueSupported(), and GetId3\Write\Id3v1\setRealFileSize().

Referenced by GetId3\Write\Id3v1\FixID3v1Padding().

61  {
62  // File MUST be writeable - CHMOD(646) at least
63  if (!empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) {
64  $this->setRealFileSize();
65  if (($this->filesize <= 0) || !Helper::intValueSupported($this->filesize)) {
66  $this->errors[] = 'Unable to WriteID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
67 
68  return false;
69  }
70  if ($fp_source = fopen($this->filename, 'r+b')) {
71  fseek($fp_source, -128, SEEK_END);
72  if (fread($fp_source, 3) == 'TAG') {
73  fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag
74  } else {
75  fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag
76  }
77  $this->tag_data['track'] = (isset($this->tag_data['track']) ? $this->tag_data['track'] : (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : (isset($this->tag_data['tracknumber']) ? $this->tag_data['tracknumber'] : '')));
78 
79  $new_id3v1_tag_data = Tag\Id3v1::GenerateID3v1Tag(
80  (isset($this->tag_data['title'] ) ? $this->tag_data['title'] : ''),
81  (isset($this->tag_data['artist'] ) ? $this->tag_data['artist'] : ''),
82  (isset($this->tag_data['album'] ) ? $this->tag_data['album'] : ''),
83  (isset($this->tag_data['year'] ) ? $this->tag_data['year'] : ''),
84  (isset($this->tag_data['genreid']) ? $this->tag_data['genreid'] : ''),
85  (isset($this->tag_data['comment']) ? $this->tag_data['comment'] : ''),
86  (isset($this->tag_data['track'] ) ? $this->tag_data['track'] : ''));
87  fwrite($fp_source, $new_id3v1_tag_data, 128);
88  fclose($fp_source);
89 
90  return true;
91 
92  } else {
93  $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")';
94 
95  return false;
96  }
97  }
98  $this->errors[] = 'File is not writeable: '.$this->filename;
99 
100  return false;
101  }
fseek($bytes, $whence=SEEK_SET)
static intValueSupported($num)
null $hasINT64
Definition: Helper.php:130
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $errors

GetId3\Write\Id3v1::$errors = array()

Definition at line 45 of file Id3v1.php.

◆ $filename

GetId3\Write\Id3v1::$filename

Definition at line 33 of file Id3v1.php.

◆ $filesize

GetId3\Write\Id3v1::$filesize

Definition at line 34 of file Id3v1.php.

◆ $tag_data

GetId3\Write\Id3v1::$tag_data

Definition at line 35 of file Id3v1.php.

◆ $warnings

GetId3\Write\Id3v1::$warnings = array()

Definition at line 40 of file Id3v1.php.


The documentation for this class was generated from the following file: