ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
getid3_write_apetag Class Reference
+ Collaboration diagram for getid3_write_apetag:

Public Member Functions

 getid3_write_apetag ()
 
 WriteAPEtag ()
 
 DeleteAPEtag ()
 
 GenerateAPEtag ()
 
 GenerateAPEtagHeaderFooter (&$items, $isheader=false)
 
 GenerateAPEtagFlags ($header=true, $footer=true, $isheader=false, $encodingid=0, $readonly=false)
 
 CleanAPEtagItemKey ($itemkey)
 
 getid3_write_apetag ()
 
 WriteAPEtag ()
 
 DeleteAPEtag ()
 
 GenerateAPEtag ()
 
 GenerateAPEtagHeaderFooter (&$items, $isheader=false)
 
 GenerateAPEtagFlags ($header=true, $footer=true, $isheader=false, $encodingid=0, $readonly=false)
 
 CleanAPEtagItemKey ($itemkey)
 

Data Fields

 $filename
 
 $tag_data
 
 $always_preserve_replaygain = true
 
 $warnings = array()
 
 $errors = array()
 

Detailed Description

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

Member Function Documentation

◆ CleanAPEtagItemKey() [1/2]

getid3_write_apetag::CleanAPEtagItemKey (   $itemkey)

Definition at line 204 of file write.apetag.php.

204  {
205  $itemkey = preg_replace("#[^\x20-\x7E]#i", '', $itemkey);
206 
207  // http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html
208  switch (strtoupper($itemkey)) {
209  case 'EAN/UPC':
210  case 'ISBN':
211  case 'LC':
212  case 'ISRC':
213  $itemkey = strtoupper($itemkey);
214  break;
215 
216  default:
217  $itemkey = ucwords($itemkey);
218  break;
219  }
220  return $itemkey;
221 
222  }

◆ CleanAPEtagItemKey() [2/2]

getid3_write_apetag::CleanAPEtagItemKey (   $itemkey)

Definition at line 206 of file write.apetag.php.

Referenced by GenerateAPEtag().

206  {
207  $itemkey = eregi_replace("[^\x20-\x7E]", '', $itemkey);
208 
209  // http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html
210  switch (strtoupper($itemkey)) {
211  case 'EAN/UPC':
212  case 'ISBN':
213  case 'LC':
214  case 'ISRC':
215  $itemkey = strtoupper($itemkey);
216  break;
217 
218  default:
219  $itemkey = ucwords($itemkey);
220  break;
221  }
222  return $itemkey;
223 
224  }
+ Here is the caller graph for this function:

◆ DeleteAPEtag() [1/2]

getid3_write_apetag::DeleteAPEtag ( )

Definition at line 95 of file write.apetag.php.

References getID3\analyze().

95  {
96  $getID3 = new getID3;
97  $ThisFileInfo = $getID3->analyze($this->filename);
98  if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['ape']['tag_offset_end'])) {
99  if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) {
100 
101  flock($fp, LOCK_EX);
102  $oldignoreuserabort = ignore_user_abort(true);
103 
104  fseek($fp, $ThisFileInfo['ape']['tag_offset_end']);
105  $DataAfterAPE = '';
106  if ($ThisFileInfo['filesize'] > $ThisFileInfo['ape']['tag_offset_end']) {
107  $DataAfterAPE = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['ape']['tag_offset_end']);
108  }
109 
110  ftruncate($fp, $ThisFileInfo['ape']['tag_offset_start']);
111  fseek($fp, $ThisFileInfo['ape']['tag_offset_start']);
112 
113  if (!empty($DataAfterAPE)) {
114  fwrite($fp, $DataAfterAPE, strlen($DataAfterAPE));
115  }
116 
117  flock($fp, LOCK_UN);
118  fclose($fp);
119  ignore_user_abort($oldignoreuserabort);
120 
121  return true;
122  }
123  return false;
124  }
125  return true;
126  }
analyze($filename)
Definition: getid3.php:168
+ Here is the call graph for this function:

◆ DeleteAPEtag() [2/2]

getid3_write_apetag::DeleteAPEtag ( )

Definition at line 96 of file write.apetag.php.

References getID3\analyze().

Referenced by WriteAPEtag().

