3 /////////////////////////////////////////////////////////////////
4 /// getID3() by James Heinrich <info@getid3.org> //
5 // available at https://github.com/JamesHeinrich/getID3 //
6 // or https://www.getid3.org //
7 // or http://getid3.sourceforge.net //
8 // see readme.txt for more details //
9 /////////////////////////////////////////////////////////////////
12 // module for writing ID3v2 tags //
13 // dependencies: module.tag.id3v2.php //
15 /////////////////////////////////////////////////////////////////
17 if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
20 getid3_lib
::IncludeDependency(GETID3_INCLUDEPATH
.'module.tag.id3v2.php', __FILE__
, true);
22 class getid3_write_id3v2
35 * Read buffer size in bytes.
39 public $fread_buffer_size = 32768;
42 * Minimum length of ID3v2 tag in bytes.
46 public $paddedlength = 4096;
49 * ID3v2 major version (2, 3 (recommended), 4).
53 public $majorversion = 3;
56 * ID3v2 minor version - always 0.
60 public $minorversion = 0;
63 * If true, merge new data with existing tags; if false, delete old tag data and only write new tags.
67 public $merge_existing_data = false;
70 * Default text encoding (ISO-8859-1) if not explicitly passed.
74 public $id3v2_default_encodingid = 0;
77 * The specs say it should be TRUE, but most other ID3v2-aware programs are broken if unsynchronization is used,
78 * so by default don't use it.
82 public $id3v2_use_unsynchronisation = false;
85 * Any non-critical errors will be stored here.
89 public $warnings = array();
92 * Any critical errors will be stored here.
96 public $errors = array();
98 public function __construct() {
104 public function WriteID3v2() {
105 // File MUST be writeable - CHMOD(646) at least. It's best if the
106 // directory is also writeable, because that method is both faster and less susceptible to errors.
108 if (!empty($this->filename
) && (getID3
::is_writable($this->filename
) ||
(!file_exists($this->filename
) && getID3
::is_writable(dirname($this->filename
))))) {
109 // Initialize getID3 engine
110 $getID3 = new getID3
;
111 $OldThisFileInfo = $getID3->analyze($this->filename
);
112 if (!getid3_lib
::intValueSupported($OldThisFileInfo['filesize'])) {
113 $this->errors
[] = 'Unable to write ID3v2 because file is larger than '.round(PHP_INT_MAX
/ 1073741824).'GB';
116 if ($this->merge_existing_data
) {
117 // merge with existing data
118 if (!empty($OldThisFileInfo['id3v2'])) {
119 $this->tag_data
= $this->array_join_merge($OldThisFileInfo['id3v2'], $this->tag_data
);
122 $this->paddedlength
= (isset($OldThisFileInfo['id3v2']['headerlength']) ?
max($OldThisFileInfo['id3v2']['headerlength'], $this->paddedlength
) : $this->paddedlength
);
124 if ($NewID3v2Tag = $this->GenerateID3v2Tag()) {
126 if (file_exists($this->filename
) && getID3
::is_writable($this->filename
) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) {
128 // best and fastest method - insert-overwrite existing tag (padded to length of old tag if neccesary)
129 if (file_exists($this->filename
)) {
131 if (is_readable($this->filename
) && getID3
::is_writable($this->filename
) && is_file($this->filename
) && ($fp = fopen($this->filename
, 'r+b'))) {
133 fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
136 $this->errors
[] = 'Could not fopen("'.$this->filename
.'", "r+b")';
141 if (getID3
::is_writable($this->filename
) && is_file($this->filename
) && ($fp = fopen($this->filename
, 'wb'))) {
143 fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
146 $this->errors
[] = 'Could not fopen("'.$this->filename
.'", "wb")';
153 if ($tempfilename = tempnam(GETID3_TEMP_DIR
, 'getID3')) {
154 if (is_readable($this->filename
) && is_file($this->filename
) && ($fp_source = fopen($this->filename
, 'rb'))) {
155 if (getID3
::is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) {
157 fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag));
160 if (!empty($OldThisFileInfo['avdataoffset'])) {
161 fseek($fp_source, $OldThisFileInfo['avdataoffset']);
164 while ($buffer = fread($fp_source, $this->fread_buffer_size
)) {
165 fwrite($fp_temp, $buffer, strlen($buffer));
170 copy($tempfilename, $this->filename
);
171 unlink($tempfilename);
175 $this->errors
[] = 'Could not fopen("'.$tempfilename.'", "wb")';
180 $this->errors
[] = 'Could not fopen("'.$this->filename
.'", "rb")';
189 $this->errors
[] = '$this->GenerateID3v2Tag() failed';
193 if (!empty($this->errors
)) {
198 $this->errors
[] = 'WriteID3v2() failed: !is_writeable('.$this->filename
.')';
206 public function RemoveID3v2() {
207 // File MUST be writeable - CHMOD(646) at least. It's best if the
208 // directory is also writeable, because that method is both faster and less susceptible to errors.
209 if (getID3
::is_writable(dirname($this->filename
))) {
211 // preferred method - only one copying operation, minimal chance of corrupting
212 // original file if script is interrupted, but required directory to be writeable
213 if (is_readable($this->filename
) && is_file($this->filename
) && ($fp_source = fopen($this->filename
, 'rb'))) {
215 // Initialize getID3 engine
216 $getID3 = new getID3
;
217 $OldThisFileInfo = $getID3->analyze($this->filename
);
218 if (!getid3_lib
::intValueSupported($OldThisFileInfo['filesize'])) {
219 $this->errors
[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX
/ 1073741824).'GB';
224 if ($OldThisFileInfo['avdataoffset'] !== false) {
225 fseek($fp_source, $OldThisFileInfo['avdataoffset']);
227 if (getID3
::is_writable($this->filename
) && is_file($this->filename
) && ($fp_temp = fopen($this->filename
.'getid3tmp', 'w+b'))) {
228 while ($buffer = fread($fp_source, $this->fread_buffer_size
)) {
229 fwrite($fp_temp, $buffer, strlen($buffer));
233 $this->errors
[] = 'Could not fopen("'.$this->filename
.'getid3tmp", "w+b")';
237 $this->errors
[] = 'Could not fopen("'.$this->filename
.'", "rb")';
239 if (file_exists($this->filename
)) {
240 unlink($this->filename
);
242 rename($this->filename
.'getid3tmp', $this->filename
);
244 } elseif (getID3
::is_writable($this->filename
)) {
246 // less desirable alternate method - double-copies the file, overwrites original file
247 // and could corrupt source file if the script is interrupted or an error occurs.
248 if (is_readable($this->filename
) && is_file($this->filename
) && ($fp_source = fopen($this->filename
, 'rb'))) {
250 // Initialize getID3 engine
251 $getID3 = new getID3
;
252 $OldThisFileInfo = $getID3->analyze($this->filename
);
253 if (!getid3_lib
::intValueSupported($OldThisFileInfo['filesize'])) {
254 $this->errors
[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX
/ 1073741824).'GB';
259 if ($OldThisFileInfo['avdataoffset'] !== false) {
260 fseek($fp_source, $OldThisFileInfo['avdataoffset']);
262 if ($fp_temp = tmpfile()) {
263 while ($buffer = fread($fp_source, $this->fread_buffer_size
)) {
264 fwrite($fp_temp, $buffer, strlen($buffer));
267 if (getID3
::is_writable($this->filename
) && is_file($this->filename
) && ($fp_source = fopen($this->filename
, 'wb'))) {
269 while ($buffer = fread($fp_temp, $this->fread_buffer_size
)) {
270 fwrite($fp_source, $buffer, strlen($buffer));
272 fseek($fp_temp, -128, SEEK_END
);
275 $this->errors
[] = 'Could not fopen("'.$this->filename
.'", "wb")';
279 $this->errors
[] = 'Could not create tmpfile()';
282 $this->errors
[] = 'Could not fopen("'.$this->filename
.'", "rb")';
287 $this->errors
[] = 'Directory and file both not writeable';
291 if (!empty($this->errors
)) {
298 * @param array $flags
300 * @return string|false
302 public function GenerateID3v2TagFlags($flags) {
304 switch ($this->majorversion
) {
307 $flag = (!empty($flags['unsynchronisation']) ?
'1' : '0'); // a - Unsynchronisation
308 $flag .= (!empty($flags['extendedheader'] ) ?
'1' : '0'); // b - Extended header
309 $flag .= (!empty($flags['experimental'] ) ?
'1' : '0'); // c - Experimental indicator
310 $flag .= (!empty($flags['footer'] ) ?
'1' : '0'); // d - Footer present
316 $flag = (!empty($flags['unsynchronisation']) ?
'1' : '0'); // a - Unsynchronisation
317 $flag .= (!empty($flags['extendedheader'] ) ?
'1' : '0'); // b - Extended header
318 $flag .= (!empty($flags['experimental'] ) ?
'1' : '0'); // c - Experimental indicator
324 $flag = (!empty($flags['unsynchronisation']) ?
'1' : '0'); // a - Unsynchronisation
325 $flag .= (!empty($flags['compression'] ) ?
'1' : '0'); // b - Compression
332 return chr(bindec($flag));
336 * @param bool $TagAlter
337 * @param bool $FileAlter
338 * @param bool $ReadOnly
339 * @param bool $Compression
340 * @param bool $Encryption
341 * @param bool $GroupingIdentity
342 * @param bool $Unsynchronisation
343 * @param bool $DataLengthIndicator
345 * @return string|false
347 public function GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false) {
350 switch ($this->majorversion
) {
352 // %0abc0000 %0h00kmnp
354 $flag1 .= $TagAlter ?
'1' : '0'; // a - Tag alter preservation (true == discard)
355 $flag1 .= $FileAlter ?
'1' : '0'; // b - File alter preservation (true == discard)
356 $flag1 .= $ReadOnly ?
'1' : '0'; // c - Read only (true == read only)
360 $flag2 .= $GroupingIdentity ?
'1' : '0'; // h - Grouping identity (true == contains group information)
362 $flag2 .= $Compression ?
'1' : '0'; // k - Compression (true == compressed)
363 $flag2 .= $Encryption ?
'1' : '0'; // m - Encryption (true == encrypted)
364 $flag2 .= $Unsynchronisation ?
'1' : '0'; // n - Unsynchronisation (true == unsynchronised)
365 $flag2 .= $DataLengthIndicator ?
'1' : '0'; // p - Data length indicator (true == data length indicator added)
369 // %abc00000 %ijk00000
370 $flag1 = $TagAlter ?
'1' : '0'; // a - Tag alter preservation (true == discard)
371 $flag1 .= $FileAlter ?
'1' : '0'; // b - File alter preservation (true == discard)
372 $flag1 .= $ReadOnly ?
'1' : '0'; // c - Read only (true == read only)
375 $flag2 = $Compression ?
'1' : '0'; // i - Compression (true == compressed)
376 $flag2 .= $Encryption ?
'1' : '0'; // j - Encryption (true == encrypted)
377 $flag2 .= $GroupingIdentity ?
'1' : '0'; // k - Grouping identity (true == contains group information)
385 return chr(bindec($flag1)).chr(bindec($flag2));
389 * @param string $frame_name
390 * @param array $source_data_array
392 * @return string|false
394 public function GenerateID3v2FrameData($frame_name, $source_data_array) {
395 if (!getid3_id3v2
::IsValidID3v2FrameName($frame_name, $this->majorversion
)) {
400 if (($this->majorversion
< 3) ||
($this->majorversion
> 4)) {
402 $this->errors
[] = 'Only ID3v2.3 and ID3v2.4 are supported in GenerateID3v2FrameData()';
404 } else { // $this->majorversion 3 or 4
406 switch ($frame_name) {
408 // 4.1 UFID Unique file identifier
409 // Owner identifier <text string> $00
410 // Identifier <up to 64 bytes binary data>
411 if (strlen($source_data_array['data']) > 64) {
412 $this->errors
[] = 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($source_data_array['data']).' bytes long)';
414 $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
415 $framedata .= substr($source_data_array['data'], 0, 64); // max 64 bytes - truncate anything longer
420 // 4.2.2 TXXX User defined text information frame
422 // Description <text string according to encoding> $00 (00)
423 // Value <text string according to encoding>
424 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
425 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
426 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
428 $framedata .= chr($source_data_array['encodingid']);
429 $framedata .= $source_data_array['description'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
430 $framedata .= $source_data_array['data'];
435 // 4.3.2 WXXX User defined URL link frame
437 // Description <text string according to encoding> $00 (00)
439 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
440 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
441 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
442 } elseif (!isset($source_data_array['data']) ||
!$this->IsValidURL($source_data_array['data'], false)) {
443 //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
444 // probably should be an error, need to rewrite IsValidURL() to handle other encodings
445 $this->warnings
[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
447 $framedata .= chr($source_data_array['encodingid']);
448 $framedata .= $source_data_array['description'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
449 $framedata .= $source_data_array['data'];
454 // 4.4 IPLS Involved people list (ID3v2.3 only)
456 // People list strings <textstrings>
457 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
458 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
459 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
461 $framedata .= chr($source_data_array['encodingid']);
462 $framedata .= $source_data_array['data'];
467 // 4.4 MCDI Music CD identifier
468 // CD TOC <binary data>
469 $framedata .= $source_data_array['data'];
473 // 4.5 ETCO Event timing codes
474 // Time stamp format $xx
475 // Where time stamp format is:
476 // $01 (32-bit value) MPEG frames from beginning of file
477 // $02 (32-bit value) milliseconds from beginning of file
478 // Followed by a list of key events in the following format:
480 // Time stamp $xx (xx ...)
481 // The 'Time stamp' is set to zero if directly at the beginning of the sound
482 // or after the previous event. All events MUST be sorted in chronological order.
483 if (($source_data_array['timestampformat'] > 2) ||
($source_data_array['timestampformat'] < 1)) {
484 $this->errors
[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
486 $framedata .= chr($source_data_array['timestampformat']);
487 foreach ($source_data_array as $key => $val) {
488 if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
489 $this->errors
[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
490 } elseif (($key != 'timestampformat') && ($key != 'flags')) {
491 if (($val['timestamp'] > 0) && isset($previousETCOtimestamp) && ($previousETCOtimestamp >= $val['timestamp'])) {
492 // The 'Time stamp' is set to zero if directly at the beginning of the sound
493 // or after the previous event. All events MUST be sorted in chronological order.
494 $this->errors
[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')';
496 $framedata .= chr($val['typeid']);
497 $framedata .= getid3_lib
::BigEndian2String($val['timestamp'], 4, false);
498 $previousETCOtimestamp = $val['timestamp'];
506 // 4.6 MLLT MPEG location lookup table
507 // MPEG frames between reference $xx xx
508 // Bytes between reference $xx xx xx
509 // Milliseconds between reference $xx xx xx
510 // Bits for bytes deviation $xx
511 // Bits for milliseconds dev. $xx
512 // Then for every reference the following data is included;
513 // Deviation in bytes %xxx....
514 // Deviation in milliseconds %xxx....
515 if (($source_data_array['framesbetweenreferences'] > 0) && ($source_data_array['framesbetweenreferences'] <= 65535)) {
516 $framedata .= getid3_lib
::BigEndian2String($source_data_array['framesbetweenreferences'], 2, false);
518 $this->errors
[] = 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$source_data_array['framesbetweenreferences'].')';
520 if (($source_data_array['bytesbetweenreferences'] > 0) && ($source_data_array['bytesbetweenreferences'] <= 16777215)) {
521 $framedata .= getid3_lib
::BigEndian2String($source_data_array['bytesbetweenreferences'], 3, false);
523 $this->errors
[] = 'Invalid bytes Between References in '.$frame_name.' ('.$source_data_array['bytesbetweenreferences'].')';
525 if (($source_data_array['msbetweenreferences'] > 0) && ($source_data_array['msbetweenreferences'] <= 16777215)) {
526 $framedata .= getid3_lib
::BigEndian2String($source_data_array['msbetweenreferences'], 3, false);
528 $this->errors
[] = 'Invalid Milliseconds Between References in '.$frame_name.' ('.$source_data_array['msbetweenreferences'].')';
530 if (!$this->IsWithinBitRange($source_data_array['bitsforbytesdeviation'], 8, false)) {
531 if (($source_data_array['bitsforbytesdeviation'] %
4) == 0) {
532 $framedata .= chr($source_data_array['bitsforbytesdeviation']);
534 $this->errors
[] = 'Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
537 $this->errors
[] = 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].')';
539 if (!$this->IsWithinBitRange($source_data_array['bitsformsdeviation'], 8, false)) {
540 if (($source_data_array['bitsformsdeviation'] %
4) == 0) {
541 $framedata .= chr($source_data_array['bitsformsdeviation']);
543 $this->errors
[] = 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
546 $this->errors
[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')';
548 $unwrittenbitstream = '';
549 foreach ($source_data_array as $key => $val) {
550 if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) {
551 $unwrittenbitstream .= str_pad(getid3_lib
::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT
);
552 $unwrittenbitstream .= str_pad(getid3_lib
::Dec2Bin($val['msdeviation']), $source_data_array['bitsformsdeviation'], '0', STR_PAD_LEFT
);
555 for ($i = 0; $i < strlen($unwrittenbitstream); $i +
= 8) {
556 $highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4;
557 $lownibble = bindec(substr($unwrittenbitstream, $i +
4, 4));
558 $framedata .= chr($highnibble & $lownibble);
563 // 4.7 SYTC Synchronised tempo codes
564 // Time stamp format $xx
565 // Tempo data <binary data>
566 // Where time stamp format is:
567 // $01 (32-bit value) MPEG frames from beginning of file
568 // $02 (32-bit value) milliseconds from beginning of file
569 if (($source_data_array['timestampformat'] > 2) ||
($source_data_array['timestampformat'] < 1)) {
570 $this->errors
[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
572 $framedata .= chr($source_data_array['timestampformat']);
573 foreach ($source_data_array as $key => $val) {
574 if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
575 $this->errors
[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
576 } elseif (($key != 'timestampformat') && ($key != 'flags')) {
577 if (($val['tempo'] < 0) ||
($val['tempo'] > 510)) {
578 $this->errors
[] = 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')';
580 if ($val['tempo'] > 255) {
581 $framedata .= chr(255);
582 $val['tempo'] -= 255;
584 $framedata .= chr($val['tempo']);
585 $framedata .= getid3_lib
::BigEndian2String($val['timestamp'], 4, false);
593 // 4.8 USLT Unsynchronised lyric/text transcription
595 // Language $xx xx xx
596 // Content descriptor <text string according to encoding> $00 (00)
597 // Lyrics/text <full text string according to encoding>
598 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
599 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
600 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
601 } elseif (getid3_id3v2
::LanguageLookup($source_data_array['language'], true) == '') {
602 $this->errors
[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
604 $framedata .= chr($source_data_array['encodingid']);
605 $framedata .= strtolower($source_data_array['language']);
606 $framedata .= $source_data_array['description'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
607 $framedata .= $source_data_array['data'];
612 // 4.9 SYLT Synchronised lyric/text
614 // Language $xx xx xx
615 // Time stamp format $xx
616 // $01 (32-bit value) MPEG frames from beginning of file
617 // $02 (32-bit value) milliseconds from beginning of file
619 // Content descriptor <text string according to encoding> $00 (00)
620 // Terminated text to be synced (typically a syllable)
621 // Sync identifier (terminator to above string) $00 (00)
622 // Time stamp $xx (xx ...)
623 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
624 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
625 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
626 } elseif (getid3_id3v2
::LanguageLookup($source_data_array['language'], true) == '') {
627 $this->errors
[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
628 } elseif (($source_data_array['timestampformat'] > 2) ||
($source_data_array['timestampformat'] < 1)) {
629 $this->errors
[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
630 } elseif (!$this->ID3v2IsValidSYLTtype($source_data_array['contenttypeid'])) {
631 $this->errors
[] = 'Invalid Content Type byte in '.$frame_name.' ('.$source_data_array['contenttypeid'].')';
632 } elseif (!is_array($source_data_array['data'])) {
633 $this->errors
[] = 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)';
635 $framedata .= chr($source_data_array['encodingid']);
636 $framedata .= strtolower($source_data_array['language']);
637 $framedata .= chr($source_data_array['timestampformat']);
638 $framedata .= chr($source_data_array['contenttypeid']);
639 $framedata .= $source_data_array['description'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
640 ksort($source_data_array['data']);
641 foreach ($source_data_array['data'] as $key => $val) {
642 $framedata .= $val['data'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
643 $framedata .= getid3_lib
::BigEndian2String($val['timestamp'], 4, false);
649 // 4.10 COMM Comments
651 // Language $xx xx xx
652 // Short content descrip. <text string according to encoding> $00 (00)
653 // The actual text <full text string according to encoding>
654 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
655 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
656 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
657 } elseif (getid3_id3v2
::LanguageLookup($source_data_array['language'], true) == '') {
658 $this->errors
[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
660 $framedata .= chr($source_data_array['encodingid']);
661 $framedata .= strtolower($source_data_array['language']);
662 $framedata .= $source_data_array['description'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
663 $framedata .= $source_data_array['data'];
668 // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only)
669 // Identification <text string> $00
670 // The 'identification' string is used to identify the situation and/or
671 // device where this adjustment should apply. The following is then
672 // repeated for every channel:
673 // Type of channel $xx
674 // Volume adjustment $xx xx
675 // Bits representing peak $xx
676 // Peak volume $xx (xx ...)
677 $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
678 foreach ($source_data_array as $key => $val) {
679 if ($key != 'description') {
680 $framedata .= chr($val['channeltypeid']);
681 $framedata .= getid3_lib
::BigEndian2String($val['volumeadjust'], 2, false, true); // signed 16-bit
682 if (!$this->IsWithinBitRange($source_data_array['bitspeakvolume'], 8, false)) {
683 $framedata .= chr($val['bitspeakvolume']);
684 if ($val['bitspeakvolume'] > 0) {
685 $framedata .= getid3_lib
::BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), false, false);
688 $this->errors
[] = 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)';
695 // 4.12 RVAD Relative volume adjustment (ID3v2.3 only)
696 // Increment/decrement %00fedcba
697 // Bits used for volume descr. $xx
698 // Relative volume change, right $xx xx (xx ...) // a
699 // Relative volume change, left $xx xx (xx ...) // b
700 // Peak volume right $xx xx (xx ...)
701 // Peak volume left $xx xx (xx ...)
702 // Relative volume change, right back $xx xx (xx ...) // c
703 // Relative volume change, left back $xx xx (xx ...) // d
704 // Peak volume right back $xx xx (xx ...)
705 // Peak volume left back $xx xx (xx ...)
706 // Relative volume change, center $xx xx (xx ...) // e
707 // Peak volume center $xx xx (xx ...)
708 // Relative volume change, bass $xx xx (xx ...) // f
709 // Peak volume bass $xx xx (xx ...)
710 if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
711 $this->errors
[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
714 $incdecflag .= $source_data_array['incdec']['right'] ?
'1' : '0'; // a - Relative volume change, right
715 $incdecflag .= $source_data_array['incdec']['left'] ?
'1' : '0'; // b - Relative volume change, left
716 $incdecflag .= $source_data_array['incdec']['rightrear'] ?
'1' : '0'; // c - Relative volume change, right back
717 $incdecflag .= $source_data_array['incdec']['leftrear'] ?
'1' : '0'; // d - Relative volume change, left back
718 $incdecflag .= $source_data_array['incdec']['center'] ?
'1' : '0'; // e - Relative volume change, center
719 $incdecflag .= $source_data_array['incdec']['bass'] ?
'1' : '0'; // f - Relative volume change, bass
720 $framedata .= chr(bindec($incdecflag));
721 $framedata .= chr($source_data_array['bitsvolume']);
722 $framedata .= getid3_lib
::BigEndian2String($source_data_array['volumechange']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
723 $framedata .= getid3_lib
::BigEndian2String($source_data_array['volumechange']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
724 $framedata .= getid3_lib
::BigEndian2String($source_data_array['peakvolume']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
725 $framedata .= getid3_lib
::BigEndian2String($source_data_array['peakvolume']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
726 if ($source_data_array['volumechange']['rightrear'] ||
$source_data_array['volumechange']['leftrear'] ||
727 $source_data_array['peakvolume']['rightrear'] ||
$source_data_array['peakvolume']['leftrear'] ||
728 $source_data_array['volumechange']['center'] ||
$source_data_array['peakvolume']['center'] ||
729 $source_data_array['volumechange']['bass'] ||
$source_data_array['peakvolume']['bass']) {
730 $framedata .= getid3_lib
::BigEndian2String($source_data_array['volumechange']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
731 $framedata .= getid3_lib
::BigEndian2String($source_data_array['volumechange']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
732 $framedata .= getid3_lib
::BigEndian2String($source_data_array['peakvolume']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
733 $framedata .= getid3_lib
::BigEndian2String($source_data_array['peakvolume']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
735 if ($source_data_array['volumechange']['center'] ||
$source_data_array['peakvolume']['center'] ||
736 $source_data_array['volumechange']['bass'] ||
$source_data_array['peakvolume']['bass']) {
737 $framedata .= getid3_lib
::BigEndian2String($source_data_array['volumechange']['center'], ceil($source_data_array['bitsvolume']/8), false);
738 $framedata .= getid3_lib
::BigEndian2String($source_data_array['peakvolume']['center'], ceil($source_data_array['bitsvolume']/8), false);
740 if ($source_data_array['volumechange']['bass'] ||
$source_data_array['peakvolume']['bass']) {
741 $framedata .= getid3_lib
::BigEndian2String($source_data_array['volumechange']['bass'], ceil($source_data_array['bitsvolume']/8), false);
742 $framedata .= getid3_lib
::BigEndian2String($source_data_array['peakvolume']['bass'], ceil($source_data_array['bitsvolume']/8), false);
748 // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only)
749 // Interpolation method $xx
752 // Identification <text string> $00
753 // The following is then repeated for every adjustment point
755 // Volume adjustment $xx xx
756 if (($source_data_array['interpolationmethod'] < 0) ||
($source_data_array['interpolationmethod'] > 1)) {
757 $this->errors
[] = 'Invalid Interpolation Method byte in '.$frame_name.' ('.$source_data_array['interpolationmethod'].') (valid = 0 or 1)';
759 $framedata .= chr($source_data_array['interpolationmethod']);
760 $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
761 foreach ($source_data_array['data'] as $key => $val) {
762 $framedata .= getid3_lib
::BigEndian2String(intval(round($key * 2)), 2, false);
763 $framedata .= getid3_lib
::BigEndian2String($val, 2, false, true); // signed 16-bit
769 // 4.12 EQUA Equalisation (ID3v2.3 only)
770 // Adjustment bits $xx
771 // This is followed by 2 bytes + ('adjustment bits' rounded up to the
772 // nearest byte) for every equalisation band in the following format,
773 // giving a frequency range of 0 - 32767Hz:
774 // Increment/decrement %x (MSB of the Frequency)
775 // Frequency (lower 15 bits)
776 // Adjustment $xx (xx ...)
777 if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
778 $this->errors
[] = 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
780 $framedata .= chr($source_data_array['adjustmentbits']);
781 foreach ($source_data_array as $key => $val) {
782 if ($key != 'bitsvolume') {
783 if (($key > 32767) ||
($key < 0)) {
784 $this->errors
[] = 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)';
787 // put MSB of frequency to 1 if increment, 0 if decrement
790 $framedata .= getid3_lib
::BigEndian2String($key, 2, false);
791 $framedata .= getid3_lib
::BigEndian2String($val, ceil($source_data_array['adjustmentbits'] / 8), false);
800 // Reverb left (ms) $xx xx
801 // Reverb right (ms) $xx xx
802 // Reverb bounces, left $xx
803 // Reverb bounces, right $xx
804 // Reverb feedback, left to left $xx
805 // Reverb feedback, left to right $xx
806 // Reverb feedback, right to right $xx
807 // Reverb feedback, right to left $xx
808 // Premix left to right $xx
809 // Premix right to left $xx
810 if (!$this->IsWithinBitRange($source_data_array['left'], 16, false)) {
811 $this->errors
[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['left'].') (range = 0 to 65535)';
812 } elseif (!$this->IsWithinBitRange($source_data_array['right'], 16, false)) {
813 $this->errors
[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['right'].') (range = 0 to 65535)';
814 } elseif (!$this->IsWithinBitRange($source_data_array['bouncesL'], 8, false)) {
815 $this->errors
[] = 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$source_data_array['bouncesL'].') (range = 0 to 255)';
816 } elseif (!$this->IsWithinBitRange($source_data_array['bouncesR'], 8, false)) {
817 $this->errors
[] = 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$source_data_array['bouncesR'].') (range = 0 to 255)';
818 } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLL'], 8, false)) {
819 $this->errors
[] = 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$source_data_array['feedbackLL'].') (range = 0 to 255)';
820 } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLR'], 8, false)) {
821 $this->errors
[] = 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$source_data_array['feedbackLR'].') (range = 0 to 255)';
822 } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRR'], 8, false)) {
823 $this->errors
[] = 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$source_data_array['feedbackRR'].') (range = 0 to 255)';
824 } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRL'], 8, false)) {
825 $this->errors
[] = 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$source_data_array['feedbackRL'].') (range = 0 to 255)';
826 } elseif (!$this->IsWithinBitRange($source_data_array['premixLR'], 8, false)) {
827 $this->errors
[] = 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$source_data_array['premixLR'].') (range = 0 to 255)';
828 } elseif (!$this->IsWithinBitRange($source_data_array['premixRL'], 8, false)) {
829 $this->errors
[] = 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$source_data_array['premixRL'].') (range = 0 to 255)';
831 $framedata .= getid3_lib
::BigEndian2String($source_data_array['left'], 2, false);
832 $framedata .= getid3_lib
::BigEndian2String($source_data_array['right'], 2, false);
833 $framedata .= chr($source_data_array['bouncesL']);
834 $framedata .= chr($source_data_array['bouncesR']);
835 $framedata .= chr($source_data_array['feedbackLL']);
836 $framedata .= chr($source_data_array['feedbackLR']);
837 $framedata .= chr($source_data_array['feedbackRR']);
838 $framedata .= chr($source_data_array['feedbackRL']);
839 $framedata .= chr($source_data_array['premixLR']);
840 $framedata .= chr($source_data_array['premixRL']);
845 // 4.14 APIC Attached picture
847 // MIME type <text string> $00
849 // Description <text string according to encoding> $00 (00)
850 // Picture data <binary data>
851 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
852 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
853 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
854 } elseif (!$this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) {
855 $this->errors
[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion
;
856 } elseif ((!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) {
857 $this->errors
[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion
;
858 } elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false))) {
859 //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
860 // probably should be an error, need to rewrite IsValidURL() to handle other encodings
861 $this->warnings
[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
863 $framedata .= chr($source_data_array['encodingid']);
864 $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
865 $framedata .= chr($source_data_array['picturetypeid']);
866 $framedata .= (!empty($source_data_array['description']) ?
$source_data_array['description'] : '').getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
867 $framedata .= $source_data_array['data'];
872 // 4.15 GEOB General encapsulated object
874 // MIME type <text string> $00
875 // Filename <text string according to encoding> $00 (00)
876 // Content description <text string according to encoding> $00 (00)
877 // Encapsulated object <binary data>
878 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
879 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
880 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
881 } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
882 $this->errors
[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
883 } elseif (!$source_data_array['description']) {
884 $this->errors
[] = 'Missing Description in '.$frame_name;
886 $framedata .= chr($source_data_array['encodingid']);
887 $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
888 $framedata .= $source_data_array['filename'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
889 $framedata .= $source_data_array['description'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
890 $framedata .= $source_data_array['data'];
895 // 4.16 PCNT Play counter
896 // When the counter reaches all one's, one byte is inserted in
897 // front of the counter thus making the counter eight bits bigger
898 // Counter $xx xx xx xx (xx ...)
899 $framedata .= getid3_lib
::BigEndian2String($source_data_array['data'], 4, false);
903 // 4.17 POPM Popularimeter
904 // When the counter reaches all one's, one byte is inserted in
905 // front of the counter thus making the counter eight bits bigger
906 // Email to user <text string> $00
908 // Counter $xx xx xx xx (xx ...)
909 if (!$this->IsValidEmail($source_data_array['email'])) {
910 // https://github.com/JamesHeinrich/getID3/issues/216
911 // https://en.wikipedia.org/wiki/ID3#ID3v2_rating_tag_issue
912 // ID3v2 specs say it should be an email address, but Windows instead uses string like "Windows Media Player 9 Series"
913 $this->warnings
[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')';
915 if (!$this->IsWithinBitRange($source_data_array['rating'], 8, false)) {
916 $this->errors
[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)';
918 $framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00";
919 $framedata .= chr($source_data_array['rating']);
920 $framedata .= getid3_lib
::BigEndian2String($source_data_array['data'], 4, false);
925 // 4.18 RBUF Recommended buffer size
926 // Buffer size $xx xx xx
927 // Embedded info flag %0000000x
928 // Offset to next tag $xx xx xx xx
929 if (!$this->IsWithinBitRange($source_data_array['buffersize'], 24, false)) {
930 $this->errors
[] = 'Invalid Buffer Size in '.$frame_name;
931 } elseif (!$this->IsWithinBitRange($source_data_array['nexttagoffset'], 32, false)) {
932 $this->errors
[] = 'Invalid Offset To Next Tag in '.$frame_name;
934 $framedata .= getid3_lib
::BigEndian2String($source_data_array['buffersize'], 3, false);
936 $flag .= $source_data_array['flags']['embededinfo'] ?
'1' : '0';
937 $framedata .= chr(bindec($flag));
938 $framedata .= getid3_lib
::BigEndian2String($source_data_array['nexttagoffset'], 4, false);
943 // 4.19 AENC Audio encryption
944 // Owner identifier <text string> $00
945 // Preview start $xx xx
946 // Preview length $xx xx
947 // Encryption info <binary data>
948 if (!$this->IsWithinBitRange($source_data_array['previewstart'], 16, false)) {
949 $this->errors
[] = 'Invalid Preview Start in '.$frame_name.' ('.$source_data_array['previewstart'].')';
950 } elseif (!$this->IsWithinBitRange($source_data_array['previewlength'], 16, false)) {
951 $this->errors
[] = 'Invalid Preview Length in '.$frame_name.' ('.$source_data_array['previewlength'].')';
953 $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
954 $framedata .= getid3_lib
::BigEndian2String($source_data_array['previewstart'], 2, false);
955 $framedata .= getid3_lib
::BigEndian2String($source_data_array['previewlength'], 2, false);
956 $framedata .= $source_data_array['encryptioninfo'];
961 // 4.20 LINK Linked information
962 // Frame identifier $xx xx xx xx
963 // URL <text string> $00
964 // ID and additional data <text string(s)>
965 if (!getid3_id3v2
::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion
)) {
966 $this->errors
[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')';
967 } elseif (!$this->IsValidURL($source_data_array['data'], true)) {
968 //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
969 // probably should be an error, need to rewrite IsValidURL() to handle other encodings
970 $this->warnings
[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
971 } elseif ((($source_data_array['frameid'] == 'AENC') ||
($source_data_array['frameid'] == 'APIC') ||
($source_data_array['frameid'] == 'GEOB') ||
($source_data_array['frameid'] == 'TXXX')) && ($source_data_array['additionaldata'] == '')) {
972 $this->errors
[] = 'Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
973 } elseif (($source_data_array['frameid'] == 'USER') && (getid3_id3v2
::LanguageLookup($source_data_array['additionaldata'], true) == '')) {
974 $this->errors
[] = 'Language must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
975 } elseif (($source_data_array['frameid'] == 'PRIV') && ($source_data_array['additionaldata'] == '')) {
976 $this->errors
[] = 'Owner Identifier must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
977 } elseif ((($source_data_array['frameid'] == 'COMM') ||
($source_data_array['frameid'] == 'SYLT') ||
($source_data_array['frameid'] == 'USLT')) && ((getid3_id3v2
::LanguageLookup(substr($source_data_array['additionaldata'], 0, 3), true) == '') ||
(substr($source_data_array['additionaldata'], 3) == ''))) {
978 $this->errors
[] = 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
980 $framedata .= $source_data_array['frameid'];
981 $framedata .= str_replace("\x00", '', $source_data_array['data'])."\x00";
982 switch ($source_data_array['frameid']) {
992 $framedata .= $source_data_array['additionaldata'];
1006 // no additional data required
1009 if ($this->majorversion
== 3) {
1010 // no additional data required
1012 $this->errors
[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion
.')';
1017 if ((substr($source_data_array['frameid'], 0, 1) == 'T') ||
(substr($source_data_array['frameid'], 0, 1) == 'W')) {
1018 // no additional data required
1020 $this->errors
[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion
.')';
1028 // 4.21 POSS Position synchronisation frame (ID3v2.3+ only)
1029 // Time stamp format $xx
1030 // Position $xx (xx ...)
1031 if (($source_data_array['timestampformat'] < 1) ||
($source_data_array['timestampformat'] > 2)) {
1032 $this->errors
[] = 'Invalid Time Stamp Format in '.$frame_name.' ('.$source_data_array['timestampformat'].') (valid = 1 or 2)';
1033 } elseif (!$this->IsWithinBitRange($source_data_array['position'], 32, false)) {
1034 $this->errors
[] = 'Invalid Position in '.$frame_name.' ('.$source_data_array['position'].') (range = 0 to 4294967295)';
1036 $framedata .= chr($source_data_array['timestampformat']);
1037 $framedata .= getid3_lib
::BigEndian2String($source_data_array['position'], 4, false);
1042 // 4.22 USER Terms of use (ID3v2.3+ only)
1043 // Text encoding $xx
1044 // Language $xx xx xx
1045 // The actual text <text string according to encoding>
1046 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
1047 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
1048 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
1049 } elseif (getid3_id3v2
::LanguageLookup($source_data_array['language'], true) == '') {
1050 $this->errors
[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
1052 $framedata .= chr($source_data_array['encodingid']);
1053 $framedata .= strtolower($source_data_array['language']);
1054 $framedata .= $source_data_array['data'];
1059 // 4.23 OWNE Ownership frame (ID3v2.3+ only)
1060 // Text encoding $xx
1061 // Price paid <text string> $00
1062 // Date of purch. <text string>
1063 // Seller <text string according to encoding>
1064 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
1065 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
1066 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
1067 } elseif (!getid3_id3v2
::IsANumber($source_data_array['pricepaid']['value'], false)) {
1068 $this->errors
[] = 'Invalid Price Paid in '.$frame_name.' ('.$source_data_array['pricepaid']['value'].')';
1069 } elseif (!getid3_id3v2
::IsValidDateStampString($source_data_array['purchasedate'])) {
1070 $this->errors
[] = 'Invalid Date Of Purchase in '.$frame_name.' ('.$source_data_array['purchasedate'].') (format = YYYYMMDD)';
1072 $framedata .= chr($source_data_array['encodingid']);
1073 $framedata .= str_replace("\x00", '', $source_data_array['pricepaid']['value'])."\x00";
1074 $framedata .= $source_data_array['purchasedate'];
1075 $framedata .= $source_data_array['seller'];
1080 // 4.24 COMR Commercial frame (ID3v2.3+ only)
1081 // Text encoding $xx
1082 // Price string <text string> $00
1083 // Valid until <text string>
1084 // Contact URL <text string> $00
1086 // Name of seller <text string according to encoding> $00 (00)
1087 // Description <text string according to encoding> $00 (00)
1088 // Picture MIME type <string> $00
1089 // Seller logo <binary data>
1090 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
1091 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
1092 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
1093 } elseif (!getid3_id3v2
::IsValidDateStampString($source_data_array['pricevaliduntil'])) {
1094 $this->errors
[] = 'Invalid Valid Until date in '.$frame_name.' ('.$source_data_array['pricevaliduntil'].') (format = YYYYMMDD)';
1095 } elseif (!$this->IsValidURL($source_data_array['contacturl'], false)) {
1096 $this->errors
[] = 'Invalid Contact URL in '.$frame_name.' ('.$source_data_array['contacturl'].') (allowed schemes: http, https, ftp, mailto)';
1097 } elseif (!$this->ID3v2IsValidCOMRreceivedAs($source_data_array['receivedasid'])) {
1098 $this->errors
[] = 'Invalid Received As byte in '.$frame_name.' ('.$source_data_array['contacturl'].') (range = 0 to 8)';
1099 } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
1100 $this->errors
[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
1102 $framedata .= chr($source_data_array['encodingid']);
1103 $pricestrings = array();
1104 foreach ($source_data_array['price'] as $key => $val) {
1105 if ($this->ID3v2IsValidPriceString($key.$val['value'])) {
1106 $pricestrings[] = $key.$val['value'];
1108 $this->errors
[] = 'Invalid Price String in '.$frame_name.' ('.$key.$val['value'].')';
1111 $framedata .= implode('/', $pricestrings);
1112 $framedata .= $source_data_array['pricevaliduntil'];
1113 $framedata .= str_replace("\x00", '', $source_data_array['contacturl'])."\x00";
1114 $framedata .= chr($source_data_array['receivedasid']);
1115 $framedata .= $source_data_array['sellername'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
1116 $framedata .= $source_data_array['description'].getid3_id3v2
::TextEncodingTerminatorLookup($source_data_array['encodingid']);
1117 $framedata .= $source_data_array['mime']."\x00";
1118 $framedata .= $source_data_array['logo'];
1123 // 4.25 ENCR Encryption method registration (ID3v2.3+ only)
1124 // Owner identifier <text string> $00
1125 // Method symbol $xx
1126 // Encryption data <binary data>
1127 if (!$this->IsWithinBitRange($source_data_array['methodsymbol'], 8, false)) {
1128 $this->errors
[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['methodsymbol'].') (range = 0 to 255)';
1130 $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
1131 $framedata .= ord($source_data_array['methodsymbol']);
1132 $framedata .= $source_data_array['data'];
1137 // 4.26 GRID Group identification registration (ID3v2.3+ only)
1138 // Owner identifier <text string> $00
1140 // Group dependent data <binary data>
1141 if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) {
1142 $this->errors
[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)';
1144 $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
1145 $framedata .= ord($source_data_array['groupsymbol']);
1146 $framedata .= $source_data_array['data'];
1151 // 4.27 PRIV Private frame (ID3v2.3+ only)
1152 // Owner identifier <text string> $00
1153 // The private data <binary data>
1154 $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
1155 $framedata .= $source_data_array['data'];
1159 // 4.28 SIGN Signature frame (ID3v2.4+ only)
1161 // Signature <binary data>
1162 if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) {
1163 $this->errors
[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)';
1165 $framedata .= ord($source_data_array['groupsymbol']);
1166 $framedata .= $source_data_array['data'];
1171 // 4.29 SEEK Seek frame (ID3v2.4+ only)
1172 // Minimum offset to next tag $xx xx xx xx
1173 if (!$this->IsWithinBitRange($source_data_array['data'], 32, false)) {
1174 $this->errors
[] = 'Invalid Minimum Offset in '.$frame_name.' ('.$source_data_array['data'].') (range = 0 to 4294967295)';
1176 $framedata .= getid3_lib
::BigEndian2String($source_data_array['data'], 4, false);
1181 // 4.30 ASPI Audio seek point index (ID3v2.4+ only)
1182 // Indexed data start (S) $xx xx xx xx
1183 // Indexed data length (L) $xx xx xx xx
1184 // Number of index points (N) $xx xx
1185 // Bits per index point (b) $xx
1186 // Then for every index point the following data is included:
1187 // Fraction at index (Fi) $xx (xx)
1188 if (!$this->IsWithinBitRange($source_data_array['datastart'], 32, false)) {
1189 $this->errors
[] = 'Invalid Indexed Data Start in '.$frame_name.' ('.$source_data_array['datastart'].') (range = 0 to 4294967295)';
1190 } elseif (!$this->IsWithinBitRange($source_data_array['datalength'], 32, false)) {
1191 $this->errors
[] = 'Invalid Indexed Data Length in '.$frame_name.' ('.$source_data_array['datalength'].') (range = 0 to 4294967295)';
1192 } elseif (!$this->IsWithinBitRange($source_data_array['indexpoints'], 16, false)) {
1193 $this->errors
[] = 'Invalid Number Of Index Points in '.$frame_name.' ('.$source_data_array['indexpoints'].') (range = 0 to 65535)';
1194 } elseif (!$this->IsWithinBitRange($source_data_array['bitsperpoint'], 8, false)) {
1195 $this->errors
[] = 'Invalid Bits Per Index Point in '.$frame_name.' ('.$source_data_array['bitsperpoint'].') (range = 0 to 255)';
1196 } elseif ($source_data_array['indexpoints'] != count($source_data_array['indexes'])) {
1197 $this->errors
[] = 'Number Of Index Points does not match actual supplied data in '.$frame_name;
1199 $framedata .= getid3_lib
::BigEndian2String($source_data_array['datastart'], 4, false);
1200 $framedata .= getid3_lib
::BigEndian2String($source_data_array['datalength'], 4, false);
1201 $framedata .= getid3_lib
::BigEndian2String($source_data_array['indexpoints'], 2, false);
1202 $framedata .= getid3_lib
::BigEndian2String($source_data_array['bitsperpoint'], 1, false);
1203 foreach ($source_data_array['indexes'] as $key => $val) {
1204 $framedata .= getid3_lib
::BigEndian2String($val, ceil($source_data_array['bitsperpoint'] / 8), false);
1210 // RGAD Replay Gain Adjustment
1211 // http://privatewww.essex.ac.uk/~djmrob/replaygain/
1212 // Peak Amplitude $xx $xx $xx $xx
1213 // Radio Replay Gain Adjustment %aaabbbcd %dddddddd
1214 // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd
1216 // b - originator code
1218 // d - replay gain adjustment
1220 if (($source_data_array['track_adjustment'] > 51) ||
($source_data_array['track_adjustment'] < -51)) {
1221 $this->errors
[] = 'Invalid Track Adjustment in '.$frame_name.' ('.$source_data_array['track_adjustment'].') (range = -51.0 to +51.0)';
1222 } elseif (($source_data_array['album_adjustment'] > 51) ||
($source_data_array['album_adjustment'] < -51)) {
1223 $this->errors
[] = 'Invalid Album Adjustment in '.$frame_name.' ('.$source_data_array['album_adjustment'].') (range = -51.0 to +51.0)';
1224 } elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['track_name'])) {
1225 $this->errors
[] = 'Invalid Track Name Code in '.$frame_name.' ('.$source_data_array['raw']['track_name'].') (range = 0 to 2)';
1226 } elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['album_name'])) {
1227 $this->errors
[] = 'Invalid Album Name Code in '.$frame_name.' ('.$source_data_array['raw']['album_name'].') (range = 0 to 2)';
1228 } elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['track_originator'])) {
1229 $this->errors
[] = 'Invalid Track Originator Code in '.$frame_name.' ('.$source_data_array['raw']['track_originator'].') (range = 0 to 3)';
1230 } elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['album_originator'])) {
1231 $this->errors
[] = 'Invalid Album Originator Code in '.$frame_name.' ('.$source_data_array['raw']['album_originator'].') (range = 0 to 3)';
1233 $framedata .= getid3_lib
::Float2String($source_data_array['peakamplitude'], 32);
1234 $framedata .= getid3_lib
::RGADgainString($source_data_array['raw']['track_name'], $source_data_array['raw']['track_originator'], $source_data_array['track_adjustment']);
1235 $framedata .= getid3_lib
::RGADgainString($source_data_array['raw']['album_name'], $source_data_array['raw']['album_originator'], $source_data_array['album_adjustment']);
1240 if (/*(($this->majorversion == 2) && (strlen($frame_name) != 3)) || (($this->majorversion > 2) && (*/strlen($frame_name) != 4/*))*/) {
1241 $this->errors
[] = 'Invalid frame name "'.$frame_name.'" for ID3v2.'.$this->majorversion
;
1242 } elseif ($frame_name[0] == 'T') {
1243 // 4.2. T??? Text information frames
1244 // Text encoding $xx
1245 // Information <text string(s) according to encoding>
1246 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ?
$source_data_array['encodingid'] : $this->id3v2_default_encodingid
);
1247 if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
1248 $this->errors
[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion
;
1250 $framedata .= chr($source_data_array['encodingid']);
1251 $framedata .= $source_data_array['data'];
1253 } elseif ($frame_name[0] == 'W') {
1254 // 4.3. W??? URL link frames
1255 // URL <text string>
1256 if (!$this->IsValidURL($source_data_array['data'], false)) {
1257 //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
1258 // probably should be an error, need to rewrite IsValidURL() to handle other encodings
1259 $this->warnings
[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
1261 $framedata .= $source_data_array['data'];
1264 $this->errors
[] = $frame_name.' not yet supported in $this->GenerateID3v2FrameData()';
1269 if (!empty($this->errors
)) {
1276 * @param string|null $frame_name
1277 * @param array $source_data_array
1281 public function ID3v2FrameIsAllowed($frame_name, $source_data_array) {
1282 static $PreviousFrames = array();
1284 if ($frame_name === null) {
1285 // if the writing functions are called multiple times, the static array needs to be
1286 // cleared - this can be done by calling $this->ID3v2FrameIsAllowed(null, '')
1287 $PreviousFrames = array();
1290 if ($this->majorversion
== 4) {
1291 switch ($frame_name) {
1296 if (!isset($source_data_array['ownerid'])) {
1297 $this->errors
[] = '[ownerid] not specified for '.$frame_name;
1298 } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
1299 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
1301 $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
1311 if (!isset($source_data_array['description'])) {
1312 $this->errors
[] = '[description] not specified for '.$frame_name;
1313 } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
1314 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
1316 $PreviousFrames[] = $frame_name.$source_data_array['description'];
1321 if (!isset($source_data_array['language'])) {
1322 $this->errors
[] = '[language] not specified for '.$frame_name;
1323 } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) {
1324 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')';
1326 $PreviousFrames[] = $frame_name.$source_data_array['language'];
1333 if (!isset($source_data_array['language'])) {
1334 $this->errors
[] = '[language] not specified for '.$frame_name;
1335 } elseif (!isset($source_data_array['description'])) {
1336 $this->errors
[] = '[description] not specified for '.$frame_name;
1337 } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
1338 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
1340 $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
1345 if (!isset($source_data_array['email'])) {
1346 $this->errors
[] = '[email] not specified for '.$frame_name;
1347 } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
1348 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
1350 $PreviousFrames[] = $frame_name.$source_data_array['email'];
1367 if (in_array($frame_name, $PreviousFrames)) {
1368 $this->errors
[] = 'Only one '.$frame_name.' tag allowed';
1370 $PreviousFrames[] = $frame_name;
1375 // this isn't implemented quite right (yet) - it should check the target frame data for compliance
1376 // but right now it just allows one linked frame of each type, to be safe.
1377 if (!isset($source_data_array['frameid'])) {
1378 $this->errors
[] = '[frameid] not specified for '.$frame_name;
1379 } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
1380 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
1381 } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
1382 // no links to singleton tags
1383 $this->errors
[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
1385 $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
1386 $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
1391 // There may be more than one 'commercial frame' in a tag, but no two may be identical
1392 // Checking isn't implemented at all (yet) - just assumes that it's OK.
1397 if (!isset($source_data_array['ownerid'])) {
1398 $this->errors
[] = '[ownerid] not specified for '.$frame_name;
1399 } elseif (!isset($source_data_array['data'])) {
1400 $this->errors
[] = '[data] not specified for '.$frame_name;
1401 } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) {
1402 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')';
1404 $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data'];
1409 if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) {
1410 $this->errors
[] = 'Frame not allowed in ID3v2.'.$this->majorversion
.': '.$frame_name;
1415 } elseif ($this->majorversion
== 3) {
1417 switch ($frame_name) {
1422 if (!isset($source_data_array['ownerid'])) {
1423 $this->errors
[] = '[ownerid] not specified for '.$frame_name;
1424 } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
1425 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
1427 $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
1435 if (!isset($source_data_array['description'])) {
1436 $this->errors
[] = '[description] not specified for '.$frame_name;
1437 } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
1438 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
1440 $PreviousFrames[] = $frame_name.$source_data_array['description'];
1445 if (!isset($source_data_array['language'])) {
1446 $this->errors
[] = '[language] not specified for '.$frame_name;
1447 } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) {
1448 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')';
1450 $PreviousFrames[] = $frame_name.$source_data_array['language'];
1457 if (!isset($source_data_array['language'])) {
1458 $this->errors
[] = '[language] not specified for '.$frame_name;
1459 } elseif (!isset($source_data_array['description'])) {
1460 $this->errors
[] = '[description] not specified for '.$frame_name;
1461 } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
1462 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
1464 $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
1469 if (!isset($source_data_array['email'])) {
1470 $this->errors
[] = '[email] not specified for '.$frame_name;
1471 } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
1472 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
1474 $PreviousFrames[] = $frame_name.$source_data_array['email'];
1491 if (in_array($frame_name, $PreviousFrames)) {
1492 $this->errors
[] = 'Only one '.$frame_name.' tag allowed';
1494 $PreviousFrames[] = $frame_name;
1499 // this isn't implemented quite right (yet) - it should check the target frame data for compliance
1500 // but right now it just allows one linked frame of each type, to be safe.
1501 if (!isset($source_data_array['frameid'])) {
1502 $this->errors
[] = '[frameid] not specified for '.$frame_name;
1503 } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
1504 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
1505 } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
1506 // no links to singleton tags
1507 $this->errors
[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
1509 $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
1510 $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
1515 // There may be more than one 'commercial frame' in a tag, but no two may be identical
1516 // Checking isn't implemented at all (yet) - just assumes that it's OK.
1520 if (!isset($source_data_array['ownerid'])) {
1521 $this->errors
[] = '[ownerid] not specified for '.$frame_name;
1522 } elseif (!isset($source_data_array['data'])) {
1523 $this->errors
[] = '[data] not specified for '.$frame_name;
1524 } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) {
1525 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')';
1527 $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data'];
1532 if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) {
1533 $this->errors
[] = 'Frame not allowed in ID3v2.'.$this->majorversion
.': '.$frame_name;
1538 } elseif ($this->majorversion
== 2) {
1540 switch ($frame_name) {
1544 if (!isset($source_data_array['ownerid'])) {
1545 $this->errors
[] = '[ownerid] not specified for '.$frame_name;
1546 } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
1547 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
1549 $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
1557 if (!isset($source_data_array['description'])) {
1558 $this->errors
[] = '[description] not specified for '.$frame_name;
1559 } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
1560 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
1562 $PreviousFrames[] = $frame_name.$source_data_array['description'];
1569 if (!isset($source_data_array['language'])) {
1570 $this->errors
[] = '[language] not specified for '.$frame_name;
1571 } elseif (!isset($source_data_array['description'])) {
1572 $this->errors
[] = '[description] not specified for '.$frame_name;
1573 } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
1574 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
1576 $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
1581 if (!isset($source_data_array['email'])) {
1582 $this->errors
[] = '[email] not specified for '.$frame_name;
1583 } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
1584 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
1586 $PreviousFrames[] = $frame_name.$source_data_array['email'];
1600 if (in_array($frame_name, $PreviousFrames)) {
1601 $this->errors
[] = 'Only one '.$frame_name.' tag allowed';
1603 $PreviousFrames[] = $frame_name;
1608 // this isn't implemented quite right (yet) - it should check the target frame data for compliance
1609 // but right now it just allows one linked frame of each type, to be safe.
1610 if (!isset($source_data_array['frameid'])) {
1611 $this->errors
[] = '[frameid] not specified for '.$frame_name;
1612 } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
1613 $this->errors
[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
1614 } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
1615 // no links to singleton tags
1616 $this->errors
[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
1618 $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
1619 $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
1624 if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) {
1625 $this->errors
[] = 'Frame not allowed in ID3v2.'.$this->majorversion
.': '.$frame_name;
1631 if (!empty($this->errors
)) {
1638 * @param bool $noerrorsonly
1640 * @return string|false
1642 public function GenerateID3v2Tag($noerrorsonly=true) {
1643 $this->ID3v2FrameIsAllowed(null, ''); // clear static array in case this isn't the first call to $this->GenerateID3v2Tag()
1646 if (is_array($this->tag_data
)) {
1647 foreach ($this->tag_data
as $frame_name => $frame_rawinputdata) {
1648 foreach ($frame_rawinputdata as $irrelevantindex => $source_data_array) {
1649 if (getid3_id3v2
::IsValidID3v2FrameName($frame_name, $this->majorversion
)) {
1650 unset($frame_length);
1651 unset($frame_flags);
1652 $frame_data = false;
1653 if ($this->ID3v2FrameIsAllowed($frame_name, $source_data_array)) {
1654 if(array_key_exists('description', $source_data_array) && array_key_exists('encodingid', $source_data_array) && array_key_exists('encoding', $this->tag_data
)) {
1655 $source_data_array['description'] = getid3_lib
::iconv_fallback($this->tag_data
['encoding'], $source_data_array['encoding'], $source_data_array['description']);
1657 if ($frame_data = $this->GenerateID3v2FrameData($frame_name, $source_data_array)) {
1658 $FrameUnsynchronisation = false;
1659 if ($this->majorversion
>= 4) {
1660 // frame-level unsynchronisation
1661 $unsynchdata = $frame_data;
1662 if ($this->id3v2_use_unsynchronisation
) {
1663 $unsynchdata = $this->Unsynchronise($frame_data);
1665 if (strlen($unsynchdata) != strlen($frame_data)) {
1666 // unsynchronisation needed
1667 $FrameUnsynchronisation = true;
1668 $frame_data = $unsynchdata;
1669 if (isset($TagUnsynchronisation) && $TagUnsynchronisation === false) {
1670 // only set to true if ALL frames are unsynchronised
1672 $TagUnsynchronisation = true;
1675 if (isset($TagUnsynchronisation)) {
1676 $TagUnsynchronisation = false;
1679 unset($unsynchdata);
1681 $frame_length = getid3_lib
::BigEndian2String(strlen($frame_data), 4, true);
1683 $frame_length = getid3_lib
::BigEndian2String(strlen($frame_data), 4, false);
1685 $frame_flags = $this->GenerateID3v2FrameFlags($this->ID3v2FrameFlagsLookupTagAlter($frame_name), $this->ID3v2FrameFlagsLookupFileAlter($frame_name), false, false, false, false, $FrameUnsynchronisation, false);
1688 $this->errors
[] = 'Frame "'.$frame_name.'" is NOT allowed';
1690 if ($frame_data === false) {
1691 $this->errors
[] = '$this->GenerateID3v2FrameData() failed for "'.$frame_name.'"';
1692 if ($noerrorsonly) {
1699 // ignore any invalid frame names, including 'title', 'header', etc
1700 $this->warnings
[] = 'Ignoring invalid ID3v2 frame type: "'.$frame_name.'"';
1702 unset($frame_length);
1703 unset($frame_flags);
1706 if (null !== $frame_name && isset($frame_length) && isset($frame_flags) && isset($frame_data)) {
1707 $tagstring .= $frame_name.$frame_length.$frame_flags.$frame_data;
1712 if (!isset($TagUnsynchronisation)) {
1713 $TagUnsynchronisation = false;
1715 if (($this->majorversion
<= 3) && $this->id3v2_use_unsynchronisation
) {
1716 // tag-level unsynchronisation
1717 $unsynchdata = $this->Unsynchronise($tagstring);
1718 if (strlen($unsynchdata) != strlen($tagstring)) {
1719 // unsynchronisation needed
1720 $TagUnsynchronisation = true;
1721 $tagstring = $unsynchdata;
1725 while ($this->paddedlength
< (strlen($tagstring) + getid3_id3v2
::ID3v2HeaderLength($this->majorversion
))) {
1726 $this->paddedlength +
= 1024;
1729 $footer = false; // ID3v2 footers not yet supported in getID3()
1730 if (/*!$footer && */($this->paddedlength
> (strlen($tagstring) + getid3_id3v2
::ID3v2HeaderLength($this->majorversion
)))) {
1731 // pad up to $paddedlength bytes if unpadded tag is shorter than $paddedlength
1732 // "Furthermore it MUST NOT have any padding when a tag footer is added to the tag."
1733 if (($this->paddedlength
- strlen($tagstring) - getid3_id3v2
::ID3v2HeaderLength($this->majorversion
)) > 0) {
1734 $tagstring .= str_repeat("\x00", $this->paddedlength
- strlen($tagstring) - getid3_id3v2
::ID3v2HeaderLength($this->majorversion
));
1737 if ($this->id3v2_use_unsynchronisation
&& (substr($tagstring, strlen($tagstring) - 1, 1) == "\xFF")) {
1738 // special unsynchronisation case:
1739 // if last byte == $FF then appended a $00
1740 $TagUnsynchronisation = true;
1741 $tagstring .= "\x00";
1745 $tagheader .= chr($this->majorversion
);
1746 $tagheader .= chr($this->minorversion
);
1747 $tagheader .= $this->GenerateID3v2TagFlags(array('unsynchronisation'=>$TagUnsynchronisation));
1748 $tagheader .= getid3_lib
::BigEndian2String(strlen($tagstring), 4, true);
1750 return $tagheader.$tagstring;
1752 $this->errors
[] = 'tag_data is not an array in GenerateID3v2Tag()';
1757 * @param string $pricestring
1761 public function ID3v2IsValidPriceString($pricestring) {
1762 if (getid3_id3v2
::LanguageLookup(substr($pricestring, 0, 3), true) == '') {
1764 } elseif (!getid3_id3v2
::IsANumber(substr($pricestring, 3), true)) {
1771 * @param string $framename
1775 public function ID3v2FrameFlagsLookupTagAlter($framename) {
1777 switch ($framename) {
1789 * @param string $framename
1793 public function ID3v2FrameFlagsLookupFileAlter($framename) {
1795 switch ($framename) {
1805 * @param int $eventid
1809 public function ID3v2IsValidETCOevent($eventid) {
1810 if (($eventid < 0) ||
($eventid > 0xFF)) {
1811 // outside range of 1 byte
1813 } elseif (($eventid >= 0xF0) && ($eventid <= 0xFC)) {
1814 // reserved for future use
1816 } elseif (($eventid >= 0x17) && ($eventid <= 0xDF)) {
1817 // reserved for future use
1819 } elseif (($eventid >= 0x0E) && ($eventid <= 0x16) && ($this->majorversion
== 2)) {
1820 // not defined in ID3v2.2
1822 } elseif (($eventid >= 0x15) && ($eventid <= 0x16) && ($this->majorversion
== 3)) {
1823 // not defined in ID3v2.3
1830 * @param int $contenttype
1834 public function ID3v2IsValidSYLTtype($contenttype) {
1835 if (($contenttype >= 0) && ($contenttype <= 8) && ($this->majorversion
== 4)) {
1837 } elseif (($contenttype >= 0) && ($contenttype <= 6) && ($this->majorversion
== 3)) {
1844 * @param int $channeltype
1848 public function ID3v2IsValidRVA2channeltype($channeltype) {
1849 if (($channeltype >= 0) && ($channeltype <= 8) && ($this->majorversion
== 4)) {
1856 * @param int $picturetype
1860 public function ID3v2IsValidAPICpicturetype($picturetype) {
1861 if (($picturetype >= 0) && ($picturetype <= 0x14) && ($this->majorversion
>= 2) && ($this->majorversion
<= 4)) {
1868 * @param int|string $imageformat
1872 public function ID3v2IsValidAPICimageformat($imageformat) {
1873 if ($imageformat == '-->') {
1875 } elseif ($this->majorversion
== 2) {
1876 if ((strlen($imageformat) == 3) && ($imageformat == strtoupper($imageformat))) {
1879 } elseif (($this->majorversion
== 3) ||
($this->majorversion
== 4)) {
1880 if ($this->IsValidMIMEstring($imageformat)) {
1888 * @param int $receivedas
1892 public function ID3v2IsValidCOMRreceivedAs($receivedas) {
1893 if (($this->majorversion
>= 3) && ($receivedas >= 0) && ($receivedas <= 8)) {
1900 * @param int $RGADname
1904 public static function ID3v2IsValidRGADname($RGADname) {
1905 if (($RGADname >= 0) && ($RGADname <= 2)) {
1912 * @param int $RGADoriginator
1916 public static function ID3v2IsValidRGADoriginator($RGADoriginator) {
1917 if (($RGADoriginator >= 0) && ($RGADoriginator <= 3)) {
1924 * @param int $textencodingbyte
1928 public function ID3v2IsValidTextEncoding($textencodingbyte) {
1930 // 1 = UTF-16 with BOM
1931 // 2 = UTF-16BE without BOM
1933 static $ID3v2IsValidTextEncoding_cache = array(
1934 2 => array(true, true), // ID3v2.2 - allow 0=ISO-8859-1, 1=UTF-16
1935 3 => array(true, true), // ID3v2.3 - allow 0=ISO-8859-1, 1=UTF-16
1936 4 => array(true, true, true, true), // ID3v2.4 - allow 0=ISO-8859-1, 1=UTF-16, 2=UTF-16BE, 3=UTF-8
1938 return isset($ID3v2IsValidTextEncoding_cache[$this->majorversion
][$textencodingbyte]);
1942 * @param string $data
1946 public static function Unsynchronise($data) {
1947 // Whenever a false synchronisation is found within the tag, one zeroed
1948 // byte is inserted after the first false synchronisation byte. The
1949 // format of a correct sync that should be altered by ID3 encoders is as
1951 // %11111111 111xxxxx
1952 // And should be replaced with:
1953 // %11111111 00000000 111xxxxx
1954 // This has the side effect that all $FF 00 combinations have to be
1955 // altered, so they won't be affected by the decoding process. Therefore
1956 // all the $FF 00 combinations have to be replaced with the $FF 00 00
1957 // combination during the unsynchronisation.
1959 $data = str_replace("\xFF\x00", "\xFF\x00\x00", $data);
1960 $unsyncheddata = '';
1961 $datalength = strlen($data);
1962 for ($i = 0; $i < $datalength; $i++
) {
1963 $thischar = $data[$i];
1964 $unsyncheddata .= $thischar;
1965 if ($thischar == "\xFF") {
1966 $nextchar = ord($data[$i +
1]);
1967 if (($nextchar & 0xE0) == 0xE0) {
1968 // previous byte = 11111111, this byte = 111?????
1969 $unsyncheddata .= "\x00";
1973 return $unsyncheddata;
1981 public function is_hash($var) {
1982 // written by dev-nullØchristophe*vg
1983 // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
1984 if (is_array($var)) {
1985 $keys = array_keys($var);
1987 for ($i = 0; $i < count($keys); $i++
) {
1988 if (is_string($keys[$i])) {
1997 * @param mixed $arr1
1998 * @param mixed $arr2
2002 public function array_join_merge($arr1, $arr2) {
2003 // written by dev-nullØchristophe*vg
2004 // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
2005 if (is_array($arr1) && is_array($arr2)) {
2006 // the same -> merge
2007 $new_array = array();
2009 if ($this->is_hash($arr1) && $this->is_hash($arr2)) {
2010 // hashes -> merge based on keys
2011 $keys = array_merge(array_keys($arr1), array_keys($arr2));
2012 foreach ($keys as $key) {
2013 $new_array[$key] = $this->array_join_merge((isset($arr1[$key]) ?
$arr1[$key] : ''), (isset($arr2[$key]) ?
$arr2[$key] : ''));
2016 // two real arrays -> merge
2017 $new_array = array_reverse(array_unique(array_reverse(array_merge($arr1, $arr2))));
2021 // not the same ... take new one if defined, else the old one stays
2022 return $arr2 ?
$arr2 : $arr1;
2027 * @param string $mimestring
2031 public static function IsValidMIMEstring($mimestring) {
2032 return preg_match('#^.+/.+$#', $mimestring);
2036 * @param int $number
2037 * @param int $maxbits
2038 * @param bool $signed
2042 public static function IsWithinBitRange($number, $maxbits, $signed=false) {
2044 if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) {
2048 if (($number >= 0) && ($number <= pow(2, $maxbits))) {
2056 * @param string $email
2058 * @return false|int|mixed
2060 public static function IsValidEmail($email) {
2061 if (function_exists('filter_var')) {
2062 return filter_var($email, FILTER_VALIDATE_EMAIL
);
2064 // VERY crude email validation
2065 return preg_match('#^[^ ]+@[a-z\\-\\.]+\\.[a-z]{2,}$#', $email);
2069 * @param string $url
2070 * @param bool $allowUserPass
2074 public static function IsValidURL($url, $allowUserPass=false) {
2078 if ($allowUserPass !== true) {
2079 if (strstr($url, '@')) {
2080 // in the format http://user:pass@example.com or http://user@example.com
2081 // but could easily be somebody incorrectly entering an email address in place of a URL
2085 // 2016-06-08: relax URL checking to avoid falsely rejecting valid URLs, leave URL validation to the user
2086 // https://www.getid3.org/phpBB3/viewtopic.php?t=1926
2089 if ($parts = $this->safe_parse_url($url)) {
2090 if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) {
2092 } elseif (!preg_match('#^[[:alnum:]]([-.]?[0-9a-z])*\\.[a-z]{2,3}$#i', $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\\.[0-9]{1,3}){3}$#', $parts['host'])) {
2094 } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['user'], $regs)) {
2096 } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['pass'], $regs)) {
2098 } elseif (!preg_match('#^[[:alnum:]/_\\.@~-]*$#i', $parts['path'], $regs)) {
2100 } elseif (!empty($parts['query']) && !preg_match('#^[[:alnum:]?&=+:;_()%\\#/,\\.-]*$#i', $parts['query'], $regs)) {
2111 * @param string $url
2115 public static function safe_parse_url($url) {
2116 $parts = @parse_url
($url);
2117 $parts['scheme'] = (isset($parts['scheme']) ?
$parts['scheme'] : '');
2118 $parts['host'] = (isset($parts['host']) ?
$parts['host'] : '');
2119 $parts['user'] = (isset($parts['user']) ?
$parts['user'] : '');
2120 $parts['pass'] = (isset($parts['pass']) ?
$parts['pass'] : '');
2121 $parts['path'] = (isset($parts['path']) ?
$parts['path'] : '');
2122 $parts['query'] = (isset($parts['query']) ?
$parts['query'] : '');
2127 * @param int $majorversion
2128 * @param string $long_description
2132 public static function ID3v2ShortFrameNameLookup($majorversion, $long_description) {
2133 $long_description = str_replace(' ', '_', strtolower(trim($long_description)));
2134 static $ID3v2ShortFrameNameLookup = array();
2135 if (empty($ID3v2ShortFrameNameLookup)) {
2137 // The following are unique to ID3v2.2
2138 $ID3v2ShortFrameNameLookup[2]['recommended_buffer_size'] = 'BUF';
2139 $ID3v2ShortFrameNameLookup[2]['comment'] = 'COM';
2140 $ID3v2ShortFrameNameLookup[2]['audio_encryption'] = 'CRA';
2141 $ID3v2ShortFrameNameLookup[2]['encrypted_meta_frame'] = 'CRM';
2142 $ID3v2ShortFrameNameLookup[2]['equalisation'] = 'EQU';
2143 $ID3v2ShortFrameNameLookup[2]['event_timing_codes'] = 'ETC';
2144 $ID3v2ShortFrameNameLookup[2]['general_encapsulated_object'] = 'GEO';
2145 $ID3v2ShortFrameNameLookup[2]['involved_people_list'] = 'IPL';
2146 $ID3v2ShortFrameNameLookup[2]['linked_information'] = 'LNK';
2147 $ID3v2ShortFrameNameLookup[2]['music_cd_identifier'] = 'MCI';
2148 $ID3v2ShortFrameNameLookup[2]['mpeg_location_lookup_table'] = 'MLL';
2149 $ID3v2ShortFrameNameLookup[2]['attached_picture'] = 'PIC';
2150 $ID3v2ShortFrameNameLookup[2]['popularimeter'] = 'POP';
2151 $ID3v2ShortFrameNameLookup[2]['reverb'] = 'REV';
2152 $ID3v2ShortFrameNameLookup[2]['relative_volume_adjustment'] = 'RVA';
2153 $ID3v2ShortFrameNameLookup[2]['synchronised_lyric'] = 'SLT';
2154 $ID3v2ShortFrameNameLookup[2]['synchronised_tempo_codes'] = 'STC';
2155 $ID3v2ShortFrameNameLookup[2]['album'] = 'TAL';
2156 $ID3v2ShortFrameNameLookup[2]['beats_per_minute'] = 'TBP';
2157 $ID3v2ShortFrameNameLookup[2]['bpm'] = 'TBP';
2158 $ID3v2ShortFrameNameLookup[2]['composer'] = 'TCM';
2159 $ID3v2ShortFrameNameLookup[2]['genre'] = 'TCO';
2160 $ID3v2ShortFrameNameLookup[2]['part_of_a_compilation'] = 'TCP';
2161 $ID3v2ShortFrameNameLookup[2]['copyright_message'] = 'TCR';
2162 $ID3v2ShortFrameNameLookup[2]['date'] = 'TDA';
2163 $ID3v2ShortFrameNameLookup[2]['playlist_delay'] = 'TDY';
2164 $ID3v2ShortFrameNameLookup[2]['encoded_by'] = 'TEN';
2165 $ID3v2ShortFrameNameLookup[2]['file_type'] = 'TFT';
2166 $ID3v2ShortFrameNameLookup[2]['time'] = 'TIM';
2167 $ID3v2ShortFrameNameLookup[2]['initial_key'] = 'TKE';
2168 $ID3v2ShortFrameNameLookup[2]['language'] = 'TLA';
2169 $ID3v2ShortFrameNameLookup[2]['length'] = 'TLE';
2170 $ID3v2ShortFrameNameLookup[2]['media_type'] = 'TMT';
2171 $ID3v2ShortFrameNameLookup[2]['original_artist'] = 'TOA';
2172 $ID3v2ShortFrameNameLookup[2]['original_filename'] = 'TOF';
2173 $ID3v2ShortFrameNameLookup[2]['original_lyricist'] = 'TOL';
2174 $ID3v2ShortFrameNameLookup[2]['original_year'] = 'TOR';
2175 $ID3v2ShortFrameNameLookup[2]['original_album'] = 'TOT';
2176 $ID3v2ShortFrameNameLookup[2]['artist'] = 'TP1';
2177 $ID3v2ShortFrameNameLookup[2]['band'] = 'TP2';
2178 $ID3v2ShortFrameNameLookup[2]['conductor'] = 'TP3';
2179 $ID3v2ShortFrameNameLookup[2]['remixer'] = 'TP4';
2180 $ID3v2ShortFrameNameLookup[2]['part_of_a_set'] = 'TPA';
2181 $ID3v2ShortFrameNameLookup[2]['publisher'] = 'TPB';
2182 $ID3v2ShortFrameNameLookup[2]['isrc'] = 'TRC';
2183 $ID3v2ShortFrameNameLookup[2]['recording_dates'] = 'TRD';
2184 $ID3v2ShortFrameNameLookup[2]['tracknumber'] = 'TRK';
2185 $ID3v2ShortFrameNameLookup[2]['track_number'] = 'TRK';
2186 $ID3v2ShortFrameNameLookup[2]['album_artist_sort_order'] = 'TS2';
2187 $ID3v2ShortFrameNameLookup[2]['album_sort_order'] = 'TSA';
2188 $ID3v2ShortFrameNameLookup[2]['composer_sort_order'] = 'TSC';
2189 $ID3v2ShortFrameNameLookup[2]['size'] = 'TSI';
2190 $ID3v2ShortFrameNameLookup[2]['performer_sort_order'] = 'TSP';
2191 $ID3v2ShortFrameNameLookup[2]['encoder_settings'] = 'TSS';
2192 $ID3v2ShortFrameNameLookup[2]['title_sort_order'] = 'TST';
2193 $ID3v2ShortFrameNameLookup[2]['content_group_description'] = 'TT1';
2194 $ID3v2ShortFrameNameLookup[2]['title'] = 'TT2';
2195 $ID3v2ShortFrameNameLookup[2]['subtitle'] = 'TT3';
2196 $ID3v2ShortFrameNameLookup[2]['lyricist'] = 'TXT';
2197 $ID3v2ShortFrameNameLookup[2]['text'] = 'TXX';
2198 $ID3v2ShortFrameNameLookup[2]['year'] = 'TYE';
2199 $ID3v2ShortFrameNameLookup[2]['unique_file_identifier'] = 'UFI';
2200 $ID3v2ShortFrameNameLookup[2]['unsynchronised_lyric'] = 'ULT';
2201 $ID3v2ShortFrameNameLookup[2]['url_file'] = 'WAF';
2202 $ID3v2ShortFrameNameLookup[2]['url_artist'] = 'WAR';
2203 $ID3v2ShortFrameNameLookup[2]['url_source'] = 'WAS';
2204 $ID3v2ShortFrameNameLookup[2]['commercial_information'] = 'WCM';
2205 $ID3v2ShortFrameNameLookup[2]['copyright'] = 'WCP';
2206 $ID3v2ShortFrameNameLookup[2]['url_publisher'] = 'WPB';
2207 $ID3v2ShortFrameNameLookup[2]['url_user'] = 'WXX';
2209 // The following are common to ID3v2.3 and ID3v2.4
2210 $ID3v2ShortFrameNameLookup[3]['audio_encryption'] = 'AENC';
2211 $ID3v2ShortFrameNameLookup[3]['attached_picture'] = 'APIC';
2212 $ID3v2ShortFrameNameLookup[3]['picture'] = 'APIC';
2213 $ID3v2ShortFrameNameLookup[3]['comment'] = 'COMM';
2214 $ID3v2ShortFrameNameLookup[3]['commercial_frame'] = 'COMR';
2215 $ID3v2ShortFrameNameLookup[3]['encryption_method_registration'] = 'ENCR';
2216 $ID3v2ShortFrameNameLookup[3]['event_timing_codes'] = 'ETCO';
2217 $ID3v2ShortFrameNameLookup[3]['general_encapsulated_object'] = 'GEOB';
2218 $ID3v2ShortFrameNameLookup[3]['group_identification_registration'] = 'GRID';
2219 $ID3v2ShortFrameNameLookup[3]['linked_information'] = 'LINK';
2220 $ID3v2ShortFrameNameLookup[3]['music_cd_identifier'] = 'MCDI';
2221 $ID3v2ShortFrameNameLookup[3]['mpeg_location_lookup_table'] = 'MLLT';
2222 $ID3v2ShortFrameNameLookup[3]['ownership_frame'] = 'OWNE';
2223 $ID3v2ShortFrameNameLookup[3]['play_counter'] = 'PCNT';
2224 $ID3v2ShortFrameNameLookup[3]['popularimeter'] = 'POPM';
2225 $ID3v2ShortFrameNameLookup[3]['position_synchronisation_frame'] = 'POSS';
2226 $ID3v2ShortFrameNameLookup[3]['private_frame'] = 'PRIV';
2227 $ID3v2ShortFrameNameLookup[3]['recommended_buffer_size'] = 'RBUF';
2228 $ID3v2ShortFrameNameLookup[3]['replay_gain_adjustment'] = 'RGAD';
2229 $ID3v2ShortFrameNameLookup[3]['reverb'] = 'RVRB';
2230 $ID3v2ShortFrameNameLookup[3]['synchronised_lyric'] = 'SYLT';
2231 $ID3v2ShortFrameNameLookup[3]['synchronised_tempo_codes'] = 'SYTC';
2232 $ID3v2ShortFrameNameLookup[3]['album'] = 'TALB';
2233 $ID3v2ShortFrameNameLookup[3]['beats_per_minute'] = 'TBPM';
2234 $ID3v2ShortFrameNameLookup[3]['bpm'] = 'TBPM';
2235 $ID3v2ShortFrameNameLookup[3]['part_of_a_compilation'] = 'TCMP';
2236 $ID3v2ShortFrameNameLookup[3]['composer'] = 'TCOM';
2237 $ID3v2ShortFrameNameLookup[3]['genre'] = 'TCON';
2238 $ID3v2ShortFrameNameLookup[3]['copyright_message'] = 'TCOP';
2239 $ID3v2ShortFrameNameLookup[3]['playlist_delay'] = 'TDLY';
2240 $ID3v2ShortFrameNameLookup[3]['encoded_by'] = 'TENC';
2241 $ID3v2ShortFrameNameLookup[3]['lyricist'] = 'TEXT';
2242 $ID3v2ShortFrameNameLookup[3]['file_type'] = 'TFLT';
2243 $ID3v2ShortFrameNameLookup[3]['content_group_description'] = 'TIT1';
2244 $ID3v2ShortFrameNameLookup[3]['title'] = 'TIT2';
2245 $ID3v2ShortFrameNameLookup[3]['subtitle'] = 'TIT3';
2246 $ID3v2ShortFrameNameLookup[3]['initial_key'] = 'TKEY';
2247 $ID3v2ShortFrameNameLookup[3]['language'] = 'TLAN';
2248 $ID3v2ShortFrameNameLookup[3]['length'] = 'TLEN';
2249 $ID3v2ShortFrameNameLookup[3]['media_type'] = 'TMED';
2250 $ID3v2ShortFrameNameLookup[3]['original_album'] = 'TOAL';
2251 $ID3v2ShortFrameNameLookup[3]['original_filename'] = 'TOFN';
2252 $ID3v2ShortFrameNameLookup[3]['original_lyricist'] = 'TOLY';
2253 $ID3v2ShortFrameNameLookup[3]['original_artist'] = 'TOPE';
2254 $ID3v2ShortFrameNameLookup[3]['file_owner'] = 'TOWN';
2255 $ID3v2ShortFrameNameLookup[3]['artist'] = 'TPE1';
2256 $ID3v2ShortFrameNameLookup[3]['band'] = 'TPE2';
2257 $ID3v2ShortFrameNameLookup[3]['conductor'] = 'TPE3';
2258 $ID3v2ShortFrameNameLookup[3]['remixer'] = 'TPE4';
2259 $ID3v2ShortFrameNameLookup[3]['part_of_a_set'] = 'TPOS';
2260 $ID3v2ShortFrameNameLookup[3]['publisher'] = 'TPUB';
2261 $ID3v2ShortFrameNameLookup[3]['tracknumber'] = 'TRCK';
2262 $ID3v2ShortFrameNameLookup[3]['track_number'] = 'TRCK';
2263 $ID3v2ShortFrameNameLookup[3]['internet_radio_station_name'] = 'TRSN';
2264 $ID3v2ShortFrameNameLookup[3]['internet_radio_station_owner'] = 'TRSO';
2265 $ID3v2ShortFrameNameLookup[3]['album_artist_sort_order'] = 'TSO2';
2266 $ID3v2ShortFrameNameLookup[3]['album_sort_order'] = 'TSOA';
2267 $ID3v2ShortFrameNameLookup[3]['composer_sort_order'] = 'TSOC';
2268 $ID3v2ShortFrameNameLookup[3]['performer_sort_order'] = 'TSOP';
2269 $ID3v2ShortFrameNameLookup[3]['title_sort_order'] = 'TSOT';
2270 $ID3v2ShortFrameNameLookup[3]['isrc'] = 'TSRC';
2271 $ID3v2ShortFrameNameLookup[3]['encoder_settings'] = 'TSSE';
2272 $ID3v2ShortFrameNameLookup[3]['text'] = 'TXXX';
2273 $ID3v2ShortFrameNameLookup[3]['unique_file_identifier'] = 'UFID';
2274 $ID3v2ShortFrameNameLookup[3]['terms_of_use'] = 'USER';
2275 $ID3v2ShortFrameNameLookup[3]['unsynchronised_lyric'] = 'USLT';
2276 $ID3v2ShortFrameNameLookup[3]['commercial_information'] = 'WCOM';
2277 $ID3v2ShortFrameNameLookup[3]['copyright'] = 'WCOP';
2278 $ID3v2ShortFrameNameLookup[3]['url_file'] = 'WOAF';
2279 $ID3v2ShortFrameNameLookup[3]['url_artist'] = 'WOAR';
2280 $ID3v2ShortFrameNameLookup[3]['url_source'] = 'WOAS';
2281 $ID3v2ShortFrameNameLookup[3]['url_station'] = 'WORS';
2282 $ID3v2ShortFrameNameLookup[3]['url_payment'] = 'WPAY';
2283 $ID3v2ShortFrameNameLookup[3]['url_publisher'] = 'WPUB';
2284 $ID3v2ShortFrameNameLookup[3]['url_user'] = 'WXXX';
2286 // The above are common to ID3v2.3 and ID3v2.4
2287 // so copy them to ID3v2.4 before adding specifics for 2.3 and 2.4
2288 $ID3v2ShortFrameNameLookup[4] = $ID3v2ShortFrameNameLookup[3];
2290 // The following are unique to ID3v2.3
2291 $ID3v2ShortFrameNameLookup[3]['equalisation'] = 'EQUA';
2292 $ID3v2ShortFrameNameLookup[3]['involved_people_list'] = 'IPLS';
2293 $ID3v2ShortFrameNameLookup[3]['relative_volume_adjustment'] = 'RVAD';
2294 $ID3v2ShortFrameNameLookup[3]['date'] = 'TDAT';
2295 $ID3v2ShortFrameNameLookup[3]['time'] = 'TIME';
2296 $ID3v2ShortFrameNameLookup[3]['original_year'] = 'TORY';
2297 $ID3v2ShortFrameNameLookup[3]['recording_dates'] = 'TRDA';
2298 $ID3v2ShortFrameNameLookup[3]['size'] = 'TSIZ';
2299 $ID3v2ShortFrameNameLookup[3]['year'] = 'TYER';
2302 // The following are unique to ID3v2.4
2303 $ID3v2ShortFrameNameLookup[4]['audio_seek_point_index'] = 'ASPI';
2304 $ID3v2ShortFrameNameLookup[4]['equalisation'] = 'EQU2';
2305 $ID3v2ShortFrameNameLookup[4]['relative_volume_adjustment'] = 'RVA2';
2306 $ID3v2ShortFrameNameLookup[4]['seek_frame'] = 'SEEK';
2307 $ID3v2ShortFrameNameLookup[4]['signature_frame'] = 'SIGN';
2308 $ID3v2ShortFrameNameLookup[4]['encoding_time'] = 'TDEN';
2309 $ID3v2ShortFrameNameLookup[4]['original_release_time'] = 'TDOR';
2310 $ID3v2ShortFrameNameLookup[4]['recording_time'] = 'TDRC';
2311 $ID3v2ShortFrameNameLookup[4]['release_time'] = 'TDRL';
2312 $ID3v2ShortFrameNameLookup[4]['tagging_time'] = 'TDTG';
2313 $ID3v2ShortFrameNameLookup[4]['involved_people_list'] = 'TIPL';
2314 $ID3v2ShortFrameNameLookup[4]['musician_credits_list'] = 'TMCL';
2315 $ID3v2ShortFrameNameLookup[4]['mood'] = 'TMOO';
2316 $ID3v2ShortFrameNameLookup[4]['produced_notice'] = 'TPRO';
2317 $ID3v2ShortFrameNameLookup[4]['album_sort_order'] = 'TSOA';
2318 $ID3v2ShortFrameNameLookup[4]['performer_sort_order'] = 'TSOP';
2319 $ID3v2ShortFrameNameLookup[4]['title_sort_order'] = 'TSOT';
2320 $ID3v2ShortFrameNameLookup[4]['set_subtitle'] = 'TSST';
2321 $ID3v2ShortFrameNameLookup[4]['year'] = 'TDRC'; // subset of ISO 8601: valid timestamps are yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddTHH, yyyy-MM-ddTHH:mm and yyyy-MM-ddTHH:mm:ss. All time stamps are UTC
2323 return (isset($ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)]) ?
$ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)] : '');