~ubuntu-branches/debian/sid/ampache/sid

« back to all changes in this revision

Viewing changes to modules/getid3/write.php

  • Committer: Package Import Robot
  • Author(s): Charlie Smotherman
  • Date: 2013-08-27 13:19:48 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20130827131948-1czew0zxn6u70dtv
Tags: 3.6-rzb2752+dfsg-1
* New upsteam snapshot.  Contains important bug fixes to the installer.
* Correct typo in ampache-common.postrm.
* Remove courtousy copy of php-getid3, during repack.  Closes: #701526
* Update package to use dh_linktree to make the needed sym links to the
  needed system libs that were removed during repack.
* Update debian/rules to reflect upstreams removing/moving of modules.
* Update debian/ampache-common.install to reflect upstreams removal of files.
* Updated to use new apache2.4 API. Closes: #669756
* Updated /debian/po/de.po thx David Prévot for the patch.  Closes:  #691963
* M3U import is now ordered, fixed upstream.  Closes: #684984
* Text input area has been resized so IPv6 addresses will now fit, fixed
  upstream.  Closes:  #716230
* Added ampache-common.preinst to make sure that the courtousy copies of code
  dirs are empty so dh_linktree can do it's magic on upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/////////////////////////////////////////////////////////////////
3
 
/// getID3() by James Heinrich <info@getid3.org>               //
4
 
//  available at http://getid3.sourceforge.net                 //
5
 
//            or http://www.getid3.org                         //
6
 
/////////////////////////////////////////////////////////////////
7
 
// See readme.txt for more details                             //
8
 
/////////////////////////////////////////////////////////////////
9
 
///                                                            //
10
 
// write.php                                                   //
11
 
// module for writing tags (APEv2, ID3v1, ID3v2)               //
12
 
// dependencies: getid3.lib.php                                //
13
 
//               write.apetag.php (optional)                   //
14
 
//               write.id3v1.php (optional)                    //
15
 
//               write.id3v2.php (optional)                    //
16
 
//               write.vorbiscomment.php (optional)            //
17
 
//               write.metaflac.php (optional)                 //
18
 
//               write.lyrics3.php (optional)                  //
19
 
//                                                            ///
20
 
/////////////////////////////////////////////////////////////////
21
 
 
22
 
if (!defined('GETID3_INCLUDEPATH')) {
23
 
        throw new Exception('getid3.php MUST be included before calling getid3_writetags');
24
 
}
25
 
if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
26
 
        throw new Exception('write.php depends on getid3.lib.php, which is missing.');
27
 
}
28
 
 
29
 
 
30
 
// NOTES:
31
 
//
32
 
// You should pass data here with standard field names as follows:
33
 
// * TITLE
34
 
// * ARTIST
35
 
// * ALBUM
36
 
// * TRACKNUMBER
37
 
// * COMMENT
38
 
// * GENRE
39
 
// * YEAR
40
 
// * ATTACHED_PICTURE (ID3v2 only)
41
 
//
42
 
// http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html
43
 
// The APEv2 Tag Items Keys definition says "TRACK" is correct but foobar2000 uses "TRACKNUMBER" instead
44
 
// Pass data here as "TRACKNUMBER" for compatability with all formats
45
 
 
46
 
 
47
 
class getid3_writetags
48
 
