ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_write_real Class Reference

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

+ Collaboration diagram for getid3_write_real:

Public Member Functions

 getid3_write_real ()
 
 WriteReal ()
 
 GenerateRMFchunk (&$chunks)
 
 GeneratePROPchunk (&$chunks, &$new_CONT_tag_data)
 
 GenerateCONTchunk ()
 
 RemoveReal ()
 
 getid3_write_real ()
 
 WriteReal ()
 
 GenerateRMFchunk (&$chunks)
 
 GeneratePROPchunk (&$chunks, &$new_CONT_tag_data)
 
 GenerateCONTchunk ()
 
 RemoveReal ()
 

Data Fields

 $filename
 
 $tag_data = array()
 
 $warnings = array()
 
 $errors = array()
 
 $paddedlength = 512
 
 $fread_buffer_size = 32768
 

Detailed Description

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

Definition at line 16 of file write.real.php.

Member Function Documentation

◆ GenerateCONTchunk() [1/2]

getid3_write_real::GenerateCONTchunk ( )

Definition at line 193 of file write.real.php.

193 {
194 foreach ($this->tag_data as $key => $value) {
195 // limit each value to 0xFFFF bytes
196 $this->tag_data[$key] = substr($value, 0, 65535);
197 }
198
199 $CONTchunk = "\x00\x00"; // object version
200
201 $CONTchunk .= getid3_lib::BigEndian2String(strlen(@$this->tag_data['title']), 2);
202 $CONTchunk .= @$this->tag_data['title'];
203
204 $CONTchunk .= getid3_lib::BigEndian2String(strlen(@$this->tag_data['artist']), 2);
205 $CONTchunk .= @$this->tag_data['artist'];
206
207 $CONTchunk .= getid3_lib::BigEndian2String(strlen(@$this->tag_data['copyright']), 2);
208 $CONTchunk .= @$this->tag_data['copyright'];
209
210 $CONTchunk .= getid3_lib::BigEndian2String(strlen(@$this->tag_data['comment']), 2);
211 $CONTchunk .= @$this->tag_data['comment'];
212
213 if ($this->paddedlength > (strlen($CONTchunk) + 8)) {
214 $CONTchunk .= str_repeat("\x00", $this->paddedlength - strlen($CONTchunk) - 8);
215 }
216
217 $CONTchunk = 'CONT'.getid3_lib::BigEndian2String(strlen($CONTchunk) + 8, 4).$CONTchunk; // CONT chunk identifier + chunk length
218
219 return $CONTchunk;
220 }
BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:281

References getid3_lib\BigEndian2String().

Referenced by WriteReal().

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

◆ GenerateCONTchunk() [2/2]

getid3_write_real::GenerateCONTchunk ( )

Definition at line 185 of file write.real.php.

185 {
186 foreach ($this->tag_data as $key => $value) {
187 // limit each value to 0xFFFF bytes
188 $this->tag_data[$key] = substr($value, 0, 65535);
189 }
190
191 $CONTchunk = "\x00\x00"; // object version
192
193 $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : 0), 2);
194 $CONTchunk .= (!empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : '');
195
196 $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : 0), 2);
197 $CONTchunk .= (!empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : '');
198
199 $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : 0), 2);
200 $CONTchunk .= (!empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : '');
201
202 $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : 0), 2);
203 $CONTchunk .= (!empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : '');
204
205 if ($this->paddedlength > (strlen($CONTchunk) + 8)) {
206 $CONTchunk .= str_repeat("\x00", $this->paddedlength - strlen($CONTchunk) - 8);
207 }
208
209 $CONTchunk = 'CONT'.getid3_lib::BigEndian2String(strlen($CONTchunk) + 8, 4).$CONTchunk; // CONT chunk identifier + chunk length
210
211 return $CONTchunk;
212 }

References getid3_lib\BigEndian2String().

+ Here is the call graph for this function:

◆ GeneratePROPchunk() [1/2]

getid3_write_real::GeneratePROPchunk ( $chunks,
$new_CONT_tag_data 
)