96  {
97  $getID3 = new getID3;
98  $ThisFileInfo = $getID3->analyze($this->filename);
99  if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['ape']['tag_offset_end'])) {
100  if ($fp = @fopen($this->filename, 'a+b')) {
101 
102  flock($fp, LOCK_EX);
103  $oldignoreuserabort = ignore_user_abort(true);
104 
105  fseek($fp, $ThisFileInfo['ape']['tag_offset_end'], SEEK_SET);
106  $DataAfterAPE = '';
107  if ($ThisFileInfo['filesize'] > $ThisFileInfo['ape']['tag_offset_end']) {
108  $DataAfterAPE = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['ape']['tag_offset_end']);
109  }
110 
111  ftruncate($fp, $ThisFileInfo['ape']['tag_offset_start']);
112  fseek($fp, $ThisFileInfo['ape']['tag_offset_start'], SEEK_SET);
113 
114  if (!empty($DataAfterAPE)) {
115  fwrite($fp, $DataAfterAPE, strlen($DataAfterAPE));
116  }
117 
118  flock($fp, LOCK_UN);
119  fclose($fp);
120  ignore_user_abort($oldignoreuserabort);
121 
122  return true;
123 
124  }
125  return false;
126  }
127  return true;
128  }
analyze($filename)
Definition: getid3.php:168
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenerateAPEtag() [1/2]

getid3_write_apetag::GenerateAPEtag ( )

Definition at line 129 of file write.apetag.php.

References CleanAPEtagItemKey(), GenerateAPEtagHeaderFooter(), and getid3_lib\LittleEndian2String().

129  {
130  // NOTE: All data passed to this function must be UTF-8 format
131 
132  $items = array();
133  if (!is_array($this->tag_data)) {
134  return false;
135  }
136  foreach ($this->tag_data as $key => $arrayofvalues) {
137  if (!is_array($arrayofvalues)) {
138  return false;
139  }
140 
141  $valuestring = '';
142  foreach ($arrayofvalues as $value) {
143  $valuestring .= str_replace("\x00", '', $value)."\x00";
144  }
145  $valuestring = rtrim($valuestring, "\x00");
146 
147  // Length of the assigned value in bytes
148  $tagitem = getid3_lib::LittleEndian2String(strlen($valuestring), 4);
149 
150  //$tagitem .= $this->GenerateAPEtagFlags(true, true, false, 0, false);
151  $tagitem .= "\x00\x00\x00\x00";
152 
153  $tagitem .= $this->CleanAPEtagItemKey($key)."\x00";
154  $tagitem .= $valuestring;
155 
156  $items[] = $tagitem;
157 
158  }
159 
160  return $this->GenerateAPEtagHeaderFooter($items, true).implode('', $items).$this->GenerateAPEtagHeaderFooter($items, false);
161  }
LittleEndian2String($number, $minbytes=1, $synchsafe=false)
Definition: getid3.lib.php:343
CleanAPEtagItemKey($itemkey)
GenerateAPEtagHeaderFooter(&$items, $isheader=false)
+ Here is the call graph for this function:

◆ GenerateAPEtag() [2/2]

getid3_write_apetag::GenerateAPEtag ( )

Definition at line 131 of file write.apetag.php.

References CleanAPEtagItemKey(), GenerateAPEtagHeaderFooter(), and getid3_lib\LittleEndian2String().

Referenced by WriteAPEtag().