{
49
 
        // public
50
 
        var $filename;                            // absolute filename of file to write tags to
51
 
        var $tagformats         = array();        // array of tag formats to write ('id3v1', 'id3v2.2', 'id2v2.3', 'id3v2.4', 'ape', 'vorbiscomment', 'metaflac', 'real')
52
 
        var $tag_data           = array(array()); // 2-dimensional array of tag data (ex: $data['ARTIST'][0] = 'Elvis')
53
 
        var $tag_encoding       = 'ISO-8859-1';   // text encoding used for tag data ('ISO-8859-1', 'UTF-8', 'UTF-16', 'UTF-16LE', 'UTF-16BE', )
54
 
        var $overwrite_tags     = true;          // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data
55
 
        var $remove_other_tags  = false;          // if true will erase remove all existing tags and only write those passed in $tagformats; if false will ignore any tags not mentioned in $tagformats
56
 
 
57
 
        var $id3v2_tag_language = 'eng';          // ISO-639-2 3-character language code needed for some ID3v2 frames (http://www.id3.org/iso639-2.html)
58
 
        var $id3v2_paddedlength = 4096;           // minimum length of ID3v2 tags (will be padded to this length if tag data is shorter)
59
 
 
60
 
        var $warnings           = array();        // any non-critical errors will be stored here
61
 
        var $errors             = array();        // any critical errors will be stored here
62
 
 
63
 
        // private
64
 
        var $ThisFileInfo; // analysis of file before writing
65
 
 
66
 
        function getid3_writetags() {
67
 
                return true;
68
 
        }
69
 
 
70
 
 
71
 
        function WriteTags() {
72
 
 
73
 
                if (empty($this->filename)) {
74
 
                        $this->errors[] = 'filename is undefined in getid3_writetags';
75
 
                        return false;
76
 
                } elseif (!file_exists($this->filename)) {
77
 
                        $this->errors[] = 'filename set to non-existant file "'.$this->filename.'" in getid3_writetags';
78
 
                        return false;
79
 
                }
80
 
 
81
 
                if (!is_array($this->tagformats)) {
82
 
                        $this->errors[] = 'tagformats must be an array in getid3_writetags';
83
 
                        return false;
84
 
                }
85
 
 
86
 
                $TagFormatsToRemove = array();
87
 
                if (filesize($this->filename) == 0) {
88
 
 
89
 
                        // empty file special case - allow any tag format, don't check existing format
90
 
                        // could be useful if you want to generate tag data for a non-existant file
91
 
                        $this->ThisFileInfo = array('fileformat'=>'');
92
 
                        $AllowedTagFormats = array('id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3');
93
 
 
94
 
                } else {
95
 
 
96
 
                        $getID3 = new getID3;
97
 
                        $getID3->encoding = $this->tag_encoding;
98
 
                        $this->ThisFileInfo = $getID3->analyze($this->filename);
99
 
 
100
 
                        // check for what file types are allowed on this fileformat
101
 
                        switch (isset($this->ThisFileInfo['fileformat']) ? $this->ThisFileInfo['fileformat'] : '') {
102
 
                                case 'mp3':
103
 
                                case 'mp2':
104
 
                                case 'mp1':
105
 
                                case 'riff': // maybe not officially, but people do it anyway
106
 
                                        $AllowedTagFormats = array('id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3');
107
 
                                        break;
108
 
 
109
 
                                case 'mpc':
110
 
                                        $AllowedTagFormats = array('ape');
111
 
                                        break;
112
 
 
113
 
                                case 'flac':
114
 
                                        $AllowedTagFormats = array('metaflac');
115
 
                                        break;
116
 
 
117
 
                                case 'real':
118
 
                                        $AllowedTagFormats = array('real');
119
 
                                        break;
120
 
 
121
 
                                case 'ogg':
122
 
                                        switch (isset($this->ThisFileInfo['audio']['dataformat']) ? $this->ThisFileInfo['audio']['dataformat'] : '') {
123
 
                                                case 'flac':
124
 
                                                        //$AllowedTagFormats = array('metaflac');
125
 
                                                        $this->errors[] = 'metaflac is not (yet) compatible with OggFLAC files';
126
 
                                                        return false;
127
 
                                                        break;
128
 
                                                case 'vorbis':
129
 
                                                        $AllowedTagFormats = array('vorbiscomment');
130
 
                                                        break;
131
 
                                                default:
132
 
                                                        $this->errors[] = 'metaflac is not (yet) compatible with Ogg files other than OggVorbis';
133
 
                                                        return false;
134
 
                                                        break;
135
 
                                        }
136
 
                                        break;
137
 
 
138
 
                                default:
139
 
                                        $AllowedTagFormats = array();
140
 
                                        break;
141
 
                        }
142
 
                        foreach ($this->tagformats as $requested_tag_format) {
143
 
                                if (!in_array($requested_tag_format, $AllowedTagFormats)) {
144
 
                                        $errormessage = 'Tag format "'.$requested_tag_format.'" is not allowed on "'.(isset($this->ThisFileInfo['fileformat']) ? $this->ThisFileInfo['fileformat'] : '');
145
 
                                        $errormessage .= (isset($this->ThisFileInfo['audio']['dataformat']) ? '.'.$this->ThisFileInfo['audio']['dataformat'] : '');
146
 
                                        $errormessage .= '" files';
147
 
                                        $this->errors[] = $errormessage;
148
 
                                        return false;
149
 
                                }
150
 
                        }
151
 
 
152
 
                        // List of other tag formats, removed if requested
153
 
                        if ($this->remove_other_tags) {
154
 
                                foreach ($AllowedTagFormats as $AllowedTagFormat) {
155
 
                                        switch ($AllowedTagFormat) {
156
 
                                                case 'id3v2.2':
157
 
                                                case 'id3v2.3':
158
 
                                                case 'id3v2.4':
159
 
                                                        if (!in_array('id3v2', $TagFormatsToRemove) && !in_array('id3v2.2', $this->tagformats) && !in_array('id3v2.3', $this->tagformats) && !in_array('id3v2.4', $this->tagformats)) {
160
 
                                                                $TagFormatsToRemove[] = 'id3v2';
161
 
                                                        }
162
 
                                                        break;
163
 
 
164
 
                                                default:
165
 
                                                        if (!in_array($AllowedTagFormat, $this->tagformats)) {
166
 
                                                                $TagFormatsToRemove[] = $AllowedTagFormat;
167
 
                                                        }
168
 
                                                        break;
169
 
                                        }
170
 
                                }
171
 
                        }
172
 
                }
173
 
 
174
 
                $WritingFilesToInclude = array_merge($this->tagformats, $TagFormatsToRemove);
175
 
 
176
 
                // Check for required include files and include them
177
 
                foreach ($WritingFilesToInclude as $tagformat) {
178
 
                        switch ($tagformat) {
179
 
                                case 'ape':
180
 
                                        $GETID3_ERRORARRAY = &$this->errors;
181
 
                                        if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.apetag.php', __FILE__, false)) {
182
 
                                                return false;
183
 
                                        }
184
 
                                        break;
185
 
 
186
 
                                case 'id3v1':
187
 
                                case 'lyrics3':
188
 
                                case 'vorbiscomment':
189
 
                                case 'metaflac':
190
 
                                case 'real':
191
 
                                        $GETID3_ERRORARRAY = &$this->errors;
192
 
                                        if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.'.$tagformat.'.php', __FILE__, false)) {
193
 
                                                return false;
194
 
                                        }
195
 
                                        break;
196
 
 
197
 
                                case 'id3v2.2':
198
 
                                case 'id3v2.3':
199
 
                                case 'id3v2.4':
200
 
                                case 'id3v2':
201
 
                                        $GETID3_ERRORARRAY = &$this->errors;
202
 
                                        if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v2.php', __FILE__, false)) {
203
 
                                                return false;
204
 
                                        }
205
 
                                        break;
206
 
 
207
 
                                default:
208
 
                                        $this->errors[] = 'unknown tag format "'.$tagformat.'" in $tagformats in WriteTags()';
209
 
                                        return false;
210
 
                                        break;
211
 
                        }