Definition at line 156 of file write.real.php.

156 {
157 $old_CONT_length = 0;
158 $old_DATA_offset = 0;
159 $old_INDX_offset = 0;
160 foreach ($chunks as $key => $chunk) {
161 $chunkNameKeys[$chunk['name']] = $key;
162 if ($chunk['name'] == 'CONT') {
163 $old_CONT_length = $chunk['length'];
164 } elseif ($chunk['name'] == 'DATA') {
165 if (!$old_DATA_offset) {
166 $old_DATA_offset = $chunk['offset'];
167 }
168 } elseif ($chunk['name'] == 'INDX') {
169 if (!$old_INDX_offset) {
170 $old_INDX_offset = $chunk['offset'];
171 }
172 }
173 }
174 $CONTdelta = strlen($new_CONT_tag_data) - $old_CONT_length;
175
176 $PROPchunk = "\x00\x00"; // object version
177 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_bit_rate'], 4);
178 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_bit_rate'], 4);
179 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_packet_size'], 4);
180 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_packet_size'], 4);
181 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_packets'], 4);
182 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['duration'], 4);
183 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['preroll'], 4);
184 $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_INDX_offset + $CONTdelta), 4);
185 $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_DATA_offset + $CONTdelta), 4);
186 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_streams'], 2);
187 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['flags_raw'], 2);
188
189 $PROPchunk = 'PROP'.getid3_lib::BigEndian2String(strlen($PROPchunk) + 8, 4).$PROPchunk; // PROP chunk identifier + chunk length
190 return $PROPchunk;
191 }

References getid3_lib\BigEndian2String().

Referenced by WriteReal().

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

◆ GeneratePROPchunk() [2/2]

getid3_write_real::GeneratePROPchunk ( $chunks,
$new_CONT_tag_data 
)

Definition at line 148 of file write.real.php.

148 {
149 $old_CONT_length = 0;
150 $old_DATA_offset = 0;
151 $old_INDX_offset = 0;
152 foreach ($chunks as $key => $chunk) {
153 $chunkNameKeys[$chunk['name']] = $key;
154 if ($chunk['name'] == 'CONT') {
155 $old_CONT_length = $chunk['length'];
156 } elseif ($chunk['name'] == 'DATA') {
157 if (!$old_DATA_offset) {
158 $old_DATA_offset = $chunk['offset'];
159 }
160 } elseif ($chunk['name'] == 'INDX') {
161 if (!$old_INDX_offset) {
162 $old_INDX_offset = $chunk['offset'];
163 }
164 }
165 }
166 $CONTdelta = strlen($new_CONT_tag_data) - $old_CONT_length;
167
168 $PROPchunk = "\x00\x00"; // object version
169 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_bit_rate'], 4);
170 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_bit_rate'], 4);
171 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_packet_size'], 4);
172 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_packet_size'], 4);
173 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_packets'], 4);
174 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['duration'], 4);
175 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['preroll'], 4);
176 $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_INDX_offset + $CONTdelta), 4);
177 $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_DATA_offset + $CONTdelta), 4);
178 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_streams'], 2);
179 $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['flags_raw'], 2);
180
181 $PROPchunk = 'PROP'.getid3_lib::BigEndian2String(strlen($PROPchunk) + 8, 4).$PROPchunk; // PROP chunk identifier + chunk length
182 return $PROPchunk;
183 }

References getid3_lib\BigEndian2String().

+ Here is the call graph for this function:

◆ GenerateRMFchunk() [1/2]

getid3_write_real::GenerateRMFchunk ( $chunks)

Definition at line 138 of file write.real.php.

