ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_write_id3v1 Class Reference
+ Collaboration diagram for getid3_write_id3v1:

Public Member Functions

 getid3_write_id3v1 ()
 
 WriteID3v1 ()
 
 FixID3v1Padding ()
 
 RemoveID3v1 ()
 
 getid3_write_id3v1 ()
 
 WriteID3v1 ()
 
 FixID3v1Padding ()
 
 RemoveID3v1 ()
 
 setRealFileSize ()
 

Data Fields

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

Detailed Description

Definition at line 18 of file write.id3v1.php.

Member Function Documentation

◆ FixID3v1Padding() [1/2]

getid3_write_id3v1::FixID3v1Padding ( )

Definition at line 62 of file write.id3v1.php.

62 {
63 // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces
64 // This function rewrites the ID3v1 tag with correct padding
65
66 // Initialize getID3 engine
67 $getID3 = new getID3;
68 $ThisFileInfo = $getID3->analyze($this->filename);
69 if (isset($ThisFileInfo['tags']['id3v1'])) {
70 foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) {
71 $id3v1data[$key] = implode(',', $value);
72 }
73 $this->tag_data = $id3v1data;
74 return $this->WriteID3v1();
75 }
76 return false;
77 }
analyze($filename)
Definition: getid3.php:168

References getID3\analyze(), and WriteID3v1().

+ Here is the call graph for this function:

◆ FixID3v1Padding() [2/2]

getid3_write_id3v1::FixID3v1Padding ( )

Definition at line 69 of file write.id3v1.php.

69 {
70 // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces
71 // This function rewrites the ID3v1 tag with correct padding
72
73 // Initialize getID3 engine
74 $getID3 = new getID3;
75 $getID3->option_tag_id3v2 = false;
76 $getID3->option_tag_apetag = false;
77 $getID3->option_tags_html = false;
78 $getID3->option_extra_info = false;
79 $getID3->option_tag_id3v1 = true;
80 $ThisFileInfo = $getID3->analyze($this->filename);
81 if (isset($ThisFileInfo['tags']['id3v1'])) {
82 foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) {
83 $id3v1data[$key] = implode(',', $value);
84 }
85 $this->tag_data = $id3v1data;
86 return $this->WriteID3v1();
87 }
88 return false;
89 }

References getID3\analyze(), and WriteID3v1().

+ Here is the call graph for this function:

◆ getid3_write_id3v1() [1/2]

getid3_write_id3v1::getid3_write_id3v1 ( )

Definition at line 25 of file write.id3v1.php.

25 {
26 return true;
27 }

◆ getid3_write_id3v1() [2/2]

getid3_write_id3v1::getid3_write_id3v1 ( )

Definition at line 27 of file write.id3v1.php.

27 {
28 return true;
29 }

◆ RemoveID3v1() [1/2]

getid3_write_id3v1::RemoveID3v1 ( )

Definition at line 79 of file write.id3v1.php.

79 {
80 // File MUST be writeable - CHMOD(646) at least
81 if (is_writeable($this->filename)) {
82 if ($fp_source = @fopen($this->filename, 'r+b')) {
83
84 fseek($fp_source, -128, SEEK_END);
85 if (fread($fp_source, 3) == 'TAG') {
86 ftruncate($fp_source, filesize($this->filename) - 128);
87 } else {
88 // no ID3v1 tag to begin with - do nothing
89 }
90 fclose($fp_source);
91 return true;
92
93 } else {
94 $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
95 }
96 } else {
97 $this->errors[] = $this->filename.' is not writeable';
98 }
99 return false;
100 }

◆ RemoveID3v1() [2/2]

getid3_write_id3v1::RemoveID3v1 ( )

Definition at line 91 of file write.id3v1.php.

91 {
92 // File MUST be writeable - CHMOD(646) at least
93 if (!empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) {
94 $this->setRealFileSize();
95 if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) {
96 $this->errors[] = 'Unable to RemoveID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
97 return false;
98 }
99 if ($fp_source = fopen($this->filename, 'r+b')) {
100
101 fseek($fp_source, -128, SEEK_END);
102 if (fread($fp_source, 3) == 'TAG') {
103 ftruncate($fp_source, $this->filesize - 128);
104 } else {
105 // no ID3v1 tag to begin with - do nothing
106 }
107 fclose($fp_source);
108 return true;
109
110 } else {
111 $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")';
112 }
113 } else {
114 $this->errors[] = $this->filename.' is not writeable';
115 }
116 return false;
117 }
static intValueSupported($num)
Definition: getid3.lib.php:80

References getid3_lib\intValueSupported(), and setRealFileSize().