212
 
 
213
 
                }
214
 
 
215
 
                // Validation of supplied data
216
 
                if (!is_array($this->tag_data)) {
217
 
                        $this->errors[] = '$this->tag_data is not an array in WriteTags()';
218
 
                        return false;
219
 
                }
220
 
                // convert supplied data array keys to upper case, if they're not already
221
 
                foreach ($this->tag_data as $tag_key => $tag_array) {
222
 
                        if (strtoupper($tag_key) !== $tag_key) {
223
 
                                $this->tag_data[strtoupper($tag_key)] = $this->tag_data[$tag_key];
224
 
                                unset($this->tag_data[$tag_key]);
225
 
                        }
226
 
                }
227
 
                // convert source data array keys to upper case, if they're not already
228
 
                if (!empty($this->ThisFileInfo['tags'])) {
229
 
                        foreach ($this->ThisFileInfo['tags'] as $tag_format => $tag_data_array) {
230
 
                                foreach ($tag_data_array as $tag_key => $tag_array) {
231
 
                                        if (strtoupper($tag_key) !== $tag_key) {
232
 
                                                $this->ThisFileInfo['tags'][$tag_format][strtoupper($tag_key)] = $this->ThisFileInfo['tags'][$tag_format][$tag_key];
233
 
                                                unset($this->ThisFileInfo['tags'][$tag_format][$tag_key]);
234
 
                                        }
235
 
                                }
236
 
                        }
237
 
                }
238
 
 
239
 
                // Convert "TRACK" to "TRACKNUMBER" (if needed) for compatability with all formats