138 {
139 $oldCONTexists = false;
140 foreach ($chunks as $key => $chunk) {
141 $chunkNameKeys[$chunk['name']] = $key;
142 if ($chunk['name'] == 'CONT') {
143 $oldCONTexists = true;
144 }
145 }
146 $newHeadersCount = $chunks[$chunkNameKeys['.RMF']]['headers_count'] + ($oldCONTexists ? 0 : 1);
147
148 $RMFchunk = "\x00\x00"; // object version
149 $RMFchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['.RMF']]['file_version'], 4);
150 $RMFchunk .= getid3_lib::BigEndian2String($newHeadersCount, 4);
151
152 $RMFchunk = '.RMF'.getid3_lib::BigEndian2String(strlen($RMFchunk) + 8, 4).$RMFchunk; // .RMF chunk identifier + chunk length
153 return $RMFchunk;
154 }

References getid3_lib\BigEndian2String().

Referenced by WriteReal().

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

◆ GenerateRMFchunk() [2/2]

getid3_write_real::GenerateRMFchunk ( $chunks)

Definition at line 130 of file write.real.php.

130 {
131 $oldCONTexists = false;
132 foreach ($chunks as $key => $chunk) {
133 $chunkNameKeys[$chunk['name']] = $key;
134 if ($chunk['name'] == 'CONT') {
135 $oldCONTexists = true;
136 }
137 }
138 $newHeadersCount = $chunks[$chunkNameKeys['.RMF']]['headers_count'] + ($oldCONTexists ? 0 : 1);
139
140 $RMFchunk = "\x00\x00"; // object version
141 $RMFchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['.RMF']]['file_version'], 4);
142 $RMFchunk .= getid3_lib::BigEndian2String($newHeadersCount, 4);
143
144 $RMFchunk = '.RMF'.getid3_lib::BigEndian2String(strlen($RMFchunk) + 8, 4).$RMFchunk; // .RMF chunk identifier + chunk length
145 return $RMFchunk;
146 }

References getid3_lib\BigEndian2String().

+ Here is the call graph for this function:

◆ getid3_write_real() [1/2]

getid3_write_real::getid3_write_real ( )

Definition at line 24 of file write.real.php.

24 {
25 return true;
26 }

◆ getid3_write_real() [2/2]

getid3_write_real::getid3_write_real ( )

Definition at line 26 of file write.real.php.

26 {
27 return true;
28 }

◆ RemoveReal() [1/2]

getid3_write_real::RemoveReal ( )

Definition at line 222 of file write.real.php.

222 {
223 // File MUST be writeable - CHMOD(646) at least
224 if (is_writeable($this->filename)) {
225 if ($fp_source = @fopen($this->filename, 'r+b')) {
226
227 // Initialize getID3 engine
228 $getID3 = new getID3;
229 $OldThisFileInfo = $getID3->analyze($this->filename);
230 if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) {
231 $this->errors[] = 'Cannot remove Real tags from old-style file format';
232 fclose($fp_source);
233 return false;
234 }
235
236 if (empty($OldThisFileInfo['real']['chunks'])) {
237 $this->errors[] = 'Cannot remove Real tags because cannot find DATA chunk in file';
238 fclose($fp_source);
239 return false;
240 }
241 foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) {
242 $oldChunkInfo[$chunkarray['name']] = $chunkarray;
243 }
244
245 if (empty($oldChunkInfo['CONT'])) {
246 // no existing CONT chunk
247 fclose($fp_source);
248 return true;
249 }
250
251 $BeforeOffset = $oldChunkInfo['CONT']['offset'];
252 $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length'];
253 if ($tempfilename = tempnam('*', 'getID3')) {
254 ob_start();
255 if ($fp_temp = fopen($tempfilename, 'wb')) {
256
257 rewind($fp_source);
258 fwrite($fp_temp, fread($fp_source, $BeforeOffset));
259 fseek($fp_source, $AfterOffset, SEEK_SET);
260 while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) {
261 fwrite($fp_temp, $buffer, strlen($buffer));
262 }
263 fclose($fp_temp);
264
265 if (copy($tempfilename, $this->filename)) {
266 unlink($tempfilename);
267 fclose($fp_source);
268 return true;
269 }
270 unlink($tempfilename);
271 $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.') - '.strip_tags(ob_get_contents());
272
273 } else {
274
275 $this->errors[] = 'Could not open '.$tempfilename.' mode "wb" - '.strip_tags(ob_get_contents());
276
277 }
278 ob_end_clean();
279 }
280 fclose($fp_source);
281 return false;
282
283
284 } else {
285 $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
286 return false;
287 }
288 }
289 $this->errors[] = 'File is not writeable: '.$this->filename;
290 return false;
291 }
analyze($filename)
Definition: getid3.php:168
const GETID3_FREAD_BUFFER_SIZE
Definition: getid3.php:14