+ Here is the call graph for this function:

◆ setRealFileSize()

getid3_write_id3v1::setRealFileSize ( )

Definition at line 119 of file write.id3v1.php.

119 {
120 if (PHP_INT_MAX > 2147483647) {
121 $this->filesize = filesize($this->filename);
122 return true;
123 }
124 // 32-bit PHP will not return correct values for filesize() if file is >=2GB
125 // but getID3->analyze() has workarounds to get actual filesize
126 $getID3 = new getID3;
127 $getID3->option_tag_id3v1 = false;
128 $getID3->option_tag_id3v2 = false;
129 $getID3->option_tag_apetag = false;
130 $getID3->option_tags_html = false;
131 $getID3->option_extra_info = false;
132 $ThisFileInfo = $getID3->analyze($this->filename);
133 $this->filesize = $ThisFileInfo['filesize'];
134 return true;
135 }

References getID3\analyze().

Referenced by RemoveID3v1(), and WriteID3v1().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WriteID3v1() [1/2]

getid3_write_id3v1::WriteID3v1 ( )

Definition at line 29 of file write.id3v1.php.

29 {
30 // File MUST be writeable - CHMOD(646) at least
31 if (is_writeable($this->filename)) {
32 if ($fp_source = @fopen($this->filename, 'r+b')) {
33
34 fseek($fp_source, -128, SEEK_END);
35 if (fread($fp_source, 3) == 'TAG') {
36 fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag
37 } else {
38 fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag
39 }
40
41 $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag(
42 @$this->tag_data['title'],
43 @$this->tag_data['artist'],
44 @$this->tag_data['album'],
45 @$this->tag_data['year'],
46 @$this->tag_data['genreid'],
47 @$this->tag_data['comment'],
48 @$this->tag_data['track']);
49 fwrite($fp_source, $new_id3v1_tag_data, 128);
50 fclose($fp_source);
51 return true;
52
53 } else {
54 $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
55 return false;
56 }
57 }
58 $this->errors[] = 'File is not writeable: '.$this->filename;
59 return false;
60 }
GenerateID3v1Tag($title, $artist, $album, $year, $genreid, $comment, $track='')

References getid3_id3v1\GenerateID3v1Tag().

Referenced by FixID3v1Padding().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WriteID3v1() [2/2]

getid3_write_id3v1::WriteID3v1 ( )

Definition at line 31 of file write.id3v1.php.

31 {
32 // File MUST be writeable - CHMOD(646) at least
33 if (!empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) {
34 $this->setRealFileSize();
35 if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) {
36 $this->errors[] = 'Unable to WriteID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
37 return false;
38 }
39 if ($fp_source = fopen($this->filename, 'r+b')) {
40 fseek($fp_source, -128, SEEK_END);
41 if (fread($fp_source, 3) == 'TAG') {
42 fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag
43 } else {
44 fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag
45 }
46 $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'] : '')));
47
48 $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag(
49 (isset($this->tag_data['title'] ) ? $this->tag_data['title'] : ''),
50 (isset($this->tag_data['artist'] ) ? $this->tag_data['artist'] : ''),
51 (isset($this->tag_data['album'] ) ? $this->tag_data['album'] : ''),
52 (isset($this->tag_data['year'] ) ? $this->tag_data['year'] : ''),
53 (isset($this->tag_data['genreid']) ? $this->tag_data['genreid'] : ''),
54 (isset($this->tag_data['comment']) ? $this->tag_data['comment'] : ''),
55 (isset($this->tag_data['track'] ) ? $this->tag_data['track'] : ''));
56 fwrite($fp_source, $new_id3v1_tag_data, 128);
57 fclose($fp_source);
58 return true;
59
60 } else {
61 $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")';
62 return false;
63 }
64 }
65 $this->errors[] = 'File is not writeable: '.$this->filename;
66 return false;
67 }

References getid3_id3v1\GenerateID3v1Tag(), getid3_lib\intValueSupported(), and setRealFileSize().

+ Here is the call graph for this function:

Field Documentation

◆ $errors

getid3_write_id3v1::$errors = array()

Definition at line 23 of file write.id3v1.php.

◆ $filename

getid3_write_id3v1::$filename

Definition at line 20 of file write.id3v1.php.

◆ $filesize

getid3_write_id3v1::$filesize

Definition at line 22 of file write.id3v1.php.

◆ $tag_data

getid3_write_id3v1::$tag_data

Definition at line 21 of file write.id3v1.php.

◆ $warnings

getid3_write_id3v1::$warnings = array()

Definition at line 22 of file write.id3v1.php.


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