240
 
                if (isset($this->tag_data['TRACK']) && !isset($this->tag_data['TRACKNUMBER'])) {
241
 
                        $this->tag_data['TRACKNUMBER'] = $this->tag_data['TRACK'];
242
 
                        unset($this->tag_data['TRACK']);
243
 
                }
244
 
 
245
 
                // Remove all other tag formats, if requested
246
 
                if ($this->remove_other_tags) {
247
 
                        $this->DeleteTags($TagFormatsToRemove);
248
 
                }
249
 
 
250
 
                // Write data for each tag format
251
 
                foreach ($this->tagformats as $tagformat) {
252
 
                        $success = false; // overridden if tag writing is successful
253
 
                        switch ($tagformat) {
254
 
                                case 'ape':
255
 
                                        $ape_writer = new getid3_write_apetag;
256
 
                                        if (($ape_writer->tag_data = $this->FormatDataForAPE()) !== false) {
257
 
                                                $ape_writer->filename = $this->filename;
258
 
                                                if (($success = $ape_writer->WriteAPEtag()) === false) {
259
 
                                                        $this->errors[] = 'WriteAPEtag() failed with message(s):<pre><ul><li>'.str_replace("\n", '</li><li>', htmlentities(trim(implode("\n", $ape_writer->errors)))).'</li></ul></pre>';
260
 
                                                }
261
 
                                        } else {
262
 
                                                $this->errors[] = 'FormatDataForAPE() failed';
263
 
                                        }
264
 
                                        break;
265
 
 
266
 
                                case 'id3v1':
267
 
                                        $id3v1_writer = new getid3_write_id3v1;
268
 
                                        if (($id3v1_writer->tag_data = $this->FormatDataForID3v1()) !== false) {
269
 
                                                $id3v1_writer->filename = $this->filename;
270
 
                                                if (($success = $id3v1_writer->WriteID3v1()) === false) {
271
 
                                                        $this->errors[] = 'WriteID3v1() failed with message(s):<pre><ul><li>'.str_replace("\n", '</li><li>', htmlentities(trim(implode("\n", $id3v1_writer->errors)))).'</li></ul></pre>';
272
 
                                                }
273
 
                                        } else {
274
 
                                                $this->errors[] = 'FormatDataForID3v1() failed';
275
 
                                        }
276
 
                                        break;
277
 
 
278
 
                                case 'id3v2.2':
279
 
                                case 'id3v2.3':
280
 
                                case 'id3v2.4':
281
 
                                        $id3v2_writer = new getid3_write_id3v2;
282
 
                                        $id3v2_writer->majorversion = intval(substr($tagformat, -1));
283
 
                                        $id3v2_writer->paddedlength = $this->id3v2_paddedlength;
284
 
                                        if (($id3v2_writer->tag_data = $this->FormatDataForID3v2($id3v2_writer->majorversion)) !== false) {
285
 
                                                $id3v2_writer->filename = $this->filename;
286
 
                                                if (($success = $id3v2_writer->WriteID3v2()) === false) {
287
 
                                                        $this->errors[] = 'WriteID3v2() failed with message(s):<pre><ul><li>'.str_replace("\n", '</li><li>', htmlentities(trim(implode("\n", $id3v2_writer->errors)))).'</li></ul></pre>';
288
 
                                                }
289
 
                                        } else {
290
 
                                                $this->errors[] = 'FormatDataForID3v2() failed';
291
 
                                        }
292
 
                                        break;
293
 
 
294
 
                                case 'vorbiscomment':
295
 
                                        $vorbiscomment_writer = new getid3_write_vorbiscomment;
296
 
                                        if (($vorbiscomment_writer->tag_data = $this->FormatDataForVorbisComment()) !== false) {
297
 
                                                $vorbiscomment_writer->filename = $this->filename;
298
 
                                                if (($success = $vorbiscomment_writer->WriteVorbisComment()) === false) {
299
 
                                                        $this->errors[] = 'WriteVorbisComment() failed with message(s):<pre><ul><li>'.str_replace("\n", '</li><li>', htmlentities(trim(implode("\n", $vorbiscomment_writer->errors)))).'</li></ul></pre>';
300
 
                                                }
301
 
                                        } else {
302
 
                                                $this->errors[] = 'FormatDataForVorbisComment() failed';
303
 
                                        }
304
 
                                        break;
305
 
 
306
 
                                case 'metaflac':
307
 
                                        $metaflac_writer = new getid3_write_metaflac;
308
 
                                        if (($metaflac_writer->tag_data = $this->FormatDataForMetaFLAC()) !== false) {
309
 
                                                $metaflac_writer->filename = $this->filename;
310
 
                                                if (($success = $metaflac_writer->WriteMetaFLAC()) === false) {
311
 
                                                        $this->errors[] = 'WriteMetaFLAC() failed with message(s):<pre><ul><li>'.str_replace("\n", '</li><li>', htmlentities(trim(implode("\n", $metaflac_writer->errors)))).'</li></ul></pre>';
312
 
                                                }
313
 
                                        } else {
314
 
                                                $this->errors[] = 'FormatDataForMetaFLAC() failed';
315
 
                                        }
316
 
                                        break;
317
 
 
318
 
                                case 'real':
319
 
                                        $real_writer = new getid3_write_real;
320
 
                                        if (($real_writer->tag_data = $this->FormatDataForReal()) !== false) {
321
 
                                                $real_writer->filename = $this->filename;
322
 
                                                if (($success = $real_writer->WriteReal()) === false) {
323
 
                                                        $this->errors[] = 'WriteReal() failed with message(s):<pre><ul><li>'.str_replace("\n", '</li><li>', htmlentities(trim(implode("\n", $real_writer->errors)))).'</li></ul></pre>';
324
 
                                                }
325
 
                                        } else {
326
 
                                                $this->errors[] = 'FormatDataForReal() failed';
327
 
                                        }
328
 
                                        break;
329
 
 
330
 
                                default:
331
 
                                        $this->errors[] = 'Invalid tag format to write: "'.$tagformat.'"';
332
 
                                        return false;
333
 
                                        break;
334
 
                        }
335
 
                        if (!$success) {
336
 
                                return false;
337
 
                        }
338
 
                }