References getID3\analyze(), and GETID3_FREAD_BUFFER_SIZE.

+ Here is the call graph for this function:

◆ RemoveReal() [2/2]

getid3_write_real::RemoveReal ( )

Definition at line 214 of file write.real.php.

214 {
215 // File MUST be writeable - CHMOD(646) at least
216 if (is_writeable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) {
217
218 // Initialize getID3 engine
219 $getID3 = new getID3;
220 $OldThisFileInfo = $getID3->analyze($this->filename);
221 if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) {
222 $this->errors[] = 'Cannot remove Real tags from old-style file format';
223 fclose($fp_source);
224 return false;
225 }
226
227 if (empty($OldThisFileInfo['real']['chunks'])) {
228 $this->errors[] = 'Cannot remove Real tags because cannot find DATA chunk in file';
229 fclose($fp_source);
230 return false;
231 }
232 foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) {
233 $oldChunkInfo[$chunkarray['name']] = $chunkarray;
234 }
235
236 if (empty($oldChunkInfo['CONT'])) {
237 // no existing CONT chunk
238 fclose($fp_source);
239 return true;
240 }
241
242 $BeforeOffset = $oldChunkInfo['CONT']['offset'];
243 $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length'];
244 if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) {
245 if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) {
246
247 rewind($fp_source);
248 fwrite($fp_temp, fread($fp_source, $BeforeOffset));
249 fseek($fp_source, $AfterOffset);
250 while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
251 fwrite($fp_temp, $buffer, strlen($buffer));
252 }
253 fclose($fp_temp);
254
255 if (copy($tempfilename, $this->filename)) {
256 unlink($tempfilename);
257 fclose($fp_source);
258 return true;
259 }
260 unlink($tempfilename);
261 $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.')';
262
263 } else {
264 $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")';
265 }
266 }
267 fclose($fp_source);
268 return false;
269 }
270 $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")';
271 return false;
272 }

References getID3\analyze().

+ Here is the call graph for this function:

◆ WriteReal() [1/2]

getid3_write_real::WriteReal ( )

Definition at line 28 of file write.real.php.