131  {
132  // NOTE: All data passed to this function must be UTF-8 format
133 
134  $items = array();
135  if (!is_array($this->tag_data)) {
136  return false;
137  }
138  foreach ($this->tag_data as $key => $arrayofvalues) {
139  if (!is_array($arrayofvalues)) {
140  return false;
141  }
142 
143  $valuestring = '';
144  foreach ($arrayofvalues as $value) {
145  $valuestring .= str_replace("\x00", '', $value)."\x00";
146  }
147  $valuestring = rtrim($valuestring, "\x00");
148 
149  // Length of the assigned value in bytes
150  $tagitem = getid3_lib::LittleEndian2String(strlen($valuestring), 4);
151 
152  //$tagitem .= $this->GenerateAPEtagFlags(true, true, false, 0, false);
153  $tagitem .= "\x00\x00\x00\x00";
154 
155  $tagitem .= $this->CleanAPEtagItemKey($key)."\x00";
156  $tagitem .= $valuestring;
157 
158  $items[] = $tagitem;
159 
160  }
161 
162  return $this->GenerateAPEtagHeaderFooter($items, true).implode('', $items).$this->GenerateAPEtagHeaderFooter($items, false);
163  }
LittleEndian2String($number, $minbytes=1, $synchsafe=false)
Definition: getid3.lib.php:343
CleanAPEtagItemKey($itemkey)
GenerateAPEtagHeaderFooter(&$items, $isheader=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenerateAPEtagFlags() [1/2]

getid3_write_apetag::GenerateAPEtagFlags (   $header = true,
  $footer = true,
  $isheader = false,
  $encodingid = 0,
  $readonly = false 
)

Definition at line 179 of file write.apetag.php.

References $header.

179  {
180  $APEtagFlags = array_fill(0, 4, 0);
181  if ($header) {
182  $APEtagFlags[0] |= 0x80; // Tag contains a header
183  }
184  if (!$footer) {
185  $APEtagFlags[0] |= 0x40; // Tag contains no footer
186  }
187  if ($isheader) {
188  $APEtagFlags[0] |= 0x20; // This is the header, not the footer
189  }
190 
191  // 0: Item contains text information coded in UTF-8
192  // 1: Item contains binary information °)
193  // 2: Item is a locator of external stored information °°)
194  // 3: reserved
195  $APEtagFlags[3] |= ($encodingid << 1);
196 
197  if ($readonly) {
198  $APEtagFlags[3] |= 0x01; // Tag or Item is Read Only
199  }
200 
201  return chr($APEtagFlags[3]).chr($APEtagFlags[2]).chr($APEtagFlags[1]).chr($APEtagFlags[0]);
202  }
$header

◆ GenerateAPEtagFlags() [2/2]

getid3_write_apetag::GenerateAPEtagFlags (   $header = true,
  $footer = true,
  $isheader = false,
  $encodingid = 0,
  $readonly = false 
)

Definition at line 181 of file write.apetag.php.

References $header.

Referenced by GenerateAPEtagHeaderFooter().

181  {
182  $APEtagFlags = array_fill(0, 4, 0);
183  if ($header) {
184  $APEtagFlags[0] |= 0x80; // Tag contains a header
185  }
186  if (!$footer) {
187  $APEtagFlags[0] |= 0x40; // Tag contains no footer
188  }
189  if ($isheader) {
190  $APEtagFlags[0] |= 0x20; // This is the header, not the footer
191  }
192 
193  // 0: Item contains text information coded in UTF-8
194  // 1: Item contains binary information °)
195  // 2: Item is a locator of external stored information °°)
196  // 3: reserved
197  $APEtagFlags[3] |= ($encodingid << 1);
198 
199  if ($readonly) {
200  $APEtagFlags[3] |= 0x01; // Tag or Item is Read Only
201  }
202 
203  return chr($APEtagFlags[3]).chr($APEtagFlags[2]).chr($APEtagFlags[1]).chr($APEtagFlags[0]);
204  }
$header
+ Here is the caller graph for this function:

◆ GenerateAPEtagHeaderFooter() [1/2]

getid3_write_apetag::GenerateAPEtagHeaderFooter ( $items,
  $isheader = false 
)

Definition at line 163 of file write.apetag.php.

References GenerateAPEtagFlags(), and getid3_lib\LittleEndian2String().

163  {
164  $tagdatalength = 0;
165  foreach ($items as $itemdata) {
166  $tagdatalength += strlen($itemdata);
167  }
168 
169  $APEheader = 'APETAGEX';
170  $APEheader .= getid3_lib::LittleEndian2String(2000, 4);
171  $APEheader .= getid3_lib::LittleEndian2String(32 + $tagdatalength, 4);
172  $APEheader .= getid3_lib::LittleEndian2String(count($items), 4);
173  $APEheader .= $this->GenerateAPEtagFlags(true, true, $isheader, 0, false);
174  $APEheader .= str_repeat("\x00", 8);
175 
176  return $APEheader;
177  }
LittleEndian2String($number, $minbytes=1, $synchsafe=false)
Definition: getid3.lib.php:343
GenerateAPEtagFlags($header=true, $footer=true, $isheader=false, $encodingid=0, $readonly=false)
+ Here is the call graph for this function:

◆ GenerateAPEtagHeaderFooter() [2/2]

getid3_write_apetag::GenerateAPEtagHeaderFooter ( $items,
  $isheader = false 
)

Definition at line 165 of file write.apetag.php.

References GenerateAPEtagFlags(), and getid3_lib\LittleEndian2String().

Referenced by GenerateAPEtag().

165  {
166  $tagdatalength = 0;
167  foreach ($items as $itemdata) {
168  $tagdatalength += strlen($itemdata);
169  }
170 
171  $APEheader = 'APETAGEX';
172  $APEheader .= getid3_lib::LittleEndian2String(2000, 4);
173  $APEheader .= getid3_lib::LittleEndian2String(32 + $tagdatalength, 4);
174  $APEheader .= getid3_lib::LittleEndian2String(count($items), 4);
175  $APEheader .= $this->GenerateAPEtagFlags(true, true, $isheader, 0, false);
176  $APEheader .= str_repeat("\x00", 8);
177 
178  return $APEheader;
179  }
LittleEndian2String($number, $minbytes=1, $synchsafe=false)
Definition: getid3.lib.php:343
GenerateAPEtagFlags($header=true, $footer=true, $isheader=false, $encodingid=0, $readonly=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getid3_write_apetag() [1/2]

getid3_write_apetag::getid3_write_apetag ( )

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

28  {
29  return true;
30  }

◆ getid3_write_apetag() [2/2]

getid3_write_apetag::getid3_write_apetag ( )

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

29  {
30  return true;
31  }

◆ WriteAPEtag() [1/2]

getid3_write_apetag::WriteAPEtag ( )

Definition at line 32 of file write.apetag.php.

References getID3\analyze(), DeleteAPEtag(), and GenerateAPEtag().

32  {
33  // NOTE: All data passed to this function must be UTF-8 format
34 
35  $getID3 = new getID3;
36  $ThisFileInfo = $getID3->analyze($this->filename);
37 
38  if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) {
39  if ($ThisFileInfo['ape']['tag_offset_start'] >= $ThisFileInfo['lyrics3']['tag_offset_end']) {
40  // Current APE tag between Lyrics3 and ID3v1/EOF
41  // This break Lyrics3 functionality
42  if (!$this->DeleteAPEtag()) {
43  return false;
44  }
45  $ThisFileInfo = $getID3->analyze($this->filename);
46  }
47  }
48 
49  if ($this->always_preserve_replaygain) {
50  $ReplayGainTagsToPreserve = array('mp3gain_minmax', 'mp3gain_album_minmax', 'mp3gain_undo', 'replaygain_track_peak', 'replaygain_track_gain', 'replaygain_album_peak', 'replaygain_album_gain');
51  foreach ($ReplayGainTagsToPreserve as $rg_key) {
52  if (isset($ThisFileInfo['ape']['items'][strtolower($rg_key)]['data'][0]) && !isset($this->tag_data[strtoupper($rg_key)][0])) {
53  $this->tag_data[strtoupper($rg_key)][0] = $ThisFileInfo['ape']['items'][strtolower($rg_key)]['data'][0];
54  }
55  }
56  }
57 
58  if ($APEtag = $this->GenerateAPEtag()) {
59  if ($fp = @fopen($this->filename, 'a+b')) {
60  $oldignoreuserabort = ignore_user_abort(true);
61  flock($fp, LOCK_EX);
62 
63  $PostAPEdataOffset = $ThisFileInfo['avdataend'];
64  if (isset($ThisFileInfo['ape']['tag_offset_end'])) {
65  $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['ape']['tag_offset_end']);
66  }
67  if (isset($ThisFileInfo['lyrics3']['tag_offset_start'])) {
68  $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['lyrics3']['tag_offset_start']);
69  }
70  fseek($fp, $PostAPEdataOffset, SEEK_SET);
71  $PostAPEdata = '';
72  if ($ThisFileInfo['filesize'] > $PostAPEdataOffset) {
73  $PostAPEdata = fread($fp, $ThisFileInfo['filesize'] - $PostAPEdataOffset);
74  }
75 
76  fseek($fp, $PostAPEdataOffset, SEEK_SET);
77  if (isset($ThisFileInfo['ape']['tag_offset_start'])) {
78  fseek($fp, $ThisFileInfo['ape']['tag_offset_start'], SEEK_SET);
79  }
80  ftruncate($fp, ftell($fp));
81  fwrite($fp, $APEtag, strlen($APEtag));
82  if (!empty($PostAPEdata)) {
83  fwrite($fp, $PostAPEdata, strlen($PostAPEdata));
84  }
85  flock($fp, LOCK_UN);
86  fclose($fp);
87  ignore_user_abort($oldignoreuserabort);
88  return true;
89 
90  }
91  return false;
92  }
93  return false;
94  }
analyze($filename)
Definition: getid3.php:168
+ Here is the call graph for this function:

◆ WriteAPEtag() [2/2]

getid3_write_apetag::WriteAPEtag ( )

Definition at line 33 of file write.apetag.php.

References getID3\analyze(), DeleteAPEtag(), and GenerateAPEtag().

33  {
34  // NOTE: All data passed to this function must be UTF-8 format
35 
36  $getID3 = new getID3;
37  $ThisFileInfo = $getID3->analyze($this->filename);
38 
39  if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) {
40  if ($ThisFileInfo['ape']['tag_offset_start'] >= $ThisFileInfo['lyrics3']['tag_offset_end']) {
41  // Current APE tag between Lyrics3 and ID3v1/EOF
42  // This break Lyrics3 functionality
43  if (!$this->DeleteAPEtag()) {
44  return false;
45  }
46  $ThisFileInfo = $getID3->analyze($this->filename);
47  }
48  }
49 
50  if ($this->always_preserve_replaygain) {
51  $ReplayGainTagsToPreserve = array('mp3gain_minmax', 'mp3gain_album_minmax', 'mp3gain_undo', 'replaygain_track_peak', 'replaygain_track_gain', 'replaygain_album_peak', 'replaygain_album_gain');
52  foreach ($ReplayGainTagsToPreserve as $rg_key) {
53  if (isset($ThisFileInfo['ape']['items'][strtolower($rg_key)]['data'][0]) && !isset($this->tag_data[strtoupper($rg_key)][0])) {
54  $this->tag_data[strtoupper($rg_key)][0] = $ThisFileInfo['ape']['items'][strtolower($rg_key)]['data'][0];
55  }
56  }
57  }
58 
59  if ($APEtag = $this->GenerateAPEtag()) {
60  if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) {
61  $oldignoreuserabort = ignore_user_abort(true);
62  flock($fp, LOCK_EX);
63 
64  $PostAPEdataOffset = $ThisFileInfo['avdataend'];
65  if (isset($ThisFileInfo['ape']['tag_offset_end'])) {
66  $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['ape']['tag_offset_end']);
67  }
68  if (isset($ThisFileInfo['lyrics3']['tag_offset_start'])) {
69  $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['lyrics3']['tag_offset_start']);
70  }
71  fseek($fp, $PostAPEdataOffset);
72  $PostAPEdata = '';
73  if ($ThisFileInfo['filesize'] > $PostAPEdataOffset) {
74  $PostAPEdata = fread($fp, $ThisFileInfo['filesize'] - $PostAPEdataOffset);
75  }
76 
77  fseek($fp, $PostAPEdataOffset);
78  if (isset($ThisFileInfo['ape']['tag_offset_start'])) {
79  fseek($fp, $ThisFileInfo['ape']['tag_offset_start']);
80  }
81  ftruncate($fp, ftell($fp));
82  fwrite($fp, $APEtag, strlen($APEtag));
83  if (!empty($PostAPEdata)) {
84  fwrite($fp, $PostAPEdata, strlen($PostAPEdata));
85  }
86  flock($fp, LOCK_UN);
87  fclose($fp);
88  ignore_user_abort($oldignoreuserabort);
89  return true;
90  }
91  }
92  return false;
93  }
analyze($filename)
Definition: getid3.php:168
+ Here is the call graph for this function:

Field Documentation

◆ $always_preserve_replaygain

getid3_write_apetag::$always_preserve_replaygain = true

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

◆ $errors

getid3_write_apetag::$errors = array()

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

◆ $filename

getid3_write_apetag::$filename

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

◆ $tag_data

getid3_write_apetag::$tag_data

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

◆ $warnings

getid3_write_apetag::$warnings = array()

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


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