339
 
                return true;
340
 
 
341
 
        }
342
 
 
343
 
 
344
 
        function DeleteTags($TagFormatsToDelete) {
345
 
                foreach ($TagFormatsToDelete as $DeleteTagFormat) {
346
 
                        $success = false; // overridden if tag deletion is successful
347
 
                        switch ($DeleteTagFormat) {
348
 
                                case 'id3v1':
349
 
                                        $id3v1_writer = new getid3_write_id3v1;
350
 
                                        $id3v1_writer->filename = $this->filename;
351
 
                                        if (($success = $id3v1_writer->RemoveID3v1()) === false) {
352
 
                                                $this->errors[] = 'RemoveID3v1() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $id3v1_writer->errors)).'</LI></UL></PRE>';
353
 
                                        }
354
 
                                        break;
355
 
 
356
 
                                case 'id3v2':
357
 
                                        $id3v2_writer = new getid3_write_id3v2;
358
 
                                        $id3v2_writer->filename = $this->filename;
359
 
                                        if (($success = $id3v2_writer->RemoveID3v2()) === false) {
360
 
                                                $this->errors[] = 'RemoveID3v2() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $id3v2_writer->errors)).'</LI></UL></PRE>';
361
 
                                        }
362
 
                                        break;
363
 
 
364
 
                                case 'ape':
365
 
                                        $ape_writer = new getid3_write_apetag;
366
 
                                        $ape_writer->filename = $this->filename;
367
 
                                        if (($success = $ape_writer->DeleteAPEtag()) === false) {
368
 
                                                $this->errors[] = 'DeleteAPEtag() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $ape_writer->errors)).'</LI></UL></PRE>';
369
 
                                        }
370
 
                                        break;
371
 
 
372
 
                                case 'vorbiscomment':
373
 
                                        $vorbiscomment_writer = new getid3_write_vorbiscomment;
374
 
                                        $vorbiscomment_writer->filename = $this->filename;
375
 
                                        if (($success = $vorbiscomment_writer->DeleteVorbisComment()) === false) {
376
 
                                                $this->errors[] = 'DeleteVorbisComment() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $vorbiscomment_writer->errors)).'</LI></UL></PRE>';
377
 
                                        }
378
 
                                        break;
379
 
 
380
 
                                case 'metaflac':
381
 
                                        $metaflac_writer = new getid3_write_metaflac;
382
 
                                        $metaflac_writer->filename = $this->filename;
383
 
                                        if (($success = $metaflac_writer->DeleteMetaFLAC()) === false) {
384
 
                                                $this->errors[] = 'DeleteMetaFLAC() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $metaflac_writer->errors)).'</LI></UL></PRE>';
385
 
                                        }
386
 
                                        break;
387
 
 
388
 
                                case 'lyrics3':
389
 
                                        $lyrics3_writer = new getid3_write_lyrics3;
390
 
                                        $lyrics3_writer->filename = $this->filename;
391
 
                                        if (($success = $lyrics3_writer->DeleteLyrics3()) === false) {
392
 
                                                $this->errors[] = 'DeleteLyrics3() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $lyrics3_writer->errors)).'</LI></UL></PRE>';
393
 
                                        }
394
 
                                        break;
395
 
 
396
 
                                case 'real':
397
 
                                        $real_writer = new getid3_write_real;
398
 
                                        $real_writer->filename = $this->filename;
399
 
                                        if (($success = $real_writer->RemoveReal()) === false) {
400
 
                                                $this->errors[] = 'RemoveReal() failed with message(s):<PRE><UL><LI>'.trim(implode('</LI><LI>', $real_writer->errors)).'</LI></UL></PRE>';
401
 
                                        }
402
 
                                        break;
403
 
 
404
 
                                default:
405
 
                                        $this->errors[] = 'Invalid tag format to delete: "'.$tagformat.'"';
406
 
                                        return false;
407
 
                                        break;
408
 
                        }
409
 
                        if (!$success) {
410
 
                                return false;
411
 
                        }
412
 
                }
413
 
                return true;
414
 
        }