28 {
29 // File MUST be writeable - CHMOD(646) at least
30 if (is_writeable($this->filename)) {
31 if ($fp_source = @fopen($this->filename, 'r+b')) {
32
33 // Initialize getID3 engine
34 $getID3 = new getID3;
35 $OldThisFileInfo = $getID3->analyze($this->filename);
36 if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) {
37 $this->errors[] = 'Cannot write Real tags on old-style file format';
38 fclose($fp_source);
39 return false;
40 }
41
42 if (empty($OldThisFileInfo['real']['chunks'])) {
43 $this->errors[] = 'Cannot write Real tags because cannot find DATA chunk in file';
44 fclose($fp_source);
45 return false;
46 }
47 foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) {
48 $oldChunkInfo[$chunkarray['name']] = $chunkarray;
49 }
50 if (!empty($oldChunkInfo['CONT']['length'])) {
51 $this->paddedlength = max($oldChunkInfo['CONT']['length'], $this->paddedlength);
52 }
53
54 $new_CONT_tag_data = $this->GenerateCONTchunk();
55 $new_PROP_tag_data = $this->GeneratePROPchunk($OldThisFileInfo['real']['chunks'], $new_CONT_tag_data);
56 $new__RMF_tag_data = $this->GenerateRMFchunk($OldThisFileInfo['real']['chunks']);
57
58 if (@$oldChunkInfo['.RMF']['length'] == strlen($new__RMF_tag_data)) {
59 fseek($fp_source, $oldChunkInfo['.RMF']['offset'], SEEK_SET);
60 fwrite($fp_source, $new__RMF_tag_data);
61 } else {
62 $this->errors[] = 'new .RMF tag ('.strlen($new__RMF_tag_data).' bytes) different length than old .RMF tag ('.$oldChunkInfo['.RMF']['length'].' bytes)';
63 fclose($fp_source);
64 return false;
65 }
66
67 if (@$oldChunkInfo['PROP']['length'] == strlen($new_PROP_tag_data)) {
68 fseek($fp_source, $oldChunkInfo['PROP']['offset'], SEEK_SET);
69 fwrite($fp_source, $new_PROP_tag_data);
70 } else {
71 $this->errors[] = 'new PROP tag ('.strlen($new_PROP_tag_data).' bytes) different length than old PROP tag ('.$oldChunkInfo['PROP']['length'].' bytes)';
72 fclose($fp_source);
73 return false;
74 }
75
76 if (@$oldChunkInfo['CONT']['length'] == strlen($new_CONT_tag_data)) {
77
78 // new data length is same as old data length - just overwrite
79 fseek($fp_source, $oldChunkInfo['CONT']['offset'], SEEK_SET);
80 fwrite($fp_source, $new_CONT_tag_data);
81 fclose($fp_source);
82 return true;
83
84 } else {
85
86 if (empty($oldChunkInfo['CONT'])) {
87 // no existing CONT chunk
88 $BeforeOffset = $oldChunkInfo['DATA']['offset'];
89 $AfterOffset = $oldChunkInfo['DATA']['offset'];
90 } else {
91 // new data is longer than old data
92 $BeforeOffset = $oldChunkInfo['CONT']['offset'];
93 $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length'];
94 }
95 if ($tempfilename = tempnam('*', 'getID3')) {
96 ob_start();
97 if ($fp_temp = fopen($tempfilename, 'wb')) {
98
99 rewind($fp_source);
100 fwrite($fp_temp, fread($fp_source, $BeforeOffset));
101 fwrite($fp_temp, $new_CONT_tag_data);
102 fseek($fp_source, $AfterOffset, SEEK_SET);
103 while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) {
104 fwrite($fp_temp, $buffer, strlen($buffer));
105 }
106 fclose($fp_temp);
107
108 if (copy($tempfilename, $this->filename)) {
109 unlink($tempfilename);
110 fclose($fp_source);
111 return true;
112 }
113 unlink($tempfilename);
114 $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.') - '.strip_tags(ob_get_contents());
115
116 } else {
117
118 $this->errors[] = 'Could not open '.$tempfilename.' mode "wb" - '.strip_tags(ob_get_contents());
119
120 }
121 ob_end_clean();
122 }
123 fclose($fp_source);
124 return false;
125
126 }
127
128
129 } else {
130 $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
131 return false;
132 }
133 }
134 $this->errors[] = 'File is not writeable: '.$this->filename;
135 return false;
136 }
GenerateRMFchunk(&$chunks)
Definition: write.real.php:138
GeneratePROPchunk(&$chunks, &$new_CONT_tag_data)
Definition: write.real.php:156

References getID3\analyze(), GenerateCONTchunk(), GeneratePROPchunk(), GenerateRMFchunk(), and GETID3_FREAD_BUFFER_SIZE.

+ Here is the call graph for this function:

◆ WriteReal() [2/2]

getid3_write_real::WriteReal ( )

Definition at line 30 of file write.real.php.