415
 
 
416
 
 
417
 
        function MergeExistingTagData($TagFormat, &$tag_data) {
418
 
                // Merge supplied data with existing data, if requested
419
 
                if ($this->overwrite_tags) {
420
 
                        // do nothing - ignore previous data
421
 
                } else {
422
 
throw new Exception('$this->overwrite_tags=false is known to be buggy in this version of getID3. Will be fixed in the near future, check www.getid3.org for a newer version.');
423
 
                        if (!isset($this->ThisFileInfo['tags'][$TagFormat])) {
424
 
                                return false;
425
 
                        }
426
 
                        $tag_data = array_merge_recursive($tag_data, $this->ThisFileInfo['tags'][$TagFormat]);
427
 
                }
428
 
                return true;
429
 
        }
430
 
 
431
 
        function FormatDataForAPE() {
432
 
                $ape_tag_data = array();
433
 
                foreach ($this->tag_data as $tag_key => $valuearray) {
434
 
                        switch ($tag_key) {
435
 
                                case 'ATTACHED_PICTURE':
436
 
                                        // ATTACHED_PICTURE is ID3v2 only - ignore
437
 
                                        $this->warnings[] = '$data['.$tag_key.'] is assumed to be ID3v2 APIC data - NOT written to APE tag';
438
 
                                        break;
439
 
 
440
 
                                default:
441
 
                                        foreach ($valuearray as $key => $value) {
442
 
                                                if (is_string($value) || is_numeric($value)) {
443
 
                                                        $ape_tag_data[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value);
444
 
                                                } else {
445
 
                                                        $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to APE tag';
446
 
                                                        unset($ape_tag_data[$tag_key]);
447
 
                                                        break;
448
 
                                                }
449
 
                                        }
450
 
                                        break;
451
 
                        }
452
 
                }
453
 
                $this->MergeExistingTagData('ape', $ape_tag_data);
454
 
                return $ape_tag_data;
455
 
        }
456
 
 
457
 
 
458
 
        function FormatDataForID3v1() {
459
 
                $tag_data_id3v1['genreid'] = 255;
460
 
                if (!empty($this->tag_data['GENRE'])) {
461
 
                        foreach ($this->tag_data['GENRE'] as $key => $value) {
462
 
                                if (getid3_id3v1::LookupGenreID($value) !== false) {
463
 
                                        $tag_data_id3v1['genreid'] = getid3_id3v1::LookupGenreID($value);
464
 
                                        break;
465
 
                                }
466
 
                        }
467
 
                }
468
 
                $tag_data_id3v1['title']   =        getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE']      ) ? $this->tag_data['TITLE']       : array())));
469
 
                $tag_data_id3v1['artist']  =        getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST']     ) ? $this->tag_data['ARTIST']      : array())));
470
 
                $tag_data_id3v1['album']   =        getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ALBUM']      ) ? $this->tag_data['ALBUM']       : array())));
471
 
                $tag_data_id3v1['year']    =        getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['YEAR']       ) ? $this->tag_data['YEAR']        : array())));
472
 
                $tag_data_id3v1['comment'] =        getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COMMENT']    ) ? $this->tag_data['COMMENT']     : array())));
473
 
                $tag_data_id3v1['track']   = intval(getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TRACKNUMBER']) ? $this->tag_data['TRACKNUMBER'] : array()))));
474
 
                if ($tag_data_id3v1['track'] <= 0) {
475
 
                        $tag_data_id3v1['track'] = '';
476
 
                }
477
 
 
478
 
                $this->MergeExistingTagData('id3v1', $tag_data_id3v1);
479
 
                return $tag_data_id3v1;
480
 
        }
481
 
 
482
 
        function FormatDataForID3v2($id3v2_majorversion) {
483
 
                $tag_data_id3v2 = array();
484
 
 
485
 
                $ID3v2_text_encoding_lookup[2] = array('ISO-8859-1'=>0, 'UTF-16'=>1);
486
 
                $ID3v2_text_encoding_lookup[3] = array('ISO-8859-1'=>0, 'UTF-16'=>1);
487
 
                $ID3v2_text_encoding_lookup[4] = array('ISO-8859-1'=>0, 'UTF-16'=>1, 'UTF-16BE'=>2, 'UTF-8'=>3);
488
 
                foreach ($this->tag_data as $tag_key => $valuearray) {
489
 
                        $ID3v2_framename = getid3_write_id3v2::ID3v2ShortFrameNameLookup($id3v2_majorversion, $tag_key);
490
 
                        switch ($ID3v2_framename) {
491
 
                                case 'APIC':
492
 
                                        foreach ($valuearray as $key => $apic_data_array) {
493
 
                                                if (isset($apic_data_array['data']) &&
494
 
                                                        isset($apic_data_array['picturetypeid']) &&
495
 
                                                        isset($apic_data_array['description']) &&
496
 
                                                        isset($apic_data_array['mime'])) {
497
 
                                                                $tag_data_id3v2['APIC'][] = $apic_data_array;
498
 
                                                } else {
499
 
                                                        $this->errors[] = 'ID3v2 APIC data is not properly structured';
500
 
                                                        return false;
501
 
                                                }
502
 
                                        }
503
 
                                        break;
504
 
 
505
 
                                case '':
506
 
                                        $this->errors[] = 'ID3v2: Skipping "'.$tag_key.'" because cannot match it to a known ID3v2 frame type';
507
 
                                        // some other data type, don't know how to handle it, ignore it
508
 
                                        break;
509
 
 
510
 
                                default:
511
 
                                        // most other (text) frames can be copied over as-is
512
 
                                        foreach ($valuearray as $key => $value) {
513
 
                                                if (isset($ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding])) {
514
 
                                                        // source encoding is valid in ID3v2 - use it with no conversion
515
 
                                                        $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = $ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding];
516
 
                                                        $tag_data_id3v2[$ID3v2_framename][$key]['data']       = $value;
517
 
                                                } else {
518
 
                                                        // source encoding is NOT valid in ID3v2 - convert it to an ID3v2-valid encoding first
519
 
                                                        if ($id3v2_majorversion < 4) {
520
 
                                                                // convert data from other encoding to UTF-16 (with BOM)
521
 
                                                                // note: some software, notably Windows Media Player and iTunes are broken and treat files tagged with UTF-16BE (with BOM) as corrupt
522
 
                                                                // therefore we force data to UTF-16LE and manually prepend the BOM
523
 
                                                                $ID3v2_tag_data_converted = false;
524
 
                                                                if (!$ID3v2_tag_data_converted && ($this->tag_encoding == 'ISO-8859-1')) {
525
 
                                                                        // great, leave data as-is for minimum compatability problems
526
 
                                                                        $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0;
527
 
                                                                        $tag_data_id3v2[$ID3v2_framename][$key]['data']       = $value;
528
 
                                                                        $ID3v2_tag_data_converted = true;
529
 
                                                                }
530
 
                                                                if (!$ID3v2_tag_data_converted && ($this->tag_encoding == 'UTF-8')) {
531
 
                                                                        do {
532
 
                                                                                // if UTF-8 string does not include any characters above chr(127) then it is identical to ISO-8859-1
533
 
                                                                                for ($i = 0; $i < strlen($value); $i++) {
534
 
                                                                                        if (ord($value{$i}) > 127) {
535
 
                                                                                                break 2;
536
 
                                                                                        }
537
 
                                                                                }
538
 
                                                                                $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0;
539
 
                                                                                $tag_data_id3v2[$ID3v2_framename][$key]['data']       = $value;
540
 
                                                                                $ID3v2_tag_data_converted = true;
541
 
                                                                        } while (false);
542
 
                                                                }
543
 
                                                                if (!$ID3v2_tag_data_converted) {
544
 
                                                                        $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 1;
545
 
                                                                        //$tag_data_id3v2[$ID3v2_framename][$key]['data']       = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16', $value); // output is UTF-16LE+BOM or UTF-16BE+BOM depending on system architecture
546
 
                                                                        $tag_data_id3v2[$ID3v2_framename][$key]['data']       = "\xFF\xFE".getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16LE', $value); // force LittleEndian order version of UTF-16
547
 
                                                                        $ID3v2_tag_data_converted = true;
548
 
                                                                }
549
 
 
550
 
                                                        } else {
551
 
                                                                // convert data from other encoding to UTF-8
552
 
                                                                $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 3;
553
 
                                                                $tag_data_id3v2[$ID3v2_framename][$key]['data']       = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value);
554
 
                                                        }
555
 
                                                }
556
 
 
557
 
                                                // These values are not needed for all frame types, but if they're not used no matter
558
 
                                                $tag_data_id3v2[$ID3v2_framename][$key]['description'] = '';
559
 
                                                $tag_data_id3v2[$ID3v2_framename][$key]['language']    = $this->id3v2_tag_language;
560
 
                                        }