30 {
31 // File MUST be writeable - CHMOD(646) at least
32 if (is_writeable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) {
33
34 // Initialize getID3 engine
35 $getID3 = new getID3;
36 $OldThisFileInfo = $getID3->analyze($this->filename);
37 if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) {
38 $this->errors[] = 'Cannot write Real tags on old-style file format';
39 fclose($fp_source);
40 return false;
41 }
42
43 if (empty($OldThisFileInfo['real']['chunks'])) {
44 $this->errors[] = 'Cannot write Real tags because cannot find DATA chunk in file';
45 fclose($fp_source);
46 return false;
47 }
48 foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) {
49 $oldChunkInfo[$chunkarray['name']] = $chunkarray;
50 }
51 if (!empty($oldChunkInfo['CONT']['length'])) {
52 $this->paddedlength = max($oldChunkInfo['CONT']['length'], $this->paddedlength);
53 }
54
55 $new_CONT_tag_data = $this->GenerateCONTchunk();
56 $new_PROP_tag_data = $this->GeneratePROPchunk($OldThisFileInfo['real']['chunks'], $new_CONT_tag_data);
57 $new__RMF_tag_data = $this->GenerateRMFchunk($OldThisFileInfo['real']['chunks']);
58
59 if (isset($oldChunkInfo['.RMF']['length']) && ($oldChunkInfo['.RMF']['length'] == strlen($new__RMF_tag_data))) {
60 fseek($fp_source, $oldChunkInfo['.RMF']['offset']);
61 fwrite($fp_source, $new__RMF_tag_data);
62 } else {
63 $this->errors[] = 'new .RMF tag ('.strlen($new__RMF_tag_data).' bytes) different length than old .RMF tag ('.$oldChunkInfo['.RMF']['length'].' bytes)';
64 fclose($fp_source);
65 return false;
66 }
67
68 if (isset($oldChunkInfo['PROP']['length']) && ($oldChunkInfo['PROP']['length'] == strlen($new_PROP_tag_data))) {
69 fseek($fp_source, $oldChunkInfo['PROP']['offset']);
70 fwrite($fp_source, $new_PROP_tag_data);
71 } else {
72 $this->errors[] = 'new PROP tag ('.strlen($new_PROP_tag_data).' bytes) different length than old PROP tag ('.$oldChunkInfo['PROP']['length'].' bytes)';
73 fclose($fp_source);
74 return false;
75 }
76
77 if (isset($oldChunkInfo['CONT']['length']) && ($oldChunkInfo['CONT']['length'] == strlen($new_CONT_tag_data))) {
78
79 // new data length is same as old data length - just overwrite
80 fseek($fp_source, $oldChunkInfo['CONT']['offset']);
81 fwrite($fp_source, $new_CONT_tag_data);
82 fclose($fp_source);
83 return true;
84
85 } else {
86
87 if (empty($oldChunkInfo['CONT'])) {
88 // no existing CONT chunk
89 $BeforeOffset = $oldChunkInfo['DATA']['offset'];
90 $AfterOffset = $oldChunkInfo['DATA']['offset'];
91 } else {
92 // new data is longer than old data
93 $BeforeOffset = $oldChunkInfo['CONT']['offset'];
94 $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length'];
95 }
96 if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) {
97 if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) {
98
99 rewind($fp_source);
100 fwrite($fp_temp, fread($fp_source, $BeforeOffset));
101 fwrite($fp_temp, $new_CONT_tag_data);
102 fseek($fp_source, $AfterOffset);
103 while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
104 fwrite($fp_temp, $buffer, strlen($buffer));
105 }
106 fclose($fp_temp);
107
108 if (copy($tempfilename, $this->filename)) {
109 unlink($tempfilename);
110 fclose($fp_source);
111 return true;
112 }
113 unlink($tempfilename);
114 $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.')';
115
116 } else {
117 $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")';
118 }
119 }
120 fclose($fp_source);
121 return false;
122
123 }
124
125 }
126 $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")';
127 return false;
128 }

References getID3\analyze(), GenerateCONTchunk(), GeneratePROPchunk(), and GenerateRMFchunk().

+ Here is the call graph for this function:

Field Documentation

◆ $errors

getid3_write_real::$errors = array()

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

◆ $filename

getid3_write_real::$filename

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

◆ $fread_buffer_size

getid3_write_real::$fread_buffer_size = 32768

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

◆ $paddedlength

getid3_write_real::$paddedlength = 512

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

◆ $tag_data

getid3_write_real::$tag_data = array()

Definition at line 19 of file write.real.php.

◆ $warnings

getid3_write_real::$warnings = array()

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


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