561
 
                                        break;
562
 
                        }
563
 
                }
564
 
                $this->MergeExistingTagData('id3v2', $tag_data_id3v2);
565
 
                return $tag_data_id3v2;
566
 
        }
567
 
 
568
 
        function FormatDataForVorbisComment() {
569
 
                $tag_data_vorbiscomment = $this->tag_data;
570
 
 
571
 
                // check for multi-line comment values - split out to multiple comments if neccesary
572
 
                // and convert data to UTF-8 strings
573
 
                foreach ($tag_data_vorbiscomment as $tag_key => $valuearray) {
574
 
                        foreach ($valuearray as $key => $value) {
575
 
                                str_replace("\r", "\n", $value);
576
 
                                if (strstr($value, "\n")) {
577
 
                                        unset($tag_data_vorbiscomment[$tag_key][$key]);
578
 
                                        $multilineexploded = explode("\n", $value);
579
 
                                        foreach ($multilineexploded as $newcomment) {
580
 
                                                if (strlen(trim($newcomment)) > 0) {
581
 
                                                        $tag_data_vorbiscomment[$tag_key][] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $newcomment);
582
 
                                                }
583
 
                                        }
584
 
                                } elseif (is_string($value) || is_numeric($value)) {
585
 
                                        $tag_data_vorbiscomment[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value);
586
 
                                } else {
587
 
                                        $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to VorbisComment tag';
588
 
                                        unset($tag_data_vorbiscomment[$tag_key]);
589
 
                                        break;
590
 
                                }
591
 
                        }
592
 
                }
593
 
                $this->MergeExistingTagData('vorbiscomment', $tag_data_vorbiscomment);
594
 
                return $tag_data_vorbiscomment;
595
 
        }
596
 
 
597
 
        function FormatDataForMetaFLAC() {
598
 
                // FLAC & OggFLAC use VorbisComments same as OggVorbis
599
 
                // but require metaflac to do the writing rather than vorbiscomment
600
 
                return $this->FormatDataForVorbisComment();
601
 
        }
602
 
 
603
 
        function FormatDataForReal() {
604
 
                $tag_data_real['title']     = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE']    ) ? $this->tag_data['TITLE']     : array())));
605
 
                $tag_data_real['artist']    = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST']   ) ? $this->tag_data['ARTIST']    : array())));
606
 
                $tag_data_real['copyright'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COPYRIGHT']) ? $this->tag_data['COPYRIGHT'] : array())));
607
 
                $tag_data_real['comment']   = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COMMENT']  ) ? $this->tag_data['COMMENT']   : array())));
608
 
 
609
 
                $this->MergeExistingTagData('real', $tag_data_real);
610
 
                return $tag_data_real;
611
 
        }
612
 
 
613
 
}
614
 
 
615
 
?>
 
 
b'\\ No newline at end of file'