| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 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 ///////////////////////////////////////////////////////////////// 10 /// // 11 // module.tag.id3v2.php // 12 // module for analyzing ID3v2 tags // 13 // dependencies: module.tag.id3v1.php // 14 // /// 15 ///////////////////////////////////////////////////////////////// 16 17 if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers 18 exit; 19 } 20 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); 21 22 class getid3_id3v2 extends getid3_handler 23 { 24 public $StartingOffset = 0; 25 26 /** 27 * @return bool 28 */ 29 public function Analyze() { 30 $info = &$this->getid3->info; 31 32 // Overall tag structure: 33 // +-----------------------------+ 34 // | Header (10 bytes) | 35 // +-----------------------------+ 36 // | Extended Header | 37 // | (variable length, OPTIONAL) | 38 // +-----------------------------+ 39 // | Frames (variable length) | 40 // +-----------------------------+ 41 // | Padding | 42 // | (variable length, OPTIONAL) | 43 // +-----------------------------+ 44 // | Footer (10 bytes, OPTIONAL) | 45 // +-----------------------------+ 46 47 // Header 48 // ID3v2/file identifier "ID3" 49 // ID3v2 version $04 00 50 // ID3v2 flags (%ab000000 in v2.2, %abc00000 in v2.3, %abcd0000 in v2.4.x) 51 // ID3v2 size 4 * %0xxxxxxx 52 53 54 // shortcuts 55 $info['id3v2']['header'] = true; 56 $thisfile_id3v2 = &$info['id3v2']; 57 $thisfile_id3v2['flags'] = array(); 58 $thisfile_id3v2_flags = &$thisfile_id3v2['flags']; 59 60 61 $this->fseek($this->StartingOffset); 62 $header = $this->fread(10); 63 if (substr($header, 0, 3) == 'ID3' && strlen($header) == 10) { 64 65 $thisfile_id3v2['majorversion'] = ord($header[3]); 66 $thisfile_id3v2['minorversion'] = ord($header[4]); 67 68 // shortcut 69 $id3v2_majorversion = &$thisfile_id3v2['majorversion']; 70 71 } else { 72 73 unset($info['id3v2']); 74 return false; 75 76 } 77 78 if ($id3v2_majorversion > 4) { // this script probably won't correctly parse ID3v2.5.x and above (if it ever exists) 79 80 $this->error('this script only parses up to ID3v2.4.x - this tag is ID3v2.'.$id3v2_majorversion.'.'.$thisfile_id3v2['minorversion']); 81 return false; 82 83 } 84 85 $id3_flags = ord($header[5]); 86 switch ($id3v2_majorversion) { 87 case 2: 88 // %ab000000 in v2.2 89 $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation 90 $thisfile_id3v2_flags['compression'] = (bool) ($id3_flags & 0x40); // b - Compression 91 break; 92 93 case 3: 94 // %abc00000 in v2.3 95 $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation 96 $thisfile_id3v2_flags['exthead'] = (bool) ($id3_flags & 0x40); // b - Extended header 97 $thisfile_id3v2_flags['experim'] = (bool) ($id3_flags & 0x20); // c - Experimental indicator 98 break; 99 100 case 4: 101 // %abcd0000 in v2.4 102 $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation 103 $thisfile_id3v2_flags['exthead'] = (bool) ($id3_flags & 0x40); // b - Extended header 104 $thisfile_id3v2_flags['experim'] = (bool) ($id3_flags & 0x20); // c - Experimental indicator 105 $thisfile_id3v2_flags['isfooter'] = (bool) ($id3_flags & 0x10); // d - Footer present 106 break; 107 } 108 109 $thisfile_id3v2['headerlength'] = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length 110 111 $thisfile_id3v2['tag_offset_start'] = $this->StartingOffset; 112 $thisfile_id3v2['tag_offset_end'] = $thisfile_id3v2['tag_offset_start'] + $thisfile_id3v2['headerlength']; 113 114 115 116 // create 'encoding' key - used by getid3::HandleAllTags() 117 // in ID3v2 every field can have it's own encoding type 118 // so force everything to UTF-8 so it can be handled consistantly 119 $thisfile_id3v2['encoding'] = 'UTF-8'; 120 121 122 // Frames 123 124 // All ID3v2 frames consists of one frame header followed by one or more 125 // fields containing the actual information. The header is always 10 126 // bytes and laid out as follows: 127 // 128 // Frame ID $xx xx xx xx (four characters) 129 // Size 4 * %0xxxxxxx 130 // Flags $xx xx 131 132 $sizeofframes = $thisfile_id3v2['headerlength'] - 10; // not including 10-byte initial header 133 if (!empty($thisfile_id3v2['exthead']['length'])) { 134 $sizeofframes -= ($thisfile_id3v2['exthead']['length'] + 4); 135 } 136 if (!empty($thisfile_id3v2_flags['isfooter'])) { 137 $sizeofframes -= 10; // footer takes last 10 bytes of ID3v2 header, after frame data, before audio 138 } 139 $sizeofframes = min($sizeofframes, $this->getid3->info['filesize'] - $this->ftell()); 140 if ($sizeofframes > 0) { 141 142 $framedata = $this->fread($sizeofframes); // read all frames from file into $framedata variable 143 144 // if entire frame data is unsynched, de-unsynch it now (ID3v2.3.x) 145 if (!empty($thisfile_id3v2_flags['unsynch']) && ($id3v2_majorversion <= 3)) { 146 $framedata = $this->DeUnsynchronise($framedata); 147 } 148 // [in ID3v2.4.0] Unsynchronisation [S:6.1] is done on frame level, instead 149 // of on tag level, making it easier to skip frames, increasing the streamability 150 // of the tag. The unsynchronisation flag in the header [S:3.1] indicates that 151 // there exists an unsynchronised frame, while the new unsynchronisation flag in 152 // the frame header [S:4.1.2] indicates unsynchronisation. 153 154 155 //$framedataoffset = 10 + ($thisfile_id3v2['exthead']['length'] ? $thisfile_id3v2['exthead']['length'] + 4 : 0); // how many bytes into the stream - start from after the 10-byte header (and extended header length+4, if present) 156 $framedataoffset = 10; // how many bytes into the stream - start from after the 10-byte header 157 158 159 // Extended Header 160 if (!empty($thisfile_id3v2_flags['exthead'])) { 161 $extended_header_offset = 0; 162 163 if ($id3v2_majorversion == 3) { 164 165 // v2.3 definition: 166 //Extended header size $xx xx xx xx // 32-bit integer 167 //Extended Flags $xx xx 168 // %x0000000 %00000000 // v2.3 169 // x - CRC data present 170 //Size of padding $xx xx xx xx 171 172 $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), 0); 173 $extended_header_offset += 4; 174 175 $thisfile_id3v2['exthead']['flag_bytes'] = 2; 176 $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes'])); 177 $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes']; 178 179 $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x8000); 180 181 $thisfile_id3v2['exthead']['padding_size'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4)); 182 $extended_header_offset += 4; 183 184 if ($thisfile_id3v2['exthead']['flags']['crc']) { 185 $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4)); 186 $extended_header_offset += 4; 187 } 188 $extended_header_offset += $thisfile_id3v2['exthead']['padding_size']; 189 190 } elseif ($id3v2_majorversion == 4) { 191 192 // v2.4 definition: 193 //Extended header size 4 * %0xxxxxxx // 28-bit synchsafe integer 194 //Number of flag bytes $01 195 //Extended Flags $xx 196 // %0bcd0000 // v2.4 197 // b - Tag is an update 198 // Flag data length $00 199 // c - CRC data present 200 // Flag data length $05 201 // Total frame CRC 5 * %0xxxxxxx 202 // d - Tag restrictions 203 // Flag data length $01 204 205 $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), true); 206 $extended_header_offset += 4; 207 208 $thisfile_id3v2['exthead']['flag_bytes'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should always be 1 209 $extended_header_offset += 1; 210 211 $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes'])); 212 $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes']; 213 214 $thisfile_id3v2['exthead']['flags']['update'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x40); 215 $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x20); 216 $thisfile_id3v2['exthead']['flags']['restrictions'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x10); 217 218 if ($thisfile_id3v2['exthead']['flags']['update']) { 219 $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 0 220 $extended_header_offset += 1; 221 } 222 223 if ($thisfile_id3v2['exthead']['flags']['crc']) { 224 $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 5 225 $extended_header_offset += 1; 226 $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $ext_header_chunk_length), true, false); 227 $extended_header_offset += $ext_header_chunk_length; 228 } 229 230 if ($thisfile_id3v2['exthead']['flags']['restrictions']) { 231 $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 1 232 $extended_header_offset += 1; 233 234 // %ppqrrstt 235 $restrictions_raw = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); 236 $extended_header_offset += 1; 237 $thisfile_id3v2['exthead']['flags']['restrictions']['tagsize'] = ($restrictions_raw & 0xC0) >> 6; // p - Tag size restrictions 238 $thisfile_id3v2['exthead']['flags']['restrictions']['textenc'] = ($restrictions_raw & 0x20) >> 5; // q - Text encoding restrictions 239 $thisfile_id3v2['exthead']['flags']['restrictions']['textsize'] = ($restrictions_raw & 0x18) >> 3; // r - Text fields size restrictions 240 $thisfile_id3v2['exthead']['flags']['restrictions']['imgenc'] = ($restrictions_raw & 0x04) >> 2; // s - Image encoding restrictions 241 $thisfile_id3v2['exthead']['flags']['restrictions']['imgsize'] = ($restrictions_raw & 0x03) >> 0; // t - Image size restrictions 242 243 $thisfile_id3v2['exthead']['flags']['restrictions_text']['tagsize'] = $this->LookupExtendedHeaderRestrictionsTagSizeLimits($thisfile_id3v2['exthead']['flags']['restrictions']['tagsize']); 244 $thisfile_id3v2['exthead']['flags']['restrictions_text']['textenc'] = $this->LookupExtendedHeaderRestrictionsTextEncodings($thisfile_id3v2['exthead']['flags']['restrictions']['textenc']); 245 $thisfile_id3v2['exthead']['flags']['restrictions_text']['textsize'] = $this->LookupExtendedHeaderRestrictionsTextFieldSize($thisfile_id3v2['exthead']['flags']['restrictions']['textsize']); 246 $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgenc'] = $this->LookupExtendedHeaderRestrictionsImageEncoding($thisfile_id3v2['exthead']['flags']['restrictions']['imgenc']); 247 $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgsize'] = $this->LookupExtendedHeaderRestrictionsImageSizeSize($thisfile_id3v2['exthead']['flags']['restrictions']['imgsize']); 248 } 249 250 if ($thisfile_id3v2['exthead']['length'] != $extended_header_offset) { 251 $this->warning('ID3v2.4 extended header length mismatch (expecting '.intval($thisfile_id3v2['exthead']['length']).', found '.intval($extended_header_offset).')'); 252 } 253 } 254 255 $framedataoffset += $extended_header_offset; 256 $framedata = substr($framedata, $extended_header_offset); 257 } // end extended header 258 259 260 while (isset($framedata) && (strlen($framedata) > 0)) { // cycle through until no more frame data is left to parse 261 if (strlen($framedata) <= $this->ID3v2HeaderLength($id3v2_majorversion)) { 262 // insufficient room left in ID3v2 header for actual data - must be padding 263 $thisfile_id3v2['padding']['start'] = $framedataoffset; 264 $thisfile_id3v2['padding']['length'] = strlen($framedata); 265 $thisfile_id3v2['padding']['valid'] = true; 266 for ($i = 0; $i < $thisfile_id3v2['padding']['length']; $i++) { 267 if ($framedata[$i] != "\x00") { 268 $thisfile_id3v2['padding']['valid'] = false; 269 $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i; 270 $this->warning('Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'); 271 break; 272 } 273 } 274 break; // skip rest of ID3v2 header 275 } 276 $frame_header = null; 277 $frame_name = null; 278 $frame_size = null; 279 $frame_flags = null; 280 if ($id3v2_majorversion == 2) { 281 // Frame ID $xx xx xx (three characters) 282 // Size $xx xx xx (24-bit integer) 283 // Flags $xx xx 284 285 $frame_header = substr($framedata, 0, 6); // take next 6 bytes for header 286 $framedata = substr($framedata, 6); // and leave the rest in $framedata 287 $frame_name = substr($frame_header, 0, 3); 288 $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 3, 3), 0); 289 $frame_flags = 0; // not used for anything in ID3v2.2, just set to avoid E_NOTICEs 290 291 } elseif ($id3v2_majorversion > 2) { 292 293 // Frame ID $xx xx xx xx (four characters) 294 // Size $xx xx xx xx (32-bit integer in v2.3, 28-bit synchsafe in v2.4+) 295 // Flags $xx xx 296 297 $frame_header = substr($framedata, 0, 10); // take next 10 bytes for header 298 $framedata = substr($framedata, 10); // and leave the rest in $framedata 299 300 $frame_name = substr($frame_header, 0, 4); 301 if ($id3v2_majorversion == 3) { 302 $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer 303 } else { // ID3v2.4+ 304 $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 1); // 32-bit synchsafe integer (28-bit value) 305 } 306 307 if ($frame_size < (strlen($framedata) + 4)) { 308 $nextFrameID = substr($framedata, $frame_size, 4); 309 if ($this->IsValidID3v2FrameName($nextFrameID, $id3v2_majorversion)) { 310 // next frame is OK 311 } elseif (($frame_name == "\x00".'MP3') || ($frame_name == "\x00\x00".'MP') || ($frame_name == ' MP3') || ($frame_name == 'MP3e')) { 312 // MP3ext known broken frames - "ok" for the purposes of this test 313 } elseif (($id3v2_majorversion == 4) && ($this->IsValidID3v2FrameName(substr($framedata, getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0), 4), 3))) { 314 $this->warning('ID3v2 tag written as ID3v2.4, but with non-synchsafe integers (ID3v2.3 style). Older versions of (Helium2; iTunes) are known culprits of this. Tag has been parsed as ID3v2.3'); 315 $id3v2_majorversion = 3; 316 $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer 317 } 318 } 319 320 321 $frame_flags = getid3_lib::BigEndian2Int(substr($frame_header, 8, 2)); 322 } 323 324 if ((($id3v2_majorversion == 2) && ($frame_name == "\x00\x00\x00")) || ($frame_name == "\x00\x00\x00\x00")) { 325 // padding encountered 326 327 $thisfile_id3v2['padding']['start'] = $framedataoffset; 328 $thisfile_id3v2['padding']['length'] = strlen($frame_header) + strlen($framedata); 329 $thisfile_id3v2['padding']['valid'] = true; 330 331 $len = strlen($framedata); 332 for ($i = 0; $i < $len; $i++) { 333 if ($framedata[$i] != "\x00") { 334 $thisfile_id3v2['padding']['valid'] = false; 335 $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i; 336 $this->warning('Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'); 337 break; 338 } 339 } 340 break; // skip rest of ID3v2 header 341 } 342 343 if ($iTunesBrokenFrameNameFixed = self::ID3v22iTunesBrokenFrameName($frame_name)) { 344 $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by iTunes (versions "X v2.0.3", "v3.0.1", "v7.0.0.70" are known-guilty, probably others too)]. Translated frame name from "'.str_replace("\x00", ' ', $frame_name).'" to "'.$iTunesBrokenFrameNameFixed.'" for parsing.'); 345 $frame_name = $iTunesBrokenFrameNameFixed; 346 } 347 if (($frame_size <= strlen($framedata)) && ($this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion))) { 348 349 $parsedFrame = array(); 350 $parsedFrame['frame_name'] = $frame_name; 351 $parsedFrame['frame_flags_raw'] = $frame_flags; 352 $parsedFrame['data'] = substr($framedata, 0, $frame_size); 353 $parsedFrame['datalength'] = getid3_lib::CastAsInt($frame_size); 354 $parsedFrame['dataoffset'] = $framedataoffset; 355 356 $this->ParseID3v2Frame($parsedFrame); 357 $thisfile_id3v2[$frame_name][] = $parsedFrame; 358 359 $framedata = substr($framedata, $frame_size); 360 361 } else { // invalid frame length or FrameID 362 363 if ($frame_size <= strlen($framedata)) { 364 365 if ($this->IsValidID3v2FrameName(substr($framedata, $frame_size, 4), $id3v2_majorversion)) { 366 367 // next frame is valid, just skip the current frame 368 $framedata = substr($framedata, $frame_size); 369 $this->warning('Next ID3v2 frame is valid, skipping current frame.'); 370 371 } else { 372 373 // next frame is invalid too, abort processing 374 //unset($framedata); 375 $framedata = null; 376 $this->error('Next ID3v2 frame is also invalid, aborting processing.'); 377 378 } 379 380 } elseif ($frame_size == strlen($framedata)) { 381 382 // this is the last frame, just skip 383 $this->warning('This was the last ID3v2 frame.'); 384 385 } else { 386 387 // next frame is invalid too, abort processing 388 //unset($framedata); 389 $framedata = null; 390 $this->warning('Invalid ID3v2 frame size, aborting.'); 391 392 } 393 if (!$this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion)) { 394 395 switch ($frame_name) { 396 case "\x00\x00".'MP': 397 case "\x00".'MP3': 398 case ' MP3': 399 case 'MP3e': 400 case "\x00".'MP': 401 case ' MP': 402 case 'MP3': 403 $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by "MP3ext (www.mutschler.de/mp3ext/)"]'); 404 break; 405 406 default: 407 $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))).'); 408 break; 409 } 410 411 } elseif (!isset($framedata) || ($frame_size > strlen($framedata))) { 412 413 $this->error('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: $frame_size ('.$frame_size.') > strlen($framedata) ('.(isset($framedata) ? strlen($framedata) : 'null').')).'); 414 415 } else { 416 417 $this->error('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag).'); 418 419 } 420 421 } 422 $framedataoffset += ($frame_size + $this->ID3v2HeaderLength($id3v2_majorversion)); 423 424 } 425 426 } 427 428 429 // Footer 430 431 // The footer is a copy of the header, but with a different identifier. 432 // ID3v2 identifier "3DI" 433 // ID3v2 version $04 00 434 // ID3v2 flags %abcd0000 435 // ID3v2 size 4 * %0xxxxxxx 436 437 if (isset($thisfile_id3v2_flags['isfooter']) && $thisfile_id3v2_flags['isfooter']) { 438 $footer = $this->fread(10); 439 if (substr($footer, 0, 3) == '3DI') { 440 $thisfile_id3v2['footer'] = true; 441 $thisfile_id3v2['majorversion_footer'] = ord($footer[3]); 442 $thisfile_id3v2['minorversion_footer'] = ord($footer[4]); 443 } 444 if ($thisfile_id3v2['majorversion_footer'] <= 4) { 445 $id3_flags = ord($footer[5]); 446 $thisfile_id3v2_flags['unsynch_footer'] = (bool) ($id3_flags & 0x80); 447 $thisfile_id3v2_flags['extfoot_footer'] = (bool) ($id3_flags & 0x40); 448 $thisfile_id3v2_flags['experim_footer'] = (bool) ($id3_flags & 0x20); 449 $thisfile_id3v2_flags['isfooter_footer'] = (bool) ($id3_flags & 0x10); 450 451 $thisfile_id3v2['footerlength'] = getid3_lib::BigEndian2Int(substr($footer, 6, 4), 1); 452 } 453 } // end footer 454 455 if (isset($thisfile_id3v2['comments']['genre'])) { 456 $genres = array(); 457 foreach ($thisfile_id3v2['comments']['genre'] as $key => $value) { 458 foreach ($this->ParseID3v2GenreString($value) as $genre) { 459 $genres[] = $genre; 460 } 461 } 462 $thisfile_id3v2['comments']['genre'] = array_unique($genres); 463 unset($key, $value, $genres, $genre); 464 } 465 466 if (isset($thisfile_id3v2['comments']['track_number'])) { 467 foreach ($thisfile_id3v2['comments']['track_number'] as $key => $value) { 468 if (strstr($value, '/')) { 469 list($thisfile_id3v2['comments']['track_number'][$key], $thisfile_id3v2['comments']['totaltracks'][$key]) = explode('/', $thisfile_id3v2['comments']['track_number'][$key]); 470 } 471 } 472 } 473 474 if (!isset($thisfile_id3v2['comments']['year']) && !empty($thisfile_id3v2['comments']['recording_time'][0]) && preg_match('#^([0-9]{4})#', trim($thisfile_id3v2['comments']['recording_time'][0]), $matches)) { 475 $thisfile_id3v2['comments']['year'] = array($matches[1]); 476 } 477 478 479 if (!empty($thisfile_id3v2['TXXX'])) { 480 // MediaMonkey does this, maybe others: write a blank RGAD frame, but put replay-gain adjustment values in TXXX frames 481 foreach ($thisfile_id3v2['TXXX'] as $txxx_array) { 482 switch ($txxx_array['description']) { 483 case 'replaygain_track_gain': 484 if (empty($info['replay_gain']['track']['adjustment']) && !empty($txxx_array['data'])) { 485 $info['replay_gain']['track']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data']))); 486 } 487 break; 488 case 'replaygain_track_peak': 489 if (empty($info['replay_gain']['track']['peak']) && !empty($txxx_array['data'])) { 490 $info['replay_gain']['track']['peak'] = floatval($txxx_array['data']); 491 } 492 break; 493 case 'replaygain_album_gain': 494 if (empty($info['replay_gain']['album']['adjustment']) && !empty($txxx_array['data'])) { 495 $info['replay_gain']['album']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data']))); 496 } 497 break; 498 case 'replaygain_album_peak': 499 if (empty($info['replay_gain']['album']['peak']) && !empty($txxx_array['data'])) { 500 $info['replay_gain']['album']['peak'] = floatval($txxx_array['data']); 501 } 502 break; 503 } 504 } 505 } 506 507 508 // Set avdataoffset 509 $info['avdataoffset'] = $thisfile_id3v2['headerlength']; 510 if (isset($thisfile_id3v2['footer'])) { 511 $info['avdataoffset'] += 10; 512 } 513 514 return true; 515 } 516 517 /** 518 * @param string $genrestring 519 * 520 * @return array 521 */ 522 public function ParseID3v2GenreString($genrestring) { 523 // Parse genres into arrays of genreName and genreID 524 // ID3v2.2.x, ID3v2.3.x: '(21)' or '(4)Eurodisco' or '(51)(39)' or '(55)((I think...)' 525 // ID3v2.4.x: '21' $00 'Eurodisco' $00 526 $clean_genres = array(); 527 528 // hack-fixes for some badly-written ID3v2.3 taggers, while trying not to break correctly-written tags 529 if (($this->getid3->info['id3v2']['majorversion'] == 3) && !preg_match('#[\x00]#', $genrestring)) { 530 // note: MusicBrainz Picard incorrectly stores plaintext genres separated by "/" when writing in ID3v2.3 mode, hack-fix here: 531 // replace / with NULL, then replace back the two ID3v1 genres that legitimately have "/" as part of the single genre name 532 if (strpos($genrestring, '/') !== false) { 533 $LegitimateSlashedGenreList = array( // https://github.com/JamesHeinrich/getID3/issues/223 534 'Pop/Funk', // ID3v1 genre #62 - https://en.wikipedia.org/wiki/ID3#standard 535 'Cut-up/DJ', // Discogs - https://www.discogs.com/style/cut-up/dj 536 'RnB/Swing', // Discogs - https://www.discogs.com/style/rnb/swing 537 'Funk / Soul', // Discogs (note spaces) - https://www.discogs.com/genre/funk+%2F+soul 538 ); 539 $genrestring = str_replace('/', "\x00", $genrestring); 540 foreach ($LegitimateSlashedGenreList as $SlashedGenre) { 541 $genrestring = str_ireplace(str_replace('/', "\x00", $SlashedGenre), $SlashedGenre, $genrestring); 542 } 543 } 544 545 // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" 546 if (strpos($genrestring, ';') !== false) { 547 $genrestring = str_replace(';', "\x00", $genrestring); 548 } 549 } 550 551 552 if (strpos($genrestring, "\x00") === false) { 553 $genrestring = preg_replace('#\(([0-9]{1,3})\)#', '$1'."\x00", $genrestring); 554 } 555 556 $genre_elements = explode("\x00", $genrestring); 557 foreach ($genre_elements as $element) { 558 $element = trim($element); 559 if ($element) { 560 if (preg_match('#^[0-9]{1,3}$#', $element)) { 561 $clean_genres[] = getid3_id3v1::LookupGenreName($element); 562 } else { 563 $clean_genres[] = str_replace('((', '(', $element); 564 } 565 } 566 } 567 return $clean_genres; 568 } 569 570 /** 571 * @param array $parsedFrame 572 * 573 * @return bool 574 */ 575 public function ParseID3v2Frame(&$parsedFrame) { 576 577 // shortcuts 578 $info = &$this->getid3->info; 579 $id3v2_majorversion = $info['id3v2']['majorversion']; 580 581 $parsedFrame['framenamelong'] = $this->FrameNameLongLookup($parsedFrame['frame_name']); 582 if (empty($parsedFrame['framenamelong'])) { 583 unset($parsedFrame['framenamelong']); 584 } 585 $parsedFrame['framenameshort'] = $this->FrameNameShortLookup($parsedFrame['frame_name']); 586 if (empty($parsedFrame['framenameshort'])) { 587 unset($parsedFrame['framenameshort']); 588 } 589 590 if ($id3v2_majorversion >= 3) { // frame flags are not part of the ID3v2.2 standard 591 if ($id3v2_majorversion == 3) { 592 // Frame Header Flags 593 // %abc00000 %ijk00000 594 $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x8000); // a - Tag alter preservation 595 $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // b - File alter preservation 596 $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // c - Read only 597 $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0080); // i - Compression 598 $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // j - Encryption 599 $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0020); // k - Grouping identity 600 601 } elseif ($id3v2_majorversion == 4) { 602 // Frame Header Flags 603 // %0abc0000 %0h00kmnp 604 $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // a - Tag alter preservation 605 $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // b - File alter preservation 606 $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x1000); // c - Read only 607 $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // h - Grouping identity 608 $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0008); // k - Compression 609 $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0004); // m - Encryption 610 $parsedFrame['flags']['Unsynchronisation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0002); // n - Unsynchronisation 611 $parsedFrame['flags']['DataLengthIndicator'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0001); // p - Data length indicator 612 613 // Frame-level de-unsynchronisation - ID3v2.4 614 if ($parsedFrame['flags']['Unsynchronisation']) { 615 $parsedFrame['data'] = $this->DeUnsynchronise($parsedFrame['data']); 616 } 617 618 if ($parsedFrame['flags']['DataLengthIndicator']) { 619 $parsedFrame['data_length_indicator'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4), 1); 620 $parsedFrame['data'] = substr($parsedFrame['data'], 4); 621 } 622 } 623 624 // Frame-level de-compression 625 if ($parsedFrame['flags']['compression']) { 626 $parsedFrame['decompressed_size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4)); 627 if (!function_exists('gzuncompress')) { 628 $this->warning('gzuncompress() support required to decompress ID3v2 frame "'.$parsedFrame['frame_name'].'"'); 629 } else { 630 // https://github.com/JamesHeinrich/getID3/security/advisories/GHSA-c2xw-vp6w-gpph 631 // Set a limit of 1/4 of PHP memory limit (if known), or default hard cap of 32MB if unknown. 632 $decompression_limit = ($this->getid3->memory_limit > 0) ? (int) round($this->getid3->memory_limit / 4) : 32*1024*1024; 633 if ($decompresseddata = @gzuncompress(substr($parsedFrame['data'], 4), $decompression_limit)) { 634 $parsedFrame['data'] = $decompresseddata; 635 unset($decompresseddata); 636 } else { 637 $this->warning('gzuncompress() failed on compressed contents of ID3v2 frame "'.$parsedFrame['frame_name'].'"'); 638 } 639 } 640 } 641 } 642 643 if (!empty($parsedFrame['flags']['DataLengthIndicator'])) { 644 if ($parsedFrame['data_length_indicator'] != strlen($parsedFrame['data'])) { 645 $this->warning('ID3v2 frame "'.$parsedFrame['frame_name'].'" should be '.$parsedFrame['data_length_indicator'].' bytes long according to DataLengthIndicator, but found '.strlen($parsedFrame['data']).' bytes of data'); 646 } 647 } 648 649 if (isset($parsedFrame['datalength']) && ($parsedFrame['datalength'] == 0)) { 650 651 $warning = 'Frame "'.$parsedFrame['frame_name'].'" at offset '.$parsedFrame['dataoffset'].' has no data portion'; 652 switch ($parsedFrame['frame_name']) { 653 case 'WCOM': 654 $warning .= ' (this is known to happen with files tagged by RioPort)'; 655 break; 656 657 default: 658 break; 659 } 660 $this->warning($warning); 661 662 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'UFID')) || // 4.1 UFID Unique file identifier 663 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'UFI'))) { // 4.1 UFI Unique file identifier 664 // There may be more than one 'UFID' frame in a tag, 665 // but only one with the same 'Owner identifier'. 666 // <Header for 'Unique file identifier', ID: 'UFID'> 667 // Owner identifier <text string> $00 668 // Identifier <up to 64 bytes binary data> 669 $exploded = explode("\x00", $parsedFrame['data'], 2); 670 $parsedFrame['ownerid'] = $exploded[0]; 671 $parsedFrame['data'] = (isset($exploded[1]) ? $exploded[1] : ''); 672 673 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'TXXX')) || // 4.2.2 TXXX User defined text information frame 674 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'TXX'))) { // 4.2.2 TXX User defined text information frame 675 // There may be more than one 'TXXX' frame in each tag, 676 // but only one with the same description. 677 // <Header for 'User defined text information frame', ID: 'TXXX'> 678 // Text encoding $xx 679 // Description <text string according to encoding> $00 (00) 680 // Value <text string according to encoding> 681 682 $frame_offset = 0; 683 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 684 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 685 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 686 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 687 $frame_textencoding_terminator = "\x00"; 688 } 689 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 690 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 691 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 692 } 693 $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 694 $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); 695 $parsedFrame['encodingid'] = $frame_textencoding; 696 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 697 698 $parsedFrame['description'] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['description'])); 699 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 700 $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $frame_textencoding_terminator); 701 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 702 $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); 703 if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { 704 $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); 705 } else { 706 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); 707 } 708 } 709 //unset($parsedFrame['data']); do not unset, may be needed elsewhere, e.g. for replaygain 710 711 712 } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'IPLS')) || // 4.4 IPLS Involved people list (ID3v2.3 only) 713 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'IPL')) || // 4.4 IPL Involved people list (ID3v2.2 only) 714 (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'TIPL')) || // 4.2.2 TIPL Involved people list (ID3v2.4 only) 715 (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'TMCL'))) { // 4.2.2 TMCL Musician credits list (ID3v2.4 only) 716 // http://id3.org/id3v2.3.0#sec4.4 717 // There may only be one 'IPL' frame in each tag 718 // <Header for 'Involved people list', ID: 'IPL'> 719 // Text encoding $xx 720 // People list strings <textstrings> 721 722 $frame_offset = 0; 723 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 724 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 725 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 726 } 727 $parsedFrame['encodingid'] = $frame_textencoding; 728 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($parsedFrame['encodingid']); 729 $parsedFrame['data_raw'] = (string) substr($parsedFrame['data'], $frame_offset); 730 731 // https://www.getid3.org/phpBB3/viewtopic.php?t=1369 732 // "this tag typically contains null terminated strings, which are associated in pairs" 733 // "there are users that use the tag incorrectly" 734 $IPLS_parts_unsorted = array(); 735 if (((strlen($parsedFrame['data_raw']) % 2) == 0) && ((substr($parsedFrame['data_raw'], 0, 2) == "\xFF\xFE") || (substr($parsedFrame['data_raw'], 0, 2) == "\xFE\xFF"))) { 736 // UTF-16, be careful looking for null bytes since most 2-byte characters may contain one; you need to find twin null bytes, and on even padding 737 $thisILPS = ''; 738 for ($i = 0; $i < strlen($parsedFrame['data_raw']); $i += 2) { 739 $twobytes = substr($parsedFrame['data_raw'], $i, 2); 740 if ($twobytes === "\x00\x00") { 741 $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); 742 $thisILPS = ''; 743 } else { 744 $thisILPS .= $twobytes; 745 } 746 } 747 if (strlen($thisILPS) > 0) { // extract the last part if any, even if it's only a BOM with no text following 748 $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); 749 } 750 } else { 751 // ISO-8859-1 or UTF-8 or other single-byte-null character set 752 $IPLS_parts_unsorted = explode("\x00", $parsedFrame['data_raw']); 753 if (end($IPLS_parts_unsorted) === '') { 754 // there was a terminating null after the last part and explode appended an empty string; drop it 755 array_pop($IPLS_parts_unsorted); 756 } 757 } 758 759 $IPLS_parts = array(); 760 if (count($IPLS_parts_unsorted) == 1) { 761 // Just a list of names, e.g. "Dino Baptiste, Jimmy Copley, John Gordon, Bernie Marsden, Sharon Watson". 762 // Use the normal output format but with empty roles. 763 $IPLS_parts_sorted = preg_split('#[;,\\r\\n\\t]#', $IPLS_parts_unsorted[0]); 764 foreach ($IPLS_parts_sorted as $person) { 765 $IPLS_parts[] = array( 766 'position' => '', 767 'person' => $person 768 ); 769 } 770 } 771 else { 772 while (\count($IPLS_parts_unsorted) >= 2) { 773 $IPLS_parts[] = array( 774 'position' => array_shift($IPLS_parts_unsorted), 775 'person' => array_shift($IPLS_parts_unsorted) 776 ); 777 } 778 if (\count($IPLS_parts_unsorted) > 0) { 779 $this->warning("Odd number of {$parsedFrame['frame_name']} parts - expected even number forming role/name pairs"); 780 $IPLS_parts[] = array( 781 'position' => array_shift($IPLS_parts_unsorted), 782 'person' => '' 783 ); 784 } 785 } 786 $parsedFrame['data'] = $IPLS_parts; 787 788 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 789 $info['id3v2']['comments'][$parsedFrame['framenameshort']] = $parsedFrame['data']; 790 } 791 792 793 } elseif ($parsedFrame['frame_name'][0] == 'T') { // 4.2. T??[?] Text information frame 794 // There may only be one text information frame of its kind in an tag. 795 // <Header for 'Text information frame', ID: 'T000' - 'TZZZ', 796 // excluding 'TXXX' described in 4.2.6.> 797 // Text encoding $xx 798 // Information <text string(s) according to encoding> 799 800 $frame_offset = 0; 801 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 802 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 803 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 804 } 805 806 $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); 807 $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding)); 808 809 $parsedFrame['encodingid'] = $frame_textencoding; 810 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 811 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 812 // ID3v2.3 specs say that TPE1 (and others) can contain multiple artist values separated with / 813 // This of course breaks when an artist name contains slash character, e.g. "AC/DC" 814 // MP3tag (maybe others) implement alternative system where multiple artists are null-separated, which makes more sense 815 // getID3 will split null-separated artists into multiple artists and leave slash-separated ones to the user 816 switch ($parsedFrame['encoding']) { 817 case 'UTF-16': 818 case 'UTF-16BE': 819 case 'UTF-16LE': 820 $wordsize = 2; 821 break; 822 case 'ISO-8859-1': 823 case 'UTF-8': 824 default: 825 $wordsize = 1; 826 break; 827 } 828 $Txxx_elements = array(); 829 $Txxx_elements_start_offset = 0; 830 for ($i = 0; $i < strlen($parsedFrame['data']); $i += $wordsize) { 831 if (substr($parsedFrame['data'], $i, $wordsize) == str_repeat("\x00", $wordsize)) { 832 $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); 833 $Txxx_elements_start_offset = $i + $wordsize; 834 } 835 } 836 $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); 837 foreach ($Txxx_elements as $Txxx_element) { 838 $string = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $Txxx_element); 839 if (!empty($string)) { 840 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $string; 841 } 842 } 843 unset($string, $wordsize, $i, $Txxx_elements, $Txxx_element, $Txxx_elements_start_offset); 844 } 845 846 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'WXXX')) || // 4.3.2 WXXX User defined URL link frame 847 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'WXX'))) { // 4.3.2 WXX User defined URL link frame 848 // There may be more than one 'WXXX' frame in each tag, 849 // but only one with the same description 850 // <Header for 'User defined URL link frame', ID: 'WXXX'> 851 // Text encoding $xx 852 // Description <text string according to encoding> $00 (00) 853 // URL <text string> 854 855 $frame_offset = 0; 856 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 857 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 858 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 859 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 860 $frame_textencoding_terminator = "\x00"; 861 } 862 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 863 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 864 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 865 } 866 $parsedFrame['encodingid'] = $frame_textencoding; 867 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 868 $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); // according to the frame text encoding 869 $parsedFrame['url'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); // always ISO-8859-1 870 $parsedFrame['description'] = $this->RemoveStringTerminator($parsedFrame['description'], $frame_textencoding_terminator); 871 $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); 872 873 if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { 874 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback('ISO-8859-1', $info['id3v2']['encoding'], $parsedFrame['url']); 875 } 876 unset($parsedFrame['data']); 877 878 879 } elseif ($parsedFrame['frame_name'][0] == 'W') { // 4.3. W??? URL link frames 880 // There may only be one URL link frame of its kind in a tag, 881 // except when stated otherwise in the frame description 882 // <Header for 'URL link frame', ID: 'W000' - 'WZZZ', excluding 'WXXX' 883 // described in 4.3.2.> 884 // URL <text string> 885 886 $parsedFrame['url'] = trim($parsedFrame['data']); // always ISO-8859-1 887 if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { 888 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback('ISO-8859-1', $info['id3v2']['encoding'], $parsedFrame['url']); 889 } 890 unset($parsedFrame['data']); 891 892 893 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MCDI')) || // 4.4 MCDI Music CD identifier 894 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MCI'))) { // 4.5 MCI Music CD identifier 895 // There may only be one 'MCDI' frame in each tag 896 // <Header for 'Music CD identifier', ID: 'MCDI'> 897 // CD TOC <binary data> 898 899 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 900 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; 901 } 902 903 904 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ETCO')) || // 4.5 ETCO Event timing codes 905 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ETC'))) { // 4.6 ETC Event timing codes 906 // There may only be one 'ETCO' frame in each tag 907 // <Header for 'Event timing codes', ID: 'ETCO'> 908 // Time stamp format $xx 909 // Where time stamp format is: 910 // $01 (32-bit value) MPEG frames from beginning of file 911 // $02 (32-bit value) milliseconds from beginning of file 912 // Followed by a list of key events in the following format: 913 // Type of event $xx 914 // Time stamp $xx (xx ...) 915 // The 'Time stamp' is set to zero if directly at the beginning of the sound 916 // or after the previous event. All events MUST be sorted in chronological order. 917 918 $frame_offset = 0; 919 $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 920 921 while ($frame_offset < strlen($parsedFrame['data'])) { 922 $parsedFrame['typeid'] = substr($parsedFrame['data'], $frame_offset++, 1); 923 $parsedFrame['type'] = $this->ETCOEventLookup($parsedFrame['typeid']); 924 $parsedFrame['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 925 $frame_offset += 4; 926 } 927 unset($parsedFrame['data']); 928 929 930 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MLLT')) || // 4.6 MLLT MPEG location lookup table 931 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MLL'))) { // 4.7 MLL MPEG location lookup table 932 // There may only be one 'MLLT' frame in each tag 933 // <Header for 'Location lookup table', ID: 'MLLT'> 934 // MPEG frames between reference $xx xx 935 // Bytes between reference $xx xx xx 936 // Milliseconds between reference $xx xx xx 937 // Bits for bytes deviation $xx 938 // Bits for milliseconds dev. $xx 939 // Then for every reference the following data is included; 940 // Deviation in bytes %xxx.... 941 // Deviation in milliseconds %xxx.... 942 943 $frame_offset = 0; 944 $parsedFrame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 2)); 945 $parsedFrame['bytesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 2, 3)); 946 $parsedFrame['msbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 5, 3)); 947 $parsedFrame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1)); 948 $parsedFrame['bitsformsdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1)); 949 $parsedFrame['data'] = substr($parsedFrame['data'], 10); 950 $deviationbitstream = ''; 951 while ($frame_offset < strlen($parsedFrame['data'])) { 952 $deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); 953 } 954 $reference_counter = 0; 955 while (strlen($deviationbitstream) > 0) { 956 $parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation'])); 957 $parsedFrame[$reference_counter]['msdeviation'] = bindec(substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'], $parsedFrame['bitsformsdeviation'])); 958 $deviationbitstream = substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']); 959 $reference_counter++; 960 } 961 unset($parsedFrame['data']); 962 963 964 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYTC')) || // 4.7 SYTC Synchronised tempo codes 965 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'STC'))) { // 4.8 STC Synchronised tempo codes 966 // There may only be one 'SYTC' frame in each tag 967 // <Header for 'Synchronised tempo codes', ID: 'SYTC'> 968 // Time stamp format $xx 969 // Tempo data <binary data> 970 // Where time stamp format is: 971 // $01 (32-bit value) MPEG frames from beginning of file 972 // $02 (32-bit value) milliseconds from beginning of file 973 974 $frame_offset = 0; 975 $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 976 $timestamp_counter = 0; 977 while ($frame_offset < strlen($parsedFrame['data'])) { 978 $parsedFrame[$timestamp_counter]['tempo'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 979 if ($parsedFrame[$timestamp_counter]['tempo'] == 255) { 980 $parsedFrame[$timestamp_counter]['tempo'] += ord(substr($parsedFrame['data'], $frame_offset++, 1)); 981 } 982 $parsedFrame[$timestamp_counter]['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 983 $frame_offset += 4; 984 $timestamp_counter++; 985 } 986 unset($parsedFrame['data']); 987 988 989 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USLT')) || // 4.8 USLT Unsynchronised lyric/text transcription 990 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ULT'))) { // 4.9 ULT Unsynchronised lyric/text transcription 991 // There may be more than one 'Unsynchronised lyrics/text transcription' frame 992 // in each tag, but only one with the same language and content descriptor. 993 // <Header for 'Unsynchronised lyrics/text transcription', ID: 'USLT'> 994 // Text encoding $xx 995 // Language $xx xx xx 996 // Content descriptor <text string according to encoding> $00 (00) 997 // Lyrics/text <full text string according to encoding> 998 999 $frame_offset = 0; 1000 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1001 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1002 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1003 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 1004 $frame_textencoding_terminator = "\x00"; 1005 } 1006 if (strlen($parsedFrame['data']) >= (4 + strlen($frame_textencoding_terminator))) { // shouldn't be an issue but badly-written files have been spotted in the wild with not only no contents but also missing the required language field, see https://github.com/JamesHeinrich/getID3/issues/315 1007 $frame_language = substr($parsedFrame['data'], $frame_offset, 3); 1008 $frame_offset += 3; 1009 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1010 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 1011 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1012 } 1013 $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1014 $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); 1015 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 1016 $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $frame_textencoding_terminator); 1017 1018 $parsedFrame['encodingid'] = $frame_textencoding; 1019 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 1020 1021 $parsedFrame['language'] = $frame_language; 1022 $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); 1023 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 1024 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); 1025 } 1026 } else { 1027 $this->warning('Invalid data in frame "'.$parsedFrame['frame_name'].'" at offset '.$parsedFrame['dataoffset']); 1028 } 1029 unset($parsedFrame['data']); 1030 1031 1032 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYLT')) || // 4.9 SYLT Synchronised lyric/text 1033 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'SLT'))) { // 4.10 SLT Synchronised lyric/text 1034 // There may be more than one 'SYLT' frame in each tag, 1035 // but only one with the same language and content descriptor. 1036 // <Header for 'Synchronised lyrics/text', ID: 'SYLT'> 1037 // Text encoding $xx 1038 // Language $xx xx xx 1039 // Time stamp format $xx 1040 // $01 (32-bit value) MPEG frames from beginning of file 1041 // $02 (32-bit value) milliseconds from beginning of file 1042 // Content type $xx 1043 // Content descriptor <text string according to encoding> $00 (00) 1044 // Terminated text to be synced (typically a syllable) 1045 // Sync identifier (terminator to above string) $00 (00) 1046 // Time stamp $xx (xx ...) 1047 1048 $frame_offset = 0; 1049 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1050 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1051 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1052 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 1053 $frame_textencoding_terminator = "\x00"; 1054 } 1055 $frame_language = substr($parsedFrame['data'], $frame_offset, 3); 1056 $frame_offset += 3; 1057 $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1058 $parsedFrame['contenttypeid'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1059 $parsedFrame['contenttype'] = $this->SYTLContentTypeLookup($parsedFrame['contenttypeid']); 1060 $parsedFrame['encodingid'] = $frame_textencoding; 1061 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 1062 1063 $parsedFrame['language'] = $frame_language; 1064 $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); 1065 1066 $timestampindex = 0; 1067 $frame_remainingdata = substr($parsedFrame['data'], $frame_offset); 1068 while (strlen($frame_remainingdata)) { 1069 $frame_offset = 0; 1070 $frame_terminatorpos = strpos($frame_remainingdata, $frame_textencoding_terminator); 1071 if ($frame_terminatorpos === false) { 1072 $frame_remainingdata = ''; 1073 } else { 1074 if (substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 1075 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1076 } 1077 $parsedFrame['lyrics'][$timestampindex]['data'] = substr($frame_remainingdata, $frame_offset, $frame_terminatorpos - $frame_offset); 1078 1079 $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator)); 1080 if (strlen($frame_remainingdata)) { // https://github.com/JamesHeinrich/getID3/issues/444 1081 if (($timestampindex == 0) && (ord($frame_remainingdata[0]) != 0)) { 1082 // timestamp probably omitted for first data item 1083 } else { 1084 $parsedFrame['lyrics'][$timestampindex]['timestamp'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 4)); 1085 $frame_remainingdata = substr($frame_remainingdata, 4); 1086 } 1087 $timestampindex++; 1088 } 1089 } 1090 } 1091 unset($parsedFrame['data']); 1092 1093 1094 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMM')) || // 4.10 COMM Comments 1095 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'COM'))) { // 4.11 COM Comments 1096 // There may be more than one comment frame in each tag, 1097 // but only one with the same language and content descriptor. 1098 // <Header for 'Comment', ID: 'COMM'> 1099 // Text encoding $xx 1100 // Language $xx xx xx 1101 // Short content descrip. <text string according to encoding> $00 (00) 1102 // The actual text <full text string according to encoding> 1103 1104 if (strlen($parsedFrame['data']) < 5) { 1105 1106 $this->warning('Invalid data (too short) for "'.$parsedFrame['frame_name'].'" frame at offset '.$parsedFrame['dataoffset']); 1107 1108 } else { 1109 1110 $frame_offset = 0; 1111 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1112 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1113 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1114 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 1115 $frame_textencoding_terminator = "\x00"; 1116 } 1117 $frame_language = substr($parsedFrame['data'], $frame_offset, 3); 1118 $frame_offset += 3; 1119 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1120 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 1121 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1122 } 1123 $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1124 $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); 1125 $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 1126 $frame_text = $this->RemoveStringTerminator($frame_text, $frame_textencoding_terminator); 1127 1128 $parsedFrame['encodingid'] = $frame_textencoding; 1129 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 1130 1131 $parsedFrame['language'] = $frame_language; 1132 $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); 1133 $parsedFrame['data'] = $frame_text; 1134 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 1135 $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (!empty($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); 1136 if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { 1137 $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); 1138 } else { 1139 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); 1140 } 1141 } 1142 1143 } 1144 1145 } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'RVA2')) { // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only) 1146 // There may be more than one 'RVA2' frame in each tag, 1147 // but only one with the same identification string 1148 // <Header for 'Relative volume adjustment (2)', ID: 'RVA2'> 1149 // Identification <text string> $00 1150 // The 'identification' string is used to identify the situation and/or 1151 // device where this adjustment should apply. The following is then 1152 // repeated for every channel: 1153 // Type of channel $xx 1154 // Volume adjustment $xx xx 1155 // Bits representing peak $xx 1156 // Peak volume $xx (xx ...) 1157 1158 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00"); 1159 $frame_idstring = substr($parsedFrame['data'], 0, $frame_terminatorpos); 1160 if ($frame_idstring === "\x00") { 1161 $frame_idstring = ''; 1162 } 1163 $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00")); 1164 $parsedFrame['description'] = $frame_idstring; 1165 $RVA2channelcounter = 0; 1166 while (strlen($frame_remainingdata) >= 5) { 1167 $frame_offset = 0; 1168 $frame_channeltypeid = ord(substr($frame_remainingdata, $frame_offset++, 1)); 1169 $parsedFrame[$RVA2channelcounter]['channeltypeid'] = $frame_channeltypeid; 1170 $parsedFrame[$RVA2channelcounter]['channeltype'] = $this->RVA2ChannelTypeLookup($frame_channeltypeid); 1171 $parsedFrame[$RVA2channelcounter]['volumeadjust'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, 2), false, true); // 16-bit signed 1172 $frame_offset += 2; 1173 $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] = ord(substr($frame_remainingdata, $frame_offset++, 1)); 1174 if (($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] < 1) || ($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] > 4)) { 1175 $this->warning('ID3v2::RVA2 frame['.$RVA2channelcounter.'] contains invalid '.$parsedFrame[$RVA2channelcounter]['bitspeakvolume'].'-byte bits-representing-peak value'); 1176 break; 1177 } 1178 $frame_bytespeakvolume = ceil($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] / 8); 1179 $parsedFrame[$RVA2channelcounter]['peakvolume'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, $frame_bytespeakvolume)); 1180 $frame_remainingdata = substr($frame_remainingdata, $frame_offset + $frame_bytespeakvolume); 1181 $RVA2channelcounter++; 1182 } 1183 unset($parsedFrame['data']); 1184 1185 1186 } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'RVAD')) || // 4.12 RVAD Relative volume adjustment (ID3v2.3 only) 1187 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'RVA'))) { // 4.12 RVA Relative volume adjustment (ID3v2.2 only) 1188 // There may only be one 'RVA' frame in each tag 1189 // <Header for 'Relative volume adjustment', ID: 'RVA'> 1190 // ID3v2.2 => Increment/decrement %000000ba 1191 // ID3v2.3 => Increment/decrement %00fedcba 1192 // Bits used for volume descr. $xx 1193 // Relative volume change, right $xx xx (xx ...) // a 1194 // Relative volume change, left $xx xx (xx ...) // b 1195 // Peak volume right $xx xx (xx ...) 1196 // Peak volume left $xx xx (xx ...) 1197 // ID3v2.3 only, optional (not present in ID3v2.2): 1198 // Relative volume change, right back $xx xx (xx ...) // c 1199 // Relative volume change, left back $xx xx (xx ...) // d 1200 // Peak volume right back $xx xx (xx ...) 1201 // Peak volume left back $xx xx (xx ...) 1202 // ID3v2.3 only, optional (not present in ID3v2.2): 1203 // Relative volume change, center $xx xx (xx ...) // e 1204 // Peak volume center $xx xx (xx ...) 1205 // ID3v2.3 only, optional (not present in ID3v2.2): 1206 // Relative volume change, bass $xx xx (xx ...) // f 1207 // Peak volume bass $xx xx (xx ...) 1208 1209 $frame_offset = 0; 1210 $frame_incrdecrflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); 1211 $parsedFrame['incdec']['right'] = (bool) substr($frame_incrdecrflags, 6, 1); 1212 $parsedFrame['incdec']['left'] = (bool) substr($frame_incrdecrflags, 7, 1); 1213 $parsedFrame['bitsvolume'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1214 $frame_bytesvolume = ceil($parsedFrame['bitsvolume'] / 8); 1215 $parsedFrame['volumechange']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1216 if ($parsedFrame['incdec']['right'] === false) { 1217 $parsedFrame['volumechange']['right'] *= -1; 1218 } 1219 $frame_offset += $frame_bytesvolume; 1220 $parsedFrame['volumechange']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1221 if ($parsedFrame['incdec']['left'] === false) { 1222 $parsedFrame['volumechange']['left'] *= -1; 1223 } 1224 $frame_offset += $frame_bytesvolume; 1225 $parsedFrame['peakvolume']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1226 $frame_offset += $frame_bytesvolume; 1227 $parsedFrame['peakvolume']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1228 $frame_offset += $frame_bytesvolume; 1229 if ($id3v2_majorversion == 3) { 1230 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); 1231 if (strlen($parsedFrame['data']) > 0) { 1232 $parsedFrame['incdec']['rightrear'] = (bool) substr($frame_incrdecrflags, 4, 1); 1233 $parsedFrame['incdec']['leftrear'] = (bool) substr($frame_incrdecrflags, 5, 1); 1234 $parsedFrame['volumechange']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1235 if ($parsedFrame['incdec']['rightrear'] === false) { 1236 $parsedFrame['volumechange']['rightrear'] *= -1; 1237 } 1238 $frame_offset += $frame_bytesvolume; 1239 $parsedFrame['volumechange']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1240 if ($parsedFrame['incdec']['leftrear'] === false) { 1241 $parsedFrame['volumechange']['leftrear'] *= -1; 1242 } 1243 $frame_offset += $frame_bytesvolume; 1244 $parsedFrame['peakvolume']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1245 $frame_offset += $frame_bytesvolume; 1246 $parsedFrame['peakvolume']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1247 $frame_offset += $frame_bytesvolume; 1248 } 1249 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); 1250 if (strlen($parsedFrame['data']) > 0) { 1251 $parsedFrame['incdec']['center'] = (bool) substr($frame_incrdecrflags, 3, 1); 1252 $parsedFrame['volumechange']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1253 if ($parsedFrame['incdec']['center'] === false) { 1254 $parsedFrame['volumechange']['center'] *= -1; 1255 } 1256 $frame_offset += $frame_bytesvolume; 1257 $parsedFrame['peakvolume']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1258 $frame_offset += $frame_bytesvolume; 1259 } 1260 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); 1261 if (strlen($parsedFrame['data']) > 0) { 1262 $parsedFrame['incdec']['bass'] = (bool) substr($frame_incrdecrflags, 2, 1); 1263 $parsedFrame['volumechange']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1264 if ($parsedFrame['incdec']['bass'] === false) { 1265 $parsedFrame['volumechange']['bass'] *= -1; 1266 } 1267 $frame_offset += $frame_bytesvolume; 1268 $parsedFrame['peakvolume']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); 1269 $frame_offset += $frame_bytesvolume; 1270 } 1271 } 1272 unset($parsedFrame['data']); 1273 1274 1275 } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'EQU2')) { // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only) 1276 // There may be more than one 'EQU2' frame in each tag, 1277 // but only one with the same identification string 1278 // <Header of 'Equalisation (2)', ID: 'EQU2'> 1279 // Interpolation method $xx 1280 // $00 Band 1281 // $01 Linear 1282 // Identification <text string> $00 1283 // The following is then repeated for every adjustment point 1284 // Frequency $xx xx 1285 // Volume adjustment $xx xx 1286 1287 $frame_offset = 0; 1288 $frame_interpolationmethod = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1289 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1290 $frame_idstring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1291 if ($frame_idstring === "\x00") { 1292 $frame_idstring = ''; 1293 } 1294 $parsedFrame['description'] = $frame_idstring; 1295 $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00")); 1296 while (strlen($frame_remainingdata)) { 1297 $frame_frequency = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 2)) / 2; 1298 $parsedFrame['data'][$frame_frequency] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, 2), false, true); 1299 $frame_remainingdata = substr($frame_remainingdata, 4); 1300 } 1301 $parsedFrame['interpolationmethod'] = $frame_interpolationmethod; 1302 unset($parsedFrame['data']); 1303 1304 1305 } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'EQUA')) || // 4.12 EQUA Equalisation (ID3v2.3 only) 1306 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'EQU'))) { // 4.13 EQU Equalisation (ID3v2.2 only) 1307 // There may only be one 'EQUA' frame in each tag 1308 // <Header for 'Relative volume adjustment', ID: 'EQU'> 1309 // Adjustment bits $xx 1310 // This is followed by 2 bytes + ('adjustment bits' rounded up to the 1311 // nearest byte) for every equalisation band in the following format, 1312 // giving a frequency range of 0 - 32767Hz: 1313 // Increment/decrement %x (MSB of the Frequency) 1314 // Frequency (lower 15 bits) 1315 // Adjustment $xx (xx ...) 1316 1317 $frame_offset = 0; 1318 $parsedFrame['adjustmentbits'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1319 $frame_adjustmentbytes = ceil($parsedFrame['adjustmentbits'] / 8); 1320 1321 $frame_remainingdata = (string) substr($parsedFrame['data'], $frame_offset); 1322 while (strlen($frame_remainingdata) > 0) { 1323 $frame_frequencystr = getid3_lib::BigEndian2Bin(substr($frame_remainingdata, 0, 2)); 1324 $frame_incdec = (bool) substr($frame_frequencystr, 0, 1); 1325 $frame_frequency = bindec(substr($frame_frequencystr, 1, 15)); 1326 $parsedFrame[$frame_frequency]['incdec'] = $frame_incdec; 1327 $parsedFrame[$frame_frequency]['adjustment'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, $frame_adjustmentbytes)); 1328 if ($parsedFrame[$frame_frequency]['incdec'] === false) { 1329 $parsedFrame[$frame_frequency]['adjustment'] *= -1; 1330 } 1331 $frame_remainingdata = substr($frame_remainingdata, 2 + $frame_adjustmentbytes); 1332 } 1333 unset($parsedFrame['data']); 1334 1335 1336 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RVRB')) || // 4.13 RVRB Reverb 1337 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'REV'))) { // 4.14 REV Reverb 1338 // There may only be one 'RVRB' frame in each tag. 1339 // <Header for 'Reverb', ID: 'RVRB'> 1340 // Reverb left (ms) $xx xx 1341 // Reverb right (ms) $xx xx 1342 // Reverb bounces, left $xx 1343 // Reverb bounces, right $xx 1344 // Reverb feedback, left to left $xx 1345 // Reverb feedback, left to right $xx 1346 // Reverb feedback, right to right $xx 1347 // Reverb feedback, right to left $xx 1348 // Premix left to right $xx 1349 // Premix right to left $xx 1350 1351 $frame_offset = 0; 1352 $parsedFrame['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 1353 $frame_offset += 2; 1354 $parsedFrame['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 1355 $frame_offset += 2; 1356 $parsedFrame['bouncesL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1357 $parsedFrame['bouncesR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1358 $parsedFrame['feedbackLL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1359 $parsedFrame['feedbackLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1360 $parsedFrame['feedbackRR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1361 $parsedFrame['feedbackRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1362 $parsedFrame['premixLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1363 $parsedFrame['premixRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1364 unset($parsedFrame['data']); 1365 1366 1367 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'APIC')) || // 4.14 APIC Attached picture 1368 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'PIC'))) { // 4.15 PIC Attached picture 1369 // There may be several pictures attached to one file, 1370 // each in their individual 'APIC' frame, but only one 1371 // with the same content descriptor 1372 // <Header for 'Attached picture', ID: 'APIC'> 1373 // Text encoding $xx 1374 // ID3v2.3+ => MIME type <text string> $00 1375 // ID3v2.2 => Image format $xx xx xx 1376 // Picture type $xx 1377 // Description <text string according to encoding> $00 (00) 1378 // Picture data <binary data> 1379 1380 $frame_offset = 0; 1381 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1382 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1383 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1384 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 1385 $frame_textencoding_terminator = "\x00"; 1386 } 1387 1388 $frame_imagetype = null; 1389 $frame_mimetype = null; 1390 if ($id3v2_majorversion == 2 && strlen($parsedFrame['data']) > $frame_offset) { 1391 $frame_imagetype = substr($parsedFrame['data'], $frame_offset, 3); 1392 if (strtolower($frame_imagetype) == 'ima') { 1393 // complete hack for mp3Rage (www.chaoticsoftware.com) that puts ID3v2.3-formatted 1394 // MIME type instead of 3-char ID3v2.2-format image type (thanks xbhoffØpacbell*net) 1395 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1396 $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1397 if ($frame_mimetype === "\x00") { 1398 $frame_mimetype = ''; 1399 } 1400 $frame_imagetype = strtoupper(str_replace('image/', '', strtolower($frame_mimetype))); 1401 if ($frame_imagetype == 'JPEG') { 1402 $frame_imagetype = 'JPG'; 1403 } 1404 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1405 } else { 1406 $frame_offset += 3; 1407 } 1408 } 1409 if ($id3v2_majorversion > 2 && strlen($parsedFrame['data']) > $frame_offset) { 1410 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1411 $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1412 if ($frame_mimetype === "\x00") { 1413 $frame_mimetype = ''; 1414 } 1415 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1416 } 1417 1418 $frame_picturetype = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1419 1420 if ($frame_offset >= $parsedFrame['datalength']) { 1421 $this->warning('data portion of APIC frame is missing at offset '.($parsedFrame['dataoffset'] + 8 + $frame_offset)); 1422 } else { 1423 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1424 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 1425 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1426 } 1427 $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1428 $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); 1429 $parsedFrame['encodingid'] = $frame_textencoding; 1430 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 1431 1432 if ($id3v2_majorversion == 2) { 1433 $parsedFrame['imagetype'] = isset($frame_imagetype) ? $frame_imagetype : null; 1434 } else { 1435 $parsedFrame['mime'] = isset($frame_mimetype) ? $frame_mimetype : null; 1436 } 1437 $parsedFrame['picturetypeid'] = $frame_picturetype; 1438 $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype); 1439 $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); 1440 $parsedFrame['datalength'] = strlen($parsedFrame['data']); 1441 1442 $parsedFrame['image_mime'] = ''; 1443 $imageinfo = array(); 1444 if ($imagechunkcheck = getid3_lib::GetDataImageSize($parsedFrame['data'], $imageinfo)) { 1445 if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { 1446 $parsedFrame['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); 1447 if ($imagechunkcheck[0]) { 1448 $parsedFrame['image_width'] = $imagechunkcheck[0]; 1449 } 1450 if ($imagechunkcheck[1]) { 1451 $parsedFrame['image_height'] = $imagechunkcheck[1]; 1452 } 1453 } 1454 } 1455 1456 do { 1457 if ($this->getid3->option_save_attachments === false) { 1458 // skip entirely 1459 unset($parsedFrame['data']); 1460 break; 1461 } 1462 $dir = ''; 1463 if ($this->getid3->option_save_attachments === true) { 1464 // great 1465 /* 1466 } elseif (is_int($this->getid3->option_save_attachments)) { 1467 if ($this->getid3->option_save_attachments < $parsedFrame['data_length']) { 1468 // too big, skip 1469 $this->warning('attachment at '.$frame_offset.' is too large to process inline ('.number_format($parsedFrame['data_length']).' bytes)'); 1470 unset($parsedFrame['data']); 1471 break; 1472 } 1473 */ 1474 } elseif (is_string($this->getid3->option_save_attachments)) { 1475 $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR); 1476 if (!is_dir($dir) || !getID3::is_writable($dir)) { 1477 // cannot write, skip 1478 $this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$dir.'" (not writable)'); 1479 unset($parsedFrame['data']); 1480 break; 1481 } 1482 } 1483 // if we get this far, must be OK 1484 if (is_string($this->getid3->option_save_attachments)) { 1485 $destination_filename = $dir.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$frame_offset; 1486 if (!file_exists($destination_filename) || getID3::is_writable($destination_filename)) { 1487 file_put_contents($destination_filename, $parsedFrame['data']); 1488 } else { 1489 $this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$destination_filename.'" (not writable)'); 1490 } 1491 $parsedFrame['data_filename'] = $destination_filename; 1492 unset($parsedFrame['data']); 1493 } else { 1494 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 1495 if (!isset($info['id3v2']['comments']['picture'])) { 1496 $info['id3v2']['comments']['picture'] = array(); 1497 } 1498 $comments_picture_data = array(); 1499 foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { 1500 if (isset($parsedFrame[$picture_key])) { 1501 $comments_picture_data[$picture_key] = $parsedFrame[$picture_key]; 1502 } 1503 } 1504 $info['id3v2']['comments']['picture'][] = $comments_picture_data; 1505 unset($comments_picture_data); 1506 } 1507 } 1508 } while (false); // @phpstan-ignore-line 1509 } 1510 1511 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GEOB')) || // 4.15 GEOB General encapsulated object 1512 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'GEO'))) { // 4.16 GEO General encapsulated object 1513 // There may be more than one 'GEOB' frame in each tag, 1514 // but only one with the same content descriptor 1515 // <Header for 'General encapsulated object', ID: 'GEOB'> 1516 // Text encoding $xx 1517 // MIME type <text string> $00 1518 // Filename <text string according to encoding> $00 (00) 1519 // Content description <text string according to encoding> $00 (00) 1520 // Encapsulated object <binary data> 1521 1522 $frame_offset = 0; 1523 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1524 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1525 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1526 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 1527 $frame_textencoding_terminator = "\x00"; 1528 } 1529 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1530 $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1531 if ($frame_mimetype === "\x00") { 1532 $frame_mimetype = ''; 1533 } 1534 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1535 1536 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1537 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 1538 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1539 } 1540 $frame_filename = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1541 if ($frame_filename === "\x00") { 1542 $frame_filename = ''; 1543 } 1544 $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); 1545 1546 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1547 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 1548 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1549 } 1550 $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1551 $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); 1552 $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); 1553 1554 $parsedFrame['objectdata'] = (string) substr($parsedFrame['data'], $frame_offset); 1555 $parsedFrame['encodingid'] = $frame_textencoding; 1556 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 1557 1558 $parsedFrame['mime'] = $frame_mimetype; 1559 $parsedFrame['filename'] = $frame_filename; 1560 unset($parsedFrame['data']); 1561 1562 1563 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PCNT')) || // 4.16 PCNT Play counter 1564 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CNT'))) { // 4.17 CNT Play counter 1565 // There may only be one 'PCNT' frame in each tag. 1566 // When the counter reaches all one's, one byte is inserted in 1567 // front of the counter thus making the counter eight bits bigger 1568 // <Header for 'Play counter', ID: 'PCNT'> 1569 // Counter $xx xx xx xx (xx ...) 1570 1571 $parsedFrame['data'] = getid3_lib::BigEndian2Int($parsedFrame['data']); 1572 1573 1574 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POPM')) || // 4.17 POPM Popularimeter 1575 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'POP'))) { // 4.18 POP Popularimeter 1576 // There may be more than one 'POPM' frame in each tag, 1577 // but only one with the same email address 1578 // <Header for 'Popularimeter', ID: 'POPM'> 1579 // Email to user <text string> $00 1580 // Rating $xx 1581 // Counter $xx xx xx xx (xx ...) 1582 1583 $frame_offset = 0; 1584 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1585 $frame_emailaddress = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1586 if ($frame_emailaddress === "\x00") { 1587 $frame_emailaddress = ''; 1588 } 1589 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1590 $frame_rating = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1591 $parsedFrame['counter'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); 1592 $parsedFrame['email'] = $frame_emailaddress; 1593 $parsedFrame['rating'] = $frame_rating; 1594 unset($parsedFrame['data']); 1595 1596 1597 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RBUF')) || // 4.18 RBUF Recommended buffer size 1598 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'BUF'))) { // 4.19 BUF Recommended buffer size 1599 // There may only be one 'RBUF' frame in each tag 1600 // <Header for 'Recommended buffer size', ID: 'RBUF'> 1601 // Buffer size $xx xx xx 1602 // Embedded info flag %0000000x 1603 // Offset to next tag $xx xx xx xx 1604 1605 $frame_offset = 0; 1606 $parsedFrame['buffersize'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 3)); 1607 $frame_offset += 3; 1608 1609 $frame_embeddedinfoflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); 1610 $parsedFrame['flags']['embededinfo'] = (bool) substr($frame_embeddedinfoflags, 7, 1); 1611 $parsedFrame['nexttagoffset'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 1612 unset($parsedFrame['data']); 1613 1614 1615 } elseif (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRM')) { // 4.20 Encrypted meta frame (ID3v2.2 only) 1616 // There may be more than one 'CRM' frame in a tag, 1617 // but only one with the same 'owner identifier' 1618 // <Header for 'Encrypted meta frame', ID: 'CRM'> 1619 // Owner identifier <textstring> $00 (00) 1620 // Content/explanation <textstring> $00 (00) 1621 // Encrypted datablock <binary data> 1622 1623 $frame_offset = 0; 1624 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1625 $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1626 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1627 1628 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1629 $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1630 $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); 1631 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1632 1633 $parsedFrame['ownerid'] = $frame_ownerid; 1634 $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); 1635 unset($parsedFrame['data']); 1636 1637 1638 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'AENC')) || // 4.19 AENC Audio encryption 1639 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRA'))) { // 4.21 CRA Audio encryption 1640 // There may be more than one 'AENC' frames in a tag, 1641 // but only one with the same 'Owner identifier' 1642 // <Header for 'Audio encryption', ID: 'AENC'> 1643 // Owner identifier <text string> $00 1644 // Preview start $xx xx 1645 // Preview length $xx xx 1646 // Encryption info <binary data> 1647 1648 $frame_offset = 0; 1649 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1650 $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1651 if ($frame_ownerid === "\x00") { 1652 $frame_ownerid = ''; 1653 } 1654 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1655 $parsedFrame['ownerid'] = $frame_ownerid; 1656 $parsedFrame['previewstart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 1657 $frame_offset += 2; 1658 $parsedFrame['previewlength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 1659 $frame_offset += 2; 1660 $parsedFrame['encryptioninfo'] = (string) substr($parsedFrame['data'], $frame_offset); 1661 unset($parsedFrame['data']); 1662 1663 1664 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'LINK')) || // 4.20 LINK Linked information 1665 (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) { // 4.22 LNK Linked information 1666 // There may be more than one 'LINK' frame in a tag, 1667 // but only one with the same contents 1668 // <Header for 'Linked information', ID: 'LINK'> 1669 // ID3v2.3+ => Frame identifier $xx xx xx xx 1670 // ID3v2.2 => Frame identifier $xx xx xx 1671 // URL <text string> $00 1672 // ID and additional data <text string(s)> 1673 1674 $frame_offset = 0; 1675 if ($id3v2_majorversion == 2) { 1676 $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 3); 1677 $frame_offset += 3; 1678 } else { 1679 $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 4); 1680 $frame_offset += 4; 1681 } 1682 1683 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1684 $frame_url = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1685 if ($frame_url === "\x00") { 1686 $frame_url = ''; 1687 } 1688 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1689 $parsedFrame['url'] = $frame_url; 1690 1691 $parsedFrame['additionaldata'] = (string) substr($parsedFrame['data'], $frame_offset); 1692 if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { 1693 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback_iso88591_utf8($parsedFrame['url']); 1694 } 1695 unset($parsedFrame['data']); 1696 1697 1698 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POSS')) { // 4.21 POSS Position synchronisation frame (ID3v2.3+ only) 1699 // There may only be one 'POSS' frame in each tag 1700 // <Head for 'Position synchronisation', ID: 'POSS'> 1701 // Time stamp format $xx 1702 // Position $xx (xx ...) 1703 1704 $frame_offset = 0; 1705 $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1706 $parsedFrame['position'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); 1707 unset($parsedFrame['data']); 1708 1709 1710 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USER')) { // 4.22 USER Terms of use (ID3v2.3+ only) 1711 // There may be more than one 'Terms of use' frame in a tag, 1712 // but only one with the same 'Language' 1713 // <Header for 'Terms of use frame', ID: 'USER'> 1714 // Text encoding $xx 1715 // Language $xx xx xx 1716 // The actual text <text string according to encoding> 1717 1718 $frame_offset = 0; 1719 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1720 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1721 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 1722 } 1723 $frame_language = substr($parsedFrame['data'], $frame_offset, 3); 1724 $frame_offset += 3; 1725 $parsedFrame['language'] = $frame_language; 1726 $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); 1727 $parsedFrame['encodingid'] = $frame_textencoding; 1728 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 1729 1730 $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); 1731 $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding)); 1732 if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { 1733 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); 1734 } 1735 unset($parsedFrame['data']); 1736 1737 1738 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'OWNE')) { // 4.23 OWNE Ownership frame (ID3v2.3+ only) 1739 // There may only be one 'OWNE' frame in a tag 1740 // <Header for 'Ownership frame', ID: 'OWNE'> 1741 // Text encoding $xx 1742 // Price paid <text string> $00 1743 // Date of purch. <text string> 1744 // Seller <text string according to encoding> 1745 1746 $frame_offset = 0; 1747 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1748 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1749 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 1750 } 1751 $parsedFrame['encodingid'] = $frame_textencoding; 1752 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 1753 1754 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1755 $frame_pricepaid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1756 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1757 1758 $parsedFrame['pricepaid']['currencyid'] = substr($frame_pricepaid, 0, 3); 1759 $parsedFrame['pricepaid']['currency'] = $this->LookupCurrencyUnits($parsedFrame['pricepaid']['currencyid']); 1760 $parsedFrame['pricepaid']['value'] = substr($frame_pricepaid, 3); 1761 1762 $parsedFrame['purchasedate'] = substr($parsedFrame['data'], $frame_offset, 8); 1763 if ($this->IsValidDateStampString($parsedFrame['purchasedate'])) { 1764 $parsedFrame['purchasedateunix'] = mktime (0, 0, 0, substr($parsedFrame['purchasedate'], 4, 2), substr($parsedFrame['purchasedate'], 6, 2), substr($parsedFrame['purchasedate'], 0, 4)); 1765 } 1766 $frame_offset += 8; 1767 1768 $parsedFrame['seller'] = (string) substr($parsedFrame['data'], $frame_offset); 1769 $parsedFrame['seller'] = $this->RemoveStringTerminator($parsedFrame['seller'], $this->TextEncodingTerminatorLookup($frame_textencoding)); 1770 unset($parsedFrame['data']); 1771 1772 1773 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMR')) { // 4.24 COMR Commercial frame (ID3v2.3+ only) 1774 // There may be more than one 'commercial frame' in a tag, 1775 // but no two may be identical 1776 // <Header for 'Commercial frame', ID: 'COMR'> 1777 // Text encoding $xx 1778 // Price string <text string> $00 1779 // Valid until <text string> 1780 // Contact URL <text string> $00 1781 // Received as $xx 1782 // Name of seller <text string according to encoding> $00 (00) 1783 // Description <text string according to encoding> $00 (00) 1784 // Picture MIME type <string> $00 1785 // Seller logo <binary data> 1786 1787 $frame_offset = 0; 1788 $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1789 $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); 1790 if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { 1791 $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); 1792 $frame_textencoding_terminator = "\x00"; 1793 } 1794 1795 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1796 $frame_pricestring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1797 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1798 $frame_rawpricearray = explode('/', $frame_pricestring); 1799 foreach ($frame_rawpricearray as $key => $val) { 1800 $frame_currencyid = substr($val, 0, 3); 1801 $parsedFrame['price'][$frame_currencyid]['currency'] = $this->LookupCurrencyUnits($frame_currencyid); 1802 $parsedFrame['price'][$frame_currencyid]['value'] = substr($val, 3); 1803 } 1804 1805 $frame_datestring = substr($parsedFrame['data'], $frame_offset, 8); 1806 $frame_offset += 8; 1807 1808 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1809 $frame_contacturl = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1810 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1811 1812 $frame_receivedasid = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1813 1814 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1815 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 1816 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1817 } 1818 $frame_sellername = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1819 if ($frame_sellername === "\x00") { 1820 $frame_sellername = ''; 1821 } 1822 $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); 1823 1824 $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); 1825 if (substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1) === "\x00") { 1826 $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 1827 } 1828 $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1829 $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); 1830 $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); 1831 1832 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1833 $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1834 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1835 1836 $frame_sellerlogo = substr($parsedFrame['data'], $frame_offset); 1837 1838 $parsedFrame['encodingid'] = $frame_textencoding; 1839 $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); 1840 1841 $parsedFrame['pricevaliduntil'] = $frame_datestring; 1842 $parsedFrame['contacturl'] = $frame_contacturl; 1843 $parsedFrame['receivedasid'] = $frame_receivedasid; 1844 $parsedFrame['receivedas'] = $this->COMRReceivedAsLookup($frame_receivedasid); 1845 $parsedFrame['sellername'] = $frame_sellername; 1846 $parsedFrame['mime'] = $frame_mimetype; 1847 $parsedFrame['logo'] = $frame_sellerlogo; 1848 unset($parsedFrame['data']); 1849 1850 1851 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ENCR')) { // 4.25 ENCR Encryption method registration (ID3v2.3+ only) 1852 // There may be several 'ENCR' frames in a tag, 1853 // but only one containing the same symbol 1854 // and only one containing the same owner identifier 1855 // <Header for 'Encryption method registration', ID: 'ENCR'> 1856 // Owner identifier <text string> $00 1857 // Method symbol $xx 1858 // Encryption data <binary data> 1859 1860 $frame_offset = 0; 1861 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1862 $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1863 if ($frame_ownerid === "\x00") { 1864 $frame_ownerid = ''; 1865 } 1866 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1867 1868 $parsedFrame['ownerid'] = $frame_ownerid; 1869 $parsedFrame['methodsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1870 $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); 1871 1872 1873 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GRID')) { // 4.26 GRID Group identification registration (ID3v2.3+ only) 1874 1875 // There may be several 'GRID' frames in a tag, 1876 // but only one containing the same symbol 1877 // and only one containing the same owner identifier 1878 // <Header for 'Group ID registration', ID: 'GRID'> 1879 // Owner identifier <text string> $00 1880 // Group symbol $xx 1881 // Group dependent data <binary data> 1882 1883 $frame_offset = 0; 1884 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1885 $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1886 if ($frame_ownerid === "\x00") { 1887 $frame_ownerid = ''; 1888 } 1889 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1890 1891 $parsedFrame['ownerid'] = $frame_ownerid; 1892 $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1893 $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); 1894 1895 1896 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PRIV')) { // 4.27 PRIV Private frame (ID3v2.3+ only) 1897 // The tag may contain more than one 'PRIV' frame 1898 // but only with different contents 1899 // <Header for 'Private frame', ID: 'PRIV'> 1900 // Owner identifier <text string> $00 1901 // The private data <binary data> 1902 1903 $frame_offset = 0; 1904 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); 1905 $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); 1906 if ($frame_ownerid === "\x00") { 1907 $frame_ownerid = ''; 1908 } 1909 $frame_offset = $frame_terminatorpos + strlen("\x00"); 1910 1911 $parsedFrame['ownerid'] = $frame_ownerid; 1912 $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); 1913 1914 1915 } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SIGN')) { // 4.28 SIGN Signature frame (ID3v2.4+ only) 1916 // There may be more than one 'signature frame' in a tag, 1917 // but no two may be identical 1918 // <Header for 'Signature frame', ID: 'SIGN'> 1919 // Group symbol $xx 1920 // Signature <binary data> 1921 1922 $frame_offset = 0; 1923 $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1924 $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); 1925 1926 1927 } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SEEK')) { // 4.29 SEEK Seek frame (ID3v2.4+ only) 1928 // There may only be one 'seek frame' in a tag 1929 // <Header for 'Seek frame', ID: 'SEEK'> 1930 // Minimum offset to next tag $xx xx xx xx 1931 1932 $frame_offset = 0; 1933 $parsedFrame['data'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 1934 1935 1936 } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'ASPI')) { // 4.30 ASPI Audio seek point index (ID3v2.4+ only) 1937 // There may only be one 'audio seek point index' frame in a tag 1938 // <Header for 'Seek Point Index', ID: 'ASPI'> 1939 // Indexed data start (S) $xx xx xx xx 1940 // Indexed data length (L) $xx xx xx xx 1941 // Number of index points (N) $xx xx 1942 // Bits per index point (b) $xx 1943 // Then for every index point the following data is included: 1944 // Fraction at index (Fi) $xx (xx) 1945 1946 $frame_offset = 0; 1947 $parsedFrame['datastart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 1948 $frame_offset += 4; 1949 $parsedFrame['indexeddatalength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 1950 $frame_offset += 4; 1951 $parsedFrame['indexpoints'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 1952 $frame_offset += 2; 1953 $parsedFrame['bitsperpoint'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); 1954 $frame_bytesperpoint = ceil($parsedFrame['bitsperpoint'] / 8); 1955 for ($i = 0; $i < $parsedFrame['indexpoints']; $i++) { 1956 $parsedFrame['indexes'][$i] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesperpoint)); 1957 $frame_offset += $frame_bytesperpoint; 1958 } 1959 unset($parsedFrame['data']); 1960 1961 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RGAD')) { // Replay Gain Adjustment 1962 // http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html 1963 // There may only be one 'RGAD' frame in a tag 1964 // <Header for 'Replay Gain Adjustment', ID: 'RGAD'> 1965 // Peak Amplitude $xx $xx $xx $xx 1966 // Radio Replay Gain Adjustment %aaabbbcd %dddddddd 1967 // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd 1968 // a - name code 1969 // b - originator code 1970 // c - sign bit 1971 // d - replay gain adjustment 1972 1973 $frame_offset = 0; 1974 $parsedFrame['peakamplitude'] = getid3_lib::BigEndian2Float(substr($parsedFrame['data'], $frame_offset, 4)); 1975 $frame_offset += 4; 1976 foreach (array('track','album') as $rgad_entry_type) { 1977 $rg_adjustment_word = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 1978 $frame_offset += 2; 1979 $parsedFrame['raw'][$rgad_entry_type]['name'] = ($rg_adjustment_word & 0xE000) >> 13; 1980 $parsedFrame['raw'][$rgad_entry_type]['originator'] = ($rg_adjustment_word & 0x1C00) >> 10; 1981 $parsedFrame['raw'][$rgad_entry_type]['signbit'] = ($rg_adjustment_word & 0x0200) >> 9; 1982 $parsedFrame['raw'][$rgad_entry_type]['adjustment'] = ($rg_adjustment_word & 0x0100); 1983 } 1984 $parsedFrame['track']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['track']['name']); 1985 $parsedFrame['track']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['track']['originator']); 1986 $parsedFrame['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['track']['adjustment'], $parsedFrame['raw']['track']['signbit']); 1987 $parsedFrame['album']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['album']['name']); 1988 $parsedFrame['album']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['album']['originator']); 1989 $parsedFrame['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['album']['adjustment'], $parsedFrame['raw']['album']['signbit']); 1990 1991 $info['replay_gain']['track']['peak'] = $parsedFrame['peakamplitude']; 1992 $info['replay_gain']['track']['originator'] = $parsedFrame['track']['originator']; 1993 $info['replay_gain']['track']['adjustment'] = $parsedFrame['track']['adjustment']; 1994 $info['replay_gain']['album']['originator'] = $parsedFrame['album']['originator']; 1995 $info['replay_gain']['album']['adjustment'] = $parsedFrame['album']['adjustment']; 1996 1997 unset($parsedFrame['data']); 1998 1999 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CHAP')) { // CHAP Chapters frame (ID3v2.3+ only) 2000 // http://id3.org/id3v2-chapters-1.0 2001 // <ID3v2.3 or ID3v2.4 frame header, ID: "CHAP"> (10 bytes) 2002 // Element ID <text string> $00 2003 // Start time $xx xx xx xx 2004 // End time $xx xx xx xx 2005 // Start offset $xx xx xx xx 2006 // End offset $xx xx xx xx 2007 // <Optional embedded sub-frames> 2008 2009 $frame_offset = 0; 2010 list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); 2011 $frame_offset += strlen($parsedFrame['element_id']."\x00"); 2012 $parsedFrame['time_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 2013 $frame_offset += 4; 2014 $parsedFrame['time_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 2015 $frame_offset += 4; 2016 if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { 2017 // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." 2018 $parsedFrame['offset_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 2019 } 2020 $frame_offset += 4; 2021 if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { 2022 // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." 2023 $parsedFrame['offset_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 2024 } 2025 $frame_offset += 4; 2026 2027 if ($frame_offset < strlen($parsedFrame['data'])) { 2028 $parsedFrame['subframes'] = array(); 2029 while ($frame_offset < strlen($parsedFrame['data'])) { 2030 // <Optional embedded sub-frames> 2031 $subframe = array(); 2032 $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); 2033 $frame_offset += 4; 2034 $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 2035 $frame_offset += 4; 2036 $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 2037 $frame_offset += 2; 2038 if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { 2039 $this->warning('CHAP subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'); 2040 break; 2041 } 2042 $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); 2043 $frame_offset += $subframe['size']; 2044 2045 $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); 2046 $subframe['text'] = substr($subframe_rawdata, 1); 2047 $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); 2048 $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text'])); 2049 switch (substr($encoding_converted_text, 0, 2)) { 2050 case "\xFF\xFE": 2051 case "\xFE\xFF": 2052 switch (strtoupper($info['id3v2']['encoding'])) { 2053 case 'ISO-8859-1': 2054 case 'UTF-8': 2055 $encoding_converted_text = substr($encoding_converted_text, 2); 2056 // remove unwanted byte-order-marks 2057 break; 2058 default: 2059 // ignore 2060 break; 2061 } 2062 break; 2063 default: 2064 // do not remove BOM 2065 break; 2066 } 2067 2068 switch ($subframe['name']) { 2069 case 'TIT2': 2070 $parsedFrame['chapter_name'] = $encoding_converted_text; 2071 $parsedFrame['subframes'][] = $subframe; 2072 break; 2073 case 'TIT3': 2074 $parsedFrame['chapter_description'] = $encoding_converted_text; 2075 $parsedFrame['subframes'][] = $subframe; 2076 break; 2077 case 'WXXX': 2078 list($subframe['chapter_url_description'], $subframe['chapter_url']) = array_pad(explode("\x00", $encoding_converted_text, 2), 2, ''); 2079 $parsedFrame['chapter_url'][$subframe['chapter_url_description']] = $subframe['chapter_url']; 2080 $parsedFrame['subframes'][] = $subframe; 2081 break; 2082 case 'APIC': 2083 if (preg_match('#^([^\\x00]+)*\\x00(.)([^\\x00]+)*\\x00(.+)$#s', $subframe['text'], $matches)) { 2084 list($dummy, $subframe_apic_mime, $subframe_apic_picturetype, $subframe_apic_description, $subframe_apic_picturedata) = $matches; 2085 $subframe['image_mime'] = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe_apic_mime)); 2086 $subframe['picture_type'] = $this->APICPictureTypeLookup($subframe_apic_picturetype); 2087 $subframe['description'] = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe_apic_description)); 2088 if (strlen($this->TextEncodingTerminatorLookup($subframe['encoding'])) == 2) { 2089 // the null terminator between "description" and "picture data" could be either 1 byte (ISO-8859-1, UTF-8) or two bytes (UTF-16) 2090 // the above regex assumes one byte, if it's actually two then strip the second one here 2091 $subframe_apic_picturedata = substr($subframe_apic_picturedata, 1); 2092 } 2093 $subframe['data'] = $subframe_apic_picturedata; 2094 unset($dummy, $subframe_apic_mime, $subframe_apic_picturetype, $subframe_apic_description, $subframe_apic_picturedata); 2095 unset($subframe['text'], $parsedFrame['text']); 2096 $parsedFrame['subframes'][] = $subframe; 2097 $parsedFrame['picture_present'] = true; 2098 } else { 2099 $this->warning('ID3v2.CHAP subframe #'.(count($parsedFrame['subframes']) + 1).' "'.$subframe['name'].'" not in expected format'); 2100 } 2101 break; 2102 default: 2103 $this->warning('ID3v2.CHAP subframe "'.$subframe['name'].'" not handled (supported: TIT2, TIT3, WXXX, APIC)'); 2104 break; 2105 } 2106 } 2107 unset($subframe_rawdata, $subframe, $encoding_converted_text); 2108 unset($parsedFrame['data']); // debatable whether this this be here, without it the returned structure may contain a large amount of duplicate data if chapters contain APIC 2109 } 2110 2111 $id3v2_chapter_entry = array(); 2112 foreach (array('id', 'time_begin', 'time_end', 'offset_begin', 'offset_end', 'chapter_name', 'chapter_description', 'chapter_url', 'picture_present') as $id3v2_chapter_key) { 2113 if (isset($parsedFrame[$id3v2_chapter_key])) { 2114 $id3v2_chapter_entry[$id3v2_chapter_key] = $parsedFrame[$id3v2_chapter_key]; 2115 } 2116 } 2117 if (!isset($info['id3v2']['chapters'])) { 2118 $info['id3v2']['chapters'] = array(); 2119 } 2120 $info['id3v2']['chapters'][] = $id3v2_chapter_entry; 2121 unset($id3v2_chapter_entry, $id3v2_chapter_key); 2122 2123 2124 } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CTOC')) { // CTOC Chapters Table Of Contents frame (ID3v2.3+ only) 2125 // http://id3.org/id3v2-chapters-1.0 2126 // <ID3v2.3 or ID3v2.4 frame header, ID: "CTOC"> (10 bytes) 2127 // Element ID <text string> $00 2128 // CTOC flags %xx 2129 // Entry count $xx 2130 // Child Element ID <string>$00 /* zero or more child CHAP or CTOC entries */ 2131 // <Optional embedded sub-frames> 2132 2133 $frame_offset = 0; 2134 list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); 2135 $frame_offset += strlen($parsedFrame['element_id']."\x00"); 2136 $ctoc_flags_raw = ord(substr($parsedFrame['data'], $frame_offset, 1)); 2137 $frame_offset += 1; 2138 $parsedFrame['entry_count'] = ord(substr($parsedFrame['data'], $frame_offset, 1)); 2139 $frame_offset += 1; 2140 2141 $terminator_position = null; 2142 for ($i = 0; $i < $parsedFrame['entry_count']; $i++) { 2143 $terminator_position = strpos($parsedFrame['data'], "\x00", $frame_offset); 2144 $parsedFrame['child_element_ids'][$i] = substr($parsedFrame['data'], $frame_offset, $terminator_position - $frame_offset); 2145 $frame_offset = $terminator_position + 1; 2146 } 2147 2148 $parsedFrame['ctoc_flags']['ordered'] = (bool) ($ctoc_flags_raw & 0x01); 2149 $parsedFrame['ctoc_flags']['top_level'] = (bool) ($ctoc_flags_raw & 0x03); 2150 2151 unset($ctoc_flags_raw, $terminator_position); 2152 2153 if ($frame_offset < strlen($parsedFrame['data'])) { 2154 $parsedFrame['subframes'] = array(); 2155 while ($frame_offset < strlen($parsedFrame['data'])) { 2156 // <Optional embedded sub-frames> 2157 $subframe = array(); 2158 $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); 2159 $frame_offset += 4; 2160 $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); 2161 $frame_offset += 4; 2162 $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); 2163 $frame_offset += 2; 2164 if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { 2165 $this->warning('CTOS subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'); 2166 break; 2167 } 2168 $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); 2169 $frame_offset += $subframe['size']; 2170 2171 $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); 2172 $subframe['text'] = substr($subframe_rawdata, 1); 2173 $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); 2174 $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));; 2175 switch (substr($encoding_converted_text, 0, 2)) { 2176 case "\xFF\xFE": 2177 case "\xFE\xFF": 2178 switch (strtoupper($info['id3v2']['encoding'])) { 2179 case 'ISO-8859-1': 2180 case 'UTF-8': 2181 $encoding_converted_text = substr($encoding_converted_text, 2); 2182 // remove unwanted byte-order-marks 2183 break; 2184 default: 2185 // ignore 2186 break; 2187 } 2188 break; 2189 default: 2190 // do not remove BOM 2191 break; 2192 } 2193 2194 if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { 2195 if ($subframe['name'] == 'TIT2') { 2196 $parsedFrame['toc_name'] = $encoding_converted_text; 2197 } elseif ($subframe['name'] == 'TIT3') { 2198 $parsedFrame['toc_description'] = $encoding_converted_text; 2199 } 2200 $parsedFrame['subframes'][] = $subframe; 2201 } else { 2202 $this->warning('ID3v2.CTOC subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'); 2203 } 2204 } 2205 unset($subframe_rawdata, $subframe, $encoding_converted_text); 2206 } 2207 2208 } 2209 2210 return true; 2211 } 2212 2213 /** 2214 * @param string $data 2215 * 2216 * @return string 2217 */ 2218 public function DeUnsynchronise($data) { 2219 return str_replace("\xFF\x00", "\xFF", $data); 2220 } 2221 2222 /** 2223 * @param int $index 2224 * 2225 * @return string 2226 */ 2227 public function LookupExtendedHeaderRestrictionsTagSizeLimits($index) { 2228 static $LookupExtendedHeaderRestrictionsTagSizeLimits = array( 2229 0x00 => 'No more than 128 frames and 1 MB total tag size', 2230 0x01 => 'No more than 64 frames and 128 KB total tag size', 2231 0x02 => 'No more than 32 frames and 40 KB total tag size', 2232 0x03 => 'No more than 32 frames and 4 KB total tag size', 2233 ); 2234 return (isset($LookupExtendedHeaderRestrictionsTagSizeLimits[$index]) ? $LookupExtendedHeaderRestrictionsTagSizeLimits[$index] : ''); 2235 } 2236 2237 /** 2238 * @param int $index 2239 * 2240 * @return string 2241 */ 2242 public function LookupExtendedHeaderRestrictionsTextEncodings($index) { 2243 static $LookupExtendedHeaderRestrictionsTextEncodings = array( 2244 0x00 => 'No restrictions', 2245 0x01 => 'Strings are only encoded with ISO-8859-1 or UTF-8', 2246 ); 2247 return (isset($LookupExtendedHeaderRestrictionsTextEncodings[$index]) ? $LookupExtendedHeaderRestrictionsTextEncodings[$index] : ''); 2248 } 2249 2250 /** 2251 * @param int $index 2252 * 2253 * @return string 2254 */ 2255 public function LookupExtendedHeaderRestrictionsTextFieldSize($index) { 2256 static $LookupExtendedHeaderRestrictionsTextFieldSize = array( 2257 0x00 => 'No restrictions', 2258 0x01 => 'No string is longer than 1024 characters', 2259 0x02 => 'No string is longer than 128 characters', 2260 0x03 => 'No string is longer than 30 characters', 2261 ); 2262 return (isset($LookupExtendedHeaderRestrictionsTextFieldSize[$index]) ? $LookupExtendedHeaderRestrictionsTextFieldSize[$index] : ''); 2263 } 2264 2265 /** 2266 * @param int $index 2267 * 2268 * @return string 2269 */ 2270 public function LookupExtendedHeaderRestrictionsImageEncoding($index) { 2271 static $LookupExtendedHeaderRestrictionsImageEncoding = array( 2272 0x00 => 'No restrictions', 2273 0x01 => 'Images are encoded only with PNG or JPEG', 2274 ); 2275 return (isset($LookupExtendedHeaderRestrictionsImageEncoding[$index]) ? $LookupExtendedHeaderRestrictionsImageEncoding[$index] : ''); 2276 } 2277 2278 /** 2279 * @param int $index 2280 * 2281 * @return string 2282 */ 2283 public function LookupExtendedHeaderRestrictionsImageSizeSize($index) { 2284 static $LookupExtendedHeaderRestrictionsImageSizeSize = array( 2285 0x00 => 'No restrictions', 2286 0x01 => 'All images are 256x256 pixels or smaller', 2287 0x02 => 'All images are 64x64 pixels or smaller', 2288 0x03 => 'All images are exactly 64x64 pixels, unless required otherwise', 2289 ); 2290 return (isset($LookupExtendedHeaderRestrictionsImageSizeSize[$index]) ? $LookupExtendedHeaderRestrictionsImageSizeSize[$index] : ''); 2291 } 2292 2293 /** 2294 * @param string $currencyid 2295 * 2296 * @return string 2297 */ 2298 public function LookupCurrencyUnits($currencyid) { 2299 2300 $begin = __LINE__; 2301 2302 /** This is not a comment! 2303 2304 2305 AED Dirhams 2306 AFA Afghanis 2307 ALL Leke 2308 AMD Drams 2309 ANG Guilders 2310 AOA Kwanza 2311 ARS Pesos 2312 ATS Schillings 2313 AUD Dollars 2314 AWG Guilders 2315 AZM Manats 2316 BAM Convertible Marka 2317 BBD Dollars 2318 BDT Taka 2319 BEF Francs 2320 BGL Leva 2321 BHD Dinars 2322 BIF Francs 2323 BMD Dollars 2324 BND Dollars 2325 BOB Bolivianos 2326 BRL Brazil Real 2327 BSD Dollars 2328 BTN Ngultrum 2329 BWP Pulas 2330 BYR Rubles 2331 BZD Dollars 2332 CAD Dollars 2333 CDF Congolese Francs 2334 CHF Francs 2335 CLP Pesos 2336 CNY Yuan Renminbi 2337 COP Pesos 2338 CRC Colones 2339 CUP Pesos 2340 CVE Escudos 2341 CYP Pounds 2342 CZK Koruny 2343 DEM Deutsche Marks 2344 DJF Francs 2345 DKK Kroner 2346 DOP Pesos 2347 DZD Algeria Dinars 2348 EEK Krooni 2349 EGP Pounds 2350 ERN Nakfa 2351 ESP Pesetas 2352 ETB Birr 2353 EUR Euro 2354 FIM Markkaa 2355 FJD Dollars 2356 FKP Pounds 2357 FRF Francs 2358 GBP Pounds 2359 GEL Lari 2360 GGP Pounds 2361 GHC Cedis 2362 GIP Pounds 2363 GMD Dalasi 2364 GNF Francs 2365 GRD Drachmae 2366 GTQ Quetzales 2367 GYD Dollars 2368 HKD Dollars 2369 HNL Lempiras 2370 HRK Kuna 2371 HTG Gourdes 2372 HUF Forints 2373 IDR Rupiahs 2374 IEP Pounds 2375 ILS New Shekels 2376 IMP Pounds 2377 INR Rupees 2378 IQD Dinars 2379 IRR Rials 2380 ISK Kronur 2381 ITL Lire 2382 JEP Pounds 2383 JMD Dollars 2384 JOD Dinars 2385 JPY Yen 2386 KES Shillings 2387 KGS Soms 2388 KHR Riels 2389 KMF Francs 2390 KPW Won 2391 KWD Dinars 2392 KYD Dollars 2393 KZT Tenge 2394 LAK Kips 2395 LBP Pounds 2396 LKR Rupees 2397 LRD Dollars 2398 LSL Maloti 2399 LTL Litai 2400 LUF Francs 2401 LVL Lati 2402 LYD Dinars 2403 MAD Dirhams 2404 MDL Lei 2405 MGF Malagasy Francs 2406 MKD Denars 2407 MMK Kyats 2408 MNT Tugriks 2409 MOP Patacas 2410 MRO Ouguiyas 2411 MTL Liri 2412 MUR Rupees 2413 MVR Rufiyaa 2414 MWK Kwachas 2415 MXN Pesos 2416 MYR Ringgits 2417 MZM Meticais 2418 NAD Dollars 2419 NGN Nairas 2420 NIO Gold Cordobas 2421 NLG Guilders 2422 NOK Krone 2423 NPR Nepal Rupees 2424 NZD Dollars 2425 OMR Rials 2426 PAB Balboa 2427 PEN Nuevos Soles 2428 PGK Kina 2429 PHP Pesos 2430 PKR Rupees 2431 PLN Zlotych 2432 PTE Escudos 2433 PYG Guarani 2434 QAR Rials 2435 ROL Lei 2436 RUR Rubles 2437 RWF Rwanda Francs 2438 SAR Riyals 2439 SBD Dollars 2440 SCR Rupees 2441 SDD Dinars 2442 SEK Kronor 2443 SGD Dollars 2444 SHP Pounds 2445 SIT Tolars 2446 SKK Koruny 2447 SLL Leones 2448 SOS Shillings 2449 SPL Luigini 2450 SRG Guilders 2451 STD Dobras 2452 SVC Colones 2453 SYP Pounds 2454 SZL Emalangeni 2455 THB Baht 2456 TJR Rubles 2457 TMM Manats 2458 TND Dinars 2459 TOP Pa'anga 2460 TRL Liras (old) 2461 TRY Liras 2462 TTD Dollars 2463 TVD Tuvalu Dollars 2464 TWD New Dollars 2465 TZS Shillings 2466 UAH Hryvnia 2467 UGX Shillings 2468 USD Dollars 2469 UYU Pesos 2470 UZS Sums 2471 VAL Lire 2472 VEB Bolivares 2473 VND Dong 2474 VUV Vatu 2475 WST Tala 2476 XAF Francs 2477 XAG Ounces 2478 XAU Ounces 2479 XCD Dollars 2480 XDR Special Drawing Rights 2481 XPD Ounces 2482 XPF Francs 2483 XPT Ounces 2484 YER Rials 2485 YUM New Dinars 2486 ZAR Rand 2487 ZMK Kwacha 2488 ZWD Zimbabwe Dollars 2489 2490 */ 2491 2492 return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-units'); 2493 } 2494 2495 /** 2496 * @param string $currencyid 2497 * 2498 * @return string 2499 */ 2500 public function LookupCurrencyCountry($currencyid) { 2501 2502 $begin = __LINE__; 2503 2504 /** This is not a comment! 2505 2506 AED United Arab Emirates 2507 AFA Afghanistan 2508 ALL Albania 2509 AMD Armenia 2510 ANG Netherlands Antilles 2511 AOA Angola 2512 ARS Argentina 2513 ATS Austria 2514 AUD Australia 2515 AWG Aruba 2516 AZM Azerbaijan 2517 BAM Bosnia and Herzegovina 2518 BBD Barbados 2519 BDT Bangladesh 2520 BEF Belgium 2521 BGL Bulgaria 2522 BHD Bahrain 2523 BIF Burundi 2524 BMD Bermuda 2525 BND Brunei Darussalam 2526 BOB Bolivia 2527 BRL Brazil 2528 BSD Bahamas 2529 BTN Bhutan 2530 BWP Botswana 2531 BYR Belarus 2532 BZD Belize 2533 CAD Canada 2534 CDF Congo/Kinshasa 2535 CHF Switzerland 2536 CLP Chile 2537 CNY China 2538 COP Colombia 2539 CRC Costa Rica 2540 CUP Cuba 2541 CVE Cape Verde 2542 CYP Cyprus 2543 CZK Czech Republic 2544 DEM Germany 2545 DJF Djibouti 2546 DKK Denmark 2547 DOP Dominican Republic 2548 DZD Algeria 2549 EEK Estonia 2550 EGP Egypt 2551 ERN Eritrea 2552 ESP Spain 2553 ETB Ethiopia 2554 EUR Euro Member Countries 2555 FIM Finland 2556 FJD Fiji 2557 FKP Falkland Islands (Malvinas) 2558 FRF France 2559 GBP United Kingdom 2560 GEL Georgia 2561 GGP Guernsey 2562 GHC Ghana 2563 GIP Gibraltar 2564 GMD Gambia 2565 GNF Guinea 2566 GRD Greece 2567 GTQ Guatemala 2568 GYD Guyana 2569 HKD Hong Kong 2570 HNL Honduras 2571 HRK Croatia 2572 HTG Haiti 2573 HUF Hungary 2574 IDR Indonesia 2575 IEP Ireland (Eire) 2576 ILS Israel 2577 IMP Isle of Man 2578 INR India 2579 IQD Iraq 2580 IRR Iran 2581 ISK Iceland 2582 ITL Italy 2583 JEP Jersey 2584 JMD Jamaica 2585 JOD Jordan 2586 JPY Japan 2587 KES Kenya 2588 KGS Kyrgyzstan 2589 KHR Cambodia 2590 KMF Comoros 2591 KPW Korea 2592 KWD Kuwait 2593 KYD Cayman Islands 2594 KZT Kazakstan 2595 LAK Laos 2596 LBP Lebanon 2597 LKR Sri Lanka 2598 LRD Liberia 2599 LSL Lesotho 2600 LTL Lithuania 2601 LUF Luxembourg 2602 LVL Latvia 2603 LYD Libya 2604 MAD Morocco 2605 MDL Moldova 2606 MGF Madagascar 2607 MKD Macedonia 2608 MMK Myanmar (Burma) 2609 MNT Mongolia 2610 MOP Macau 2611 MRO Mauritania 2612 MTL Malta 2613 MUR Mauritius 2614 MVR Maldives (Maldive Islands) 2615 MWK Malawi 2616 MXN Mexico 2617 MYR Malaysia 2618 MZM Mozambique 2619 NAD Namibia 2620 NGN Nigeria 2621 NIO Nicaragua 2622 NLG Netherlands (Holland) 2623 NOK Norway 2624 NPR Nepal 2625 NZD New Zealand 2626 OMR Oman 2627 PAB Panama 2628 PEN Peru 2629 PGK Papua New Guinea 2630 PHP Philippines 2631 PKR Pakistan 2632 PLN Poland 2633 PTE Portugal 2634 PYG Paraguay 2635 QAR Qatar 2636 ROL Romania 2637 RUR Russia 2638 RWF Rwanda 2639 SAR Saudi Arabia 2640 SBD Solomon Islands 2641 SCR Seychelles 2642 SDD Sudan 2643 SEK Sweden 2644 SGD Singapore 2645 SHP Saint Helena 2646 SIT Slovenia 2647 SKK Slovakia 2648 SLL Sierra Leone 2649 SOS Somalia 2650 SPL Seborga 2651 SRG Suriname 2652 STD São Tome and Principe 2653 SVC El Salvador 2654 SYP Syria 2655 SZL Swaziland 2656 THB Thailand 2657 TJR Tajikistan 2658 TMM Turkmenistan 2659 TND Tunisia 2660 TOP Tonga 2661 TRL Turkey 2662 TRY Turkey 2663 TTD Trinidad and Tobago 2664 TVD Tuvalu 2665 TWD Taiwan 2666 TZS Tanzania 2667 UAH Ukraine 2668 UGX Uganda 2669 USD United States of America 2670 UYU Uruguay 2671 UZS Uzbekistan 2672 VAL Vatican City 2673 VEB Venezuela 2674 VND Viet Nam 2675 VUV Vanuatu 2676 WST Samoa 2677 XAF Communauté Financière Africaine 2678 XAG Silver 2679 XAU Gold 2680 XCD East Caribbean 2681 XDR International Monetary Fund 2682 XPD Palladium 2683 XPF Comptoirs Français du Pacifique 2684 XPT Platinum 2685 YER Yemen 2686 YUM Yugoslavia 2687 ZAR South Africa 2688 ZMK Zambia 2689 ZWD Zimbabwe 2690 2691 */ 2692 2693 return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-country'); 2694 } 2695 2696 /** 2697 * @param string $languagecode 2698 * @param bool $casesensitive 2699 * 2700 * @return string 2701 */ 2702 public static function LanguageLookup($languagecode, $casesensitive=false) { 2703 2704 if (!$casesensitive) { 2705 $languagecode = strtolower($languagecode); 2706 } 2707 2708 // http://www.id3.org/id3v2.4.0-structure.txt 2709 // [4. ID3v2 frame overview] 2710 // The three byte language field, present in several frames, is used to 2711 // describe the language of the frame's content, according to ISO-639-2 2712 // [ISO-639-2]. The language should be represented in lower case. If the 2713 // language is not known the string "XXX" should be used. 2714 2715 2716 // ISO 639-2 - http://www.id3.org/iso639-2.html 2717 2718 $begin = __LINE__; 2719 2720 /** This is not a comment! 2721 2722 XXX unknown 2723 xxx unknown 2724 aar Afar 2725 abk Abkhazian 2726 ace Achinese 2727 ach Acoli 2728 ada Adangme 2729 afa Afro-Asiatic (Other) 2730 afh Afrihili 2731 afr Afrikaans 2732 aka Akan 2733 akk Akkadian 2734 alb Albanian 2735 ale Aleut 2736 alg Algonquian Languages 2737 amh Amharic 2738 ang English, Old (ca. 450-1100) 2739 apa Apache Languages 2740 ara Arabic 2741 arc Aramaic 2742 arm Armenian 2743 arn Araucanian 2744 arp Arapaho 2745 art Artificial (Other) 2746 arw Arawak 2747 asm Assamese 2748 ath Athapascan Languages 2749 ava Avaric 2750 ave Avestan 2751 awa Awadhi 2752 aym Aymara 2753 aze Azerbaijani 2754 bad Banda 2755 bai Bamileke Languages 2756 bak Bashkir 2757 bal Baluchi 2758 bam Bambara 2759 ban Balinese 2760 baq Basque 2761 bas Basa 2762 bat Baltic (Other) 2763 bej Beja 2764 bel Byelorussian 2765 bem Bemba 2766 ben Bengali 2767 ber Berber (Other) 2768 bho Bhojpuri 2769 bih Bihari 2770 bik Bikol 2771 bin Bini 2772 bis Bislama 2773 bla Siksika 2774 bnt Bantu (Other) 2775 bod Tibetan 2776 bra Braj 2777 bre Breton 2778 bua Buriat 2779 bug Buginese 2780 bul Bulgarian 2781 bur Burmese 2782 cad Caddo 2783 cai Central American Indian (Other) 2784 car Carib 2785 cat Catalan 2786 cau Caucasian (Other) 2787 ceb Cebuano 2788 cel Celtic (Other) 2789 ces Czech 2790 cha Chamorro 2791 chb Chibcha 2792 che Chechen 2793 chg Chagatai 2794 chi Chinese 2795 chm Mari 2796 chn Chinook jargon 2797 cho Choctaw 2798 chr Cherokee 2799 chu Church Slavic 2800 chv Chuvash 2801 chy Cheyenne 2802 cop Coptic 2803 cor Cornish 2804 cos Corsican 2805 cpe Creoles and Pidgins, English-based (Other) 2806 cpf Creoles and Pidgins, French-based (Other) 2807 cpp Creoles and Pidgins, Portuguese-based (Other) 2808 cre Cree 2809 crp Creoles and Pidgins (Other) 2810 cus Cushitic (Other) 2811 cym Welsh 2812 cze Czech 2813 dak Dakota 2814 dan Danish 2815 del Delaware 2816 deu German 2817 din Dinka 2818 div Divehi 2819 doi Dogri 2820 dra Dravidian (Other) 2821 dua Duala 2822 dum Dutch, Middle (ca. 1050-1350) 2823 dut Dutch 2824 dyu Dyula 2825 dzo Dzongkha 2826 efi Efik 2827 egy Egyptian (Ancient) 2828 eka Ekajuk 2829 ell Greek, Modern (1453-) 2830 elx Elamite 2831 eng English 2832 enm English, Middle (ca. 1100-1500) 2833 epo Esperanto 2834 esk Eskimo (Other) 2835 esl Spanish 2836 est Estonian 2837 eus Basque 2838 ewe Ewe 2839 ewo Ewondo 2840 fan Fang 2841 fao Faroese 2842 fas Persian 2843 fat Fanti 2844 fij Fijian 2845 fin Finnish 2846 fiu Finno-Ugrian (Other) 2847 fon Fon 2848 fra French 2849 fre French 2850 frm French, Middle (ca. 1400-1600) 2851 fro French, Old (842- ca. 1400) 2852 fry Frisian 2853 ful Fulah 2854 gaa Ga 2855 gae Gaelic (Scots) 2856 gai Irish 2857 gay Gayo 2858 gdh Gaelic (Scots) 2859 gem Germanic (Other) 2860 geo Georgian 2861 ger German 2862 gez Geez 2863 gil Gilbertese 2864 glg Gallegan 2865 gmh German, Middle High (ca. 1050-1500) 2866 goh German, Old High (ca. 750-1050) 2867 gon Gondi 2868 got Gothic 2869 grb Grebo 2870 grc Greek, Ancient (to 1453) 2871 gre Greek, Modern (1453-) 2872 grn Guarani 2873 guj Gujarati 2874 hai Haida 2875 hau Hausa 2876 haw Hawaiian 2877 heb Hebrew 2878 her Herero 2879 hil Hiligaynon 2880 him Himachali 2881 hin Hindi 2882 hmo Hiri Motu 2883 hun Hungarian 2884 hup Hupa 2885 hye Armenian 2886 iba Iban 2887 ibo Igbo 2888 ice Icelandic 2889 ijo Ijo 2890 iku Inuktitut 2891 ilo Iloko 2892 ina Interlingua (International Auxiliary language Association) 2893 inc Indic (Other) 2894 ind Indonesian 2895 ine Indo-European (Other) 2896 ine Interlingue 2897 ipk Inupiak 2898 ira Iranian (Other) 2899 iri Irish 2900 iro Iroquoian uages 2901 isl Icelandic 2902 ita Italian 2903 jav Javanese 2904 jaw Javanese 2905 jpn Japanese 2906 jpr Judeo-Persian 2907 jrb Judeo-Arabic 2908 kaa Kara-Kalpak 2909 kab Kabyle 2910 kac Kachin 2911 kal Greenlandic 2912 kam Kamba 2913 kan Kannada 2914 kar Karen 2915 kas Kashmiri 2916 kat Georgian 2917 kau Kanuri 2918 kaw Kawi 2919 kaz Kazakh 2920 kha Khasi 2921 khi Khoisan (Other) 2922 khm Khmer 2923 kho Khotanese 2924 kik Kikuyu 2925 kin Kinyarwanda 2926 kir Kirghiz 2927 kok Konkani 2928 kom Komi 2929 kon Kongo 2930 kor Korean 2931 kpe Kpelle 2932 kro Kru 2933 kru Kurukh 2934 kua Kuanyama 2935 kum Kumyk 2936 kur Kurdish 2937 kus Kusaie 2938 kut Kutenai 2939 lad Ladino 2940 lah Lahnda 2941 lam Lamba 2942 lao Lao 2943 lat Latin 2944 lav Latvian 2945 lez Lezghian 2946 lin Lingala 2947 lit Lithuanian 2948 lol Mongo 2949 loz Lozi 2950 ltz Letzeburgesch 2951 lub Luba-Katanga 2952 lug Ganda 2953 lui Luiseno 2954 lun Lunda 2955 luo Luo (Kenya and Tanzania) 2956 mac Macedonian 2957 mad Madurese 2958 mag Magahi 2959 mah Marshall 2960 mai Maithili 2961 mak Macedonian 2962 mak Makasar 2963 mal Malayalam 2964 man Mandingo 2965 mao Maori 2966 map Austronesian (Other) 2967 mar Marathi 2968 mas Masai 2969 max Manx 2970 may Malay 2971 men Mende 2972 mga Irish, Middle (900 - 1200) 2973 mic Micmac 2974 min Minangkabau 2975 mis Miscellaneous (Other) 2976 mkh Mon-Kmer (Other) 2977 mlg Malagasy 2978 mlt Maltese 2979 mni Manipuri 2980 mno Manobo Languages 2981 moh Mohawk 2982 mol Moldavian 2983 mon Mongolian 2984 mos Mossi 2985 mri Maori 2986 msa Malay 2987 mul Multiple Languages 2988 mun Munda Languages 2989 mus Creek 2990 mwr Marwari 2991 mya Burmese 2992 myn Mayan Languages 2993 nah Aztec 2994 nai North American Indian (Other) 2995 nau Nauru 2996 nav Navajo 2997 nbl Ndebele, South 2998 nde Ndebele, North 2999 ndo Ndongo 3000 nep Nepali 3001 new Newari 3002 nic Niger-Kordofanian (Other) 3003 niu Niuean 3004 nla Dutch 3005 nno Norwegian (Nynorsk) 3006 non Norse, Old 3007 nor Norwegian 3008 nso Sotho, Northern 3009 nub Nubian Languages 3010 nya Nyanja 3011 nym Nyamwezi 3012 nyn Nyankole 3013 nyo Nyoro 3014 nzi Nzima 3015 oci Langue d'Oc (post 1500) 3016 oji Ojibwa 3017 ori Oriya 3018 orm Oromo 3019 osa Osage 3020 oss Ossetic 3021 ota Turkish, Ottoman (1500 - 1928) 3022 oto Otomian Languages 3023 paa Papuan-Australian (Other) 3024 pag Pangasinan 3025 pal Pahlavi 3026 pam Pampanga 3027 pan Panjabi 3028 pap Papiamento 3029 pau Palauan 3030 peo Persian, Old (ca 600 - 400 B.C.) 3031 per Persian 3032 phn Phoenician 3033 pli Pali 3034 pol Polish 3035 pon Ponape 3036 por Portuguese 3037 pra Prakrit uages 3038 pro Provencal, Old (to 1500) 3039 pus Pushto 3040 que Quechua 3041 raj Rajasthani 3042 rar Rarotongan 3043 roa Romance (Other) 3044 roh Rhaeto-Romance 3045 rom Romany 3046 ron Romanian 3047 rum Romanian 3048 run Rundi 3049 rus Russian 3050 sad Sandawe 3051 sag Sango 3052 sah Yakut 3053 sai South American Indian (Other) 3054 sal Salishan Languages 3055 sam Samaritan Aramaic 3056 san Sanskrit 3057 sco Scots 3058 scr Serbo-Croatian 3059 sel Selkup 3060 sem Semitic (Other) 3061 sga Irish, Old (to 900) 3062 shn Shan 3063 sid Sidamo 3064 sin Singhalese 3065 sio Siouan Languages 3066 sit Sino-Tibetan (Other) 3067 sla Slavic (Other) 3068 slk Slovak 3069 slo Slovak 3070 slv Slovenian 3071 smi Sami Languages 3072 smo Samoan 3073 sna Shona 3074 snd Sindhi 3075 sog Sogdian 3076 som Somali 3077 son Songhai 3078 sot Sotho, Southern 3079 spa Spanish 3080 sqi Albanian 3081 srd Sardinian 3082 srr Serer 3083 ssa Nilo-Saharan (Other) 3084 ssw Siswant 3085 ssw Swazi 3086 suk Sukuma 3087 sun Sudanese 3088 sus Susu 3089 sux Sumerian 3090 sve Swedish 3091 swa Swahili 3092 swe Swedish 3093 syr Syriac 3094 tah Tahitian 3095 tam Tamil 3096 tat Tatar 3097 tel Telugu 3098 tem Timne 3099 ter Tereno 3100 tgk Tajik 3101 tgl Tagalog 3102 tha Thai 3103 tib Tibetan 3104 tig Tigre 3105 tir Tigrinya 3106 tiv Tivi 3107 tli Tlingit 3108 tmh Tamashek 3109 tog Tonga (Nyasa) 3110 ton Tonga (Tonga Islands) 3111 tru Truk 3112 tsi Tsimshian 3113 tsn Tswana 3114 tso Tsonga 3115 tuk Turkmen 3116 tum Tumbuka 3117 tur Turkish 3118 tut Altaic (Other) 3119 twi Twi 3120 tyv Tuvinian 3121 uga Ugaritic 3122 uig Uighur 3123 ukr Ukrainian 3124 umb Umbundu 3125 und Undetermined 3126 urd Urdu 3127 uzb Uzbek 3128 vai Vai 3129 ven Venda 3130 vie Vietnamese 3131 vol Volapük 3132 vot Votic 3133 wak Wakashan Languages 3134 wal Walamo 3135 war Waray 3136 was Washo 3137 wel Welsh 3138 wen Sorbian Languages 3139 wol Wolof 3140 xho Xhosa 3141 yao Yao 3142 yap Yap 3143 yid Yiddish 3144 yor Yoruba 3145 zap Zapotec 3146 zen Zenaga 3147 zha Zhuang 3148 zho Chinese 3149 zul Zulu 3150 zun Zuni 3151 3152 */ 3153 3154 return getid3_lib::EmbeddedLookup($languagecode, $begin, __LINE__, __FILE__, 'id3v2-languagecode'); 3155 } 3156 3157 /** 3158 * @param int $index 3159 * 3160 * @return string 3161 */ 3162 public static function ETCOEventLookup($index) { 3163 if (($index >= 0x17) && ($index <= 0xDF)) { 3164 return 'reserved for future use'; 3165 } 3166 if (($index >= 0xE0) && ($index <= 0xEF)) { 3167 return 'not predefined synch 0-F'; 3168 } 3169 if (($index >= 0xF0) && ($index <= 0xFC)) { 3170 return 'reserved for future use'; 3171 } 3172 3173 static $EventLookup = array( 3174 0x00 => 'padding (has no meaning)', 3175 0x01 => 'end of initial silence', 3176 0x02 => 'intro start', 3177 0x03 => 'main part start', 3178 0x04 => 'outro start', 3179 0x05 => 'outro end', 3180 0x06 => 'verse start', 3181 0x07 => 'refrain start', 3182 0x08 => 'interlude start', 3183 0x09 => 'theme start', 3184 0x0A => 'variation start', 3185 0x0B => 'key change', 3186 0x0C => 'time change', 3187 0x0D => 'momentary unwanted noise (Snap, Crackle & Pop)', 3188 0x0E => 'sustained noise', 3189 0x0F => 'sustained noise end', 3190 0x10 => 'intro end', 3191 0x11 => 'main part end', 3192 0x12 => 'verse end', 3193 0x13 => 'refrain end', 3194 0x14 => 'theme end', 3195 0x15 => 'profanity', 3196 0x16 => 'profanity end', 3197 0xFD => 'audio end (start of silence)', 3198 0xFE => 'audio file ends', 3199 0xFF => 'one more byte of events follows' 3200 ); 3201 3202 return (isset($EventLookup[$index]) ? $EventLookup[$index] : ''); 3203 } 3204 3205 /** 3206 * @param int $index 3207 * 3208 * @return string 3209 */ 3210 public static function SYTLContentTypeLookup($index) { 3211 static $SYTLContentTypeLookup = array( 3212 0x00 => 'other', 3213 0x01 => 'lyrics', 3214 0x02 => 'text transcription', 3215 0x03 => 'movement/part name', // (e.g. 'Adagio') 3216 0x04 => 'events', // (e.g. 'Don Quijote enters the stage') 3217 0x05 => 'chord', // (e.g. 'Bb F Fsus') 3218 0x06 => 'trivia/\'pop up\' information', 3219 0x07 => 'URLs to webpages', 3220 0x08 => 'URLs to images' 3221 ); 3222 3223 return (isset($SYTLContentTypeLookup[$index]) ? $SYTLContentTypeLookup[$index] : ''); 3224 } 3225 3226 /** 3227 * @param int $index 3228 * @param bool $returnarray 3229 * 3230 * @return array|string 3231 */ 3232 public static function APICPictureTypeLookup($index, $returnarray=false) { 3233 static $APICPictureTypeLookup = array( 3234 0x00 => 'Other', 3235 0x01 => '32x32 pixels \'file icon\' (PNG only)', 3236 0x02 => 'Other file icon', 3237 0x03 => 'Cover (front)', 3238 0x04 => 'Cover (back)', 3239 0x05 => 'Leaflet page', 3240 0x06 => 'Media (e.g. label side of CD)', 3241 0x07 => 'Lead artist/lead performer/soloist', 3242 0x08 => 'Artist/performer', 3243 0x09 => 'Conductor', 3244 0x0A => 'Band/Orchestra', 3245 0x0B => 'Composer', 3246 0x0C => 'Lyricist/text writer', 3247 0x0D => 'Recording Location', 3248 0x0E => 'During recording', 3249 0x0F => 'During performance', 3250 0x10 => 'Movie/video screen capture', 3251 0x11 => 'A bright coloured fish', 3252 0x12 => 'Illustration', 3253 0x13 => 'Band/artist logotype', 3254 0x14 => 'Publisher/Studio logotype' 3255 ); 3256 if ($returnarray) { 3257 return $APICPictureTypeLookup; 3258 } 3259 return (isset($APICPictureTypeLookup[$index]) ? $APICPictureTypeLookup[$index] : ''); 3260 } 3261 3262 /** 3263 * @param int $index 3264 * 3265 * @return string 3266 */ 3267 public static function COMRReceivedAsLookup($index) { 3268 static $COMRReceivedAsLookup = array( 3269 0x00 => 'Other', 3270 0x01 => 'Standard CD album with other songs', 3271 0x02 => 'Compressed audio on CD', 3272 0x03 => 'File over the Internet', 3273 0x04 => 'Stream over the Internet', 3274 0x05 => 'As note sheets', 3275 0x06 => 'As note sheets in a book with other sheets', 3276 0x07 => 'Music on other media', 3277 0x08 => 'Non-musical merchandise' 3278 ); 3279 3280 return (isset($COMRReceivedAsLookup[$index]) ? $COMRReceivedAsLookup[$index] : ''); 3281 } 3282 3283 /** 3284 * @param int $index 3285 * 3286 * @return string 3287 */ 3288 public static function RVA2ChannelTypeLookup($index) { 3289 static $RVA2ChannelTypeLookup = array( 3290 0x00 => 'Other', 3291 0x01 => 'Master volume', 3292 0x02 => 'Front right', 3293 0x03 => 'Front left', 3294 0x04 => 'Back right', 3295 0x05 => 'Back left', 3296 0x06 => 'Front centre', 3297 0x07 => 'Back centre', 3298 0x08 => 'Subwoofer' 3299 ); 3300 3301 return (isset($RVA2ChannelTypeLookup[$index]) ? $RVA2ChannelTypeLookup[$index] : ''); 3302 } 3303 3304 /** 3305 * @param string $framename 3306 * 3307 * @return string 3308 */ 3309 public static function FrameNameLongLookup($framename) { 3310 3311 $begin = __LINE__; 3312 3313 /** This is not a comment! 3314 3315 AENC Audio encryption 3316 APIC Attached picture 3317 ASPI Audio seek point index 3318 BUF Recommended buffer size 3319 CNT Play counter 3320 COM Comments 3321 COMM Comments 3322 COMR Commercial frame 3323 CRA Audio encryption 3324 CRM Encrypted meta frame 3325 ENCR Encryption method registration 3326 EQU Equalisation 3327 EQU2 Equalisation (2) 3328 EQUA Equalisation 3329 ETC Event timing codes 3330 ETCO Event timing codes 3331 GEO General encapsulated object 3332 GEOB General encapsulated object 3333 GRID Group identification registration 3334 IPL Involved people list 3335 IPLS Involved people list 3336 LINK Linked information 3337 LNK Linked information 3338 MCDI Music CD identifier 3339 MCI Music CD Identifier 3340 MLL MPEG location lookup table 3341 MLLT MPEG location lookup table 3342 OWNE Ownership frame 3343 PCNT Play counter 3344 PIC Attached picture 3345 POP Popularimeter 3346 POPM Popularimeter 3347 POSS Position synchronisation frame 3348 PRIV Private frame 3349 RBUF Recommended buffer size 3350 REV Reverb 3351 RVA Relative volume adjustment 3352 RVA2 Relative volume adjustment (2) 3353 RVAD Relative volume adjustment 3354 RVRB Reverb 3355 SEEK Seek frame 3356 SIGN Signature frame 3357 SLT Synchronised lyric/text 3358 STC Synced tempo codes 3359 SYLT Synchronised lyric/text 3360 SYTC Synchronised tempo codes 3361 TAL Album/Movie/Show title 3362 TALB Album/Movie/Show title 3363 TBP BPM (Beats Per Minute) 3364 TBPM BPM (beats per minute) 3365 TCM Composer 3366 TCMP Part of a compilation 3367 TCO Content type 3368 TCOM Composer 3369 TCON Content type 3370 TCOP Copyright message 3371 TCP Part of a compilation 3372 TCR Copyright message 3373 TDA Date 3374 TDAT Date 3375 TDEN Encoding time 3376 TDLY Playlist delay 3377 TDOR Original release time 3378 TDRC Recording time 3379 TDRL Release time 3380 TDTG Tagging time 3381 TDY Playlist delay 3382 TEN Encoded by 3383 TENC Encoded by 3384 TEXT Lyricist/Text writer 3385 TFLT File type 3386 TFT File type 3387 TIM Time 3388 TIME Time 3389 TIPL Involved people list 3390 TIT1 Content group description 3391 TIT2 Title/songname/content description 3392 TIT3 Subtitle/Description refinement 3393 TKE Initial key 3394 TKEY Initial key 3395 TLA Language(s) 3396 TLAN Language(s) 3397 TLE Length 3398 TLEN Length 3399 TMCL Musician credits list 3400 TMED Media type 3401 TMOO Mood 3402 TMT Media type 3403 TOA Original artist(s)/performer(s) 3404 TOAL Original album/movie/show title 3405 TOF Original filename 3406 TOFN Original filename 3407 TOL Original Lyricist(s)/text writer(s) 3408 TOLY Original lyricist(s)/text writer(s) 3409 TOPE Original artist(s)/performer(s) 3410 TOR Original release year 3411 TORY Original release year 3412 TOT Original album/Movie/Show title 3413 TOWN File owner/licensee 3414 TP1 Lead artist(s)/Lead performer(s)/Soloist(s)/Performing group 3415 TP2 Band/Orchestra/Accompaniment 3416 TP3 Conductor/Performer refinement 3417 TP4 Interpreted, remixed, or otherwise modified by 3418 TPA Part of a set 3419 TPB Publisher 3420 TPE1 Lead performer(s)/Soloist(s) 3421 TPE2 Band/orchestra/accompaniment 3422 TPE3 Conductor/performer refinement 3423 TPE4 Interpreted, remixed, or otherwise modified by 3424 TPOS Part of a set 3425 TPRO Produced notice 3426 TPUB Publisher 3427 TRC ISRC (International Standard Recording Code) 3428 TRCK Track number/Position in set 3429 TRD Recording dates 3430 TRDA Recording dates 3431 TRK Track number/Position in set 3432 TRSN Internet radio station name 3433 TRSO Internet radio station owner 3434 TS2 Album-Artist sort order 3435 TSA Album sort order 3436 TSC Composer sort order 3437 TSI Size 3438 TSIZ Size 3439 TSO2 Album-Artist sort order 3440 TSOA Album sort order 3441 TSOC Composer sort order 3442 TSOP Performer sort order 3443 TSOT Title sort order 3444 TSP Performer sort order 3445 TSRC ISRC (international standard recording code) 3446 TSS Software/hardware and settings used for encoding 3447 TSSE Software/Hardware and settings used for encoding 3448 TSST Set subtitle 3449 TST Title sort order 3450 TT1 Content group description 3451 TT2 Title/Songname/Content description 3452 TT3 Subtitle/Description refinement 3453 TXT Lyricist/text writer 3454 TXX User defined text information frame 3455 TXXX User defined text information frame 3456 TYE Year 3457 TYER Year 3458 UFI Unique file identifier 3459 UFID Unique file identifier 3460 ULT Unsynchronised lyric/text transcription 3461 USER Terms of use 3462 USLT Unsynchronised lyric/text transcription 3463 WAF Official audio file webpage 3464 WAR Official artist/performer webpage 3465 WAS Official audio source webpage 3466 WCM Commercial information 3467 WCOM Commercial information 3468 WCOP Copyright/Legal information 3469 WCP Copyright/Legal information 3470 WOAF Official audio file webpage 3471 WOAR Official artist/performer webpage 3472 WOAS Official audio source webpage 3473 WORS Official Internet radio station homepage 3474 WPAY Payment 3475 WPB Publishers official webpage 3476 WPUB Publishers official webpage 3477 WXX User defined URL link frame 3478 WXXX User defined URL link frame 3479 TFEA Featured Artist 3480 TSTU Recording Studio 3481 rgad Replay Gain Adjustment 3482 3483 */ 3484 3485 return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_long'); 3486 3487 // Last three: 3488 // from Helium2 [www.helium2.com] 3489 // from http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html 3490 } 3491 3492 /** 3493 * @param string $framename 3494 * 3495 * @return string 3496 */ 3497 public static function FrameNameShortLookup($framename) { 3498 3499 $begin = __LINE__; 3500 3501 /** This is not a comment! 3502 3503 AENC audio_encryption 3504 APIC attached_picture 3505 ASPI audio_seek_point_index 3506 BUF recommended_buffer_size 3507 CNT play_counter 3508 COM comment 3509 COMM comment 3510 COMR commercial_frame 3511 CRA audio_encryption 3512 CRM encrypted_meta_frame 3513 ENCR encryption_method_registration 3514 EQU equalisation 3515 EQU2 equalisation 3516 EQUA equalisation 3517 ETC event_timing_codes 3518 ETCO event_timing_codes 3519 GEO general_encapsulated_object 3520 GEOB general_encapsulated_object 3521 GRID group_identification_registration 3522 IPL involved_people_list 3523 IPLS involved_people_list 3524 LINK linked_information 3525 LNK linked_information 3526 MCDI music_cd_identifier 3527 MCI music_cd_identifier 3528 MLL mpeg_location_lookup_table 3529 MLLT mpeg_location_lookup_table 3530 OWNE ownership_frame 3531 PCNT play_counter 3532 PIC attached_picture 3533 POP popularimeter 3534 POPM popularimeter 3535 POSS position_synchronisation_frame 3536 PRIV private_frame 3537 RBUF recommended_buffer_size 3538 REV reverb 3539 RVA relative_volume_adjustment 3540 RVA2 relative_volume_adjustment 3541 RVAD relative_volume_adjustment 3542 RVRB reverb 3543 SEEK seek_frame 3544 SIGN signature_frame 3545 SLT synchronised_lyric 3546 STC synced_tempo_codes 3547 SYLT synchronised_lyric 3548 SYTC synchronised_tempo_codes 3549 TAL album 3550 TALB album 3551 TBP bpm 3552 TBPM bpm 3553 TCM composer 3554 TCMP part_of_a_compilation 3555 TCO genre 3556 TCOM composer 3557 TCON genre 3558 TCOP copyright_message 3559 TCP part_of_a_compilation 3560 TCR copyright_message 3561 TDA date 3562 TDAT date 3563 TDEN encoding_time 3564 TDLY playlist_delay 3565 TDOR original_release_time 3566 TDRC recording_time 3567 TDRL release_time 3568 TDTG tagging_time 3569 TDY playlist_delay 3570 TEN encoded_by 3571 TENC encoded_by 3572 TEXT lyricist 3573 TFLT file_type 3574 TFT file_type 3575 TIM time 3576 TIME time 3577 TIPL involved_people_list 3578 TIT1 content_group_description 3579 TIT2 title 3580 TIT3 subtitle 3581 TKE initial_key 3582 TKEY initial_key 3583 TLA language 3584 TLAN language 3585 TLE length 3586 TLEN length 3587 TMCL musician_credits_list 3588 TMED media_type 3589 TMOO mood 3590 TMT media_type 3591 TOA original_artist 3592 TOAL original_album 3593 TOF original_filename 3594 TOFN original_filename 3595 TOL original_lyricist 3596 TOLY original_lyricist 3597 TOPE original_artist 3598 TOR original_year 3599 TORY original_year 3600 TOT original_album 3601 TOWN file_owner 3602 TP1 artist 3603 TP2 band 3604 TP3 conductor 3605 TP4 remixer 3606 TPA part_of_a_set 3607 TPB publisher 3608 TPE1 artist 3609 TPE2 band 3610 TPE3 conductor 3611 TPE4 remixer 3612 TPOS part_of_a_set 3613 TPRO produced_notice 3614 TPUB publisher 3615 TRC isrc 3616 TRCK track_number 3617 TRD recording_dates 3618 TRDA recording_dates 3619 TRK track_number 3620 TRSN internet_radio_station_name 3621 TRSO internet_radio_station_owner 3622 TS2 album_artist_sort_order 3623 TSA album_sort_order 3624 TSC composer_sort_order 3625 TSI size 3626 TSIZ size 3627 TSO2 album_artist_sort_order 3628 TSOA album_sort_order 3629 TSOC composer_sort_order 3630 TSOP performer_sort_order 3631 TSOT title_sort_order 3632 TSP performer_sort_order 3633 TSRC isrc 3634 TSS encoder_settings 3635 TSSE encoder_settings 3636 TSST set_subtitle 3637 TST title_sort_order 3638 TT1 content_group_description 3639 TT2 title 3640 TT3 subtitle 3641 TXT lyricist 3642 TXX text 3643 TXXX text 3644 TYE year 3645 TYER year 3646 UFI unique_file_identifier 3647 UFID unique_file_identifier 3648 ULT unsynchronised_lyric 3649 USER terms_of_use 3650 USLT unsynchronised_lyric 3651 WAF url_file 3652 WAR url_artist 3653 WAS url_source 3654 WCM commercial_information 3655 WCOM commercial_information 3656 WCOP copyright 3657 WCP copyright 3658 WOAF url_file 3659 WOAR url_artist 3660 WOAS url_source 3661 WORS url_station 3662 WPAY url_payment 3663 WPB url_publisher 3664 WPUB url_publisher 3665 WXX url_user 3666 WXXX url_user 3667 TFEA featured_artist 3668 TSTU recording_studio 3669 rgad replay_gain_adjustment 3670 3671 */ 3672 3673 return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_short'); 3674 } 3675 3676 /** 3677 * @param string $encoding 3678 * 3679 * @return string 3680 */ 3681 public static function TextEncodingTerminatorLookup($encoding) { 3682 // http://www.id3.org/id3v2.4.0-structure.txt 3683 // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings: 3684 static $TextEncodingTerminatorLookup = array( 3685 0 => "\x00", // $00 ISO-8859-1. Terminated with $00. 3686 1 => "\x00\x00", // $01 UTF-16 encoded Unicode with BOM. All strings in the same frame SHALL have the same byteorder. Terminated with $00 00. 3687 2 => "\x00\x00", // $02 UTF-16BE encoded Unicode without BOM. Terminated with $00 00. 3688 3 => "\x00", // $03 UTF-8 encoded Unicode. Terminated with $00. 3689 255 => "\x00\x00" 3690 ); 3691 return (isset($TextEncodingTerminatorLookup[$encoding]) ? $TextEncodingTerminatorLookup[$encoding] : "\x00"); 3692 } 3693 3694 /** 3695 * @param int $encoding 3696 * 3697 * @return string 3698 */ 3699 public static function TextEncodingNameLookup($encoding) { 3700 // http://www.id3.org/id3v2.4.0-structure.txt 3701 // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings: 3702 static $TextEncodingNameLookup = array( 3703 0 => 'ISO-8859-1', // $00 ISO-8859-1. Terminated with $00. 3704 1 => 'UTF-16', // $01 UTF-16 encoded Unicode with BOM. All strings in the same frame SHALL have the same byteorder. Terminated with $00 00. 3705 2 => 'UTF-16BE', // $02 UTF-16BE encoded Unicode without BOM. Terminated with $00 00. 3706 3 => 'UTF-8', // $03 UTF-8 encoded Unicode. Terminated with $00. 3707 255 => 'UTF-16BE' 3708 ); 3709 return (isset($TextEncodingNameLookup[$encoding]) ? $TextEncodingNameLookup[$encoding] : 'ISO-8859-1'); 3710 } 3711 3712 /** 3713 * @param string $string 3714 * @param string $terminator 3715 * 3716 * @return string 3717 */ 3718 public static function RemoveStringTerminator($string, $terminator) { 3719 // Null terminator at end of comment string is somewhat ambiguous in the specification, may or may not be implemented by various taggers. Remove terminator only if present. 3720 // https://github.com/JamesHeinrich/getID3/issues/121 3721 // https://community.mp3tag.de/t/x-trailing-nulls-in-id3v2-comments/19227 3722 if (substr($string, -strlen($terminator), strlen($terminator)) === $terminator) { 3723 $string = substr($string, 0, -strlen($terminator)); 3724 } 3725 return $string; 3726 } 3727 3728 /** 3729 * @param string $string 3730 * 3731 * @return string 3732 */ 3733 public static function MakeUTF16emptyStringEmpty($string) { 3734 if (in_array($string, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { 3735 // if string only contains a BOM or terminator then make it actually an empty string 3736 $string = ''; 3737 } 3738 return $string; 3739 } 3740 3741 /** 3742 * @param string $framename 3743 * @param int $id3v2majorversion 3744 * 3745 * @return bool|int 3746 */ 3747 public static function IsValidID3v2FrameName($framename, $id3v2majorversion) { 3748 switch ($id3v2majorversion) { 3749 case 2: 3750 return preg_match('#[A-Z][A-Z0-9]{2}#', $framename); 3751 3752 case 3: 3753 case 4: 3754 return preg_match('#[A-Z][A-Z0-9]{3}#', $framename); 3755 } 3756 return false; 3757 } 3758 3759 /** 3760 * @param string $numberstring 3761 * @param bool $allowdecimal 3762 * @param bool $allownegative 3763 * 3764 * @return bool 3765 */ 3766 public static function IsANumber($numberstring, $allowdecimal=false, $allownegative=false) { 3767 $pattern = '#^'; 3768 $pattern .= ($allownegative ? '\\-?' : ''); 3769 $pattern .= '[0-9]+'; 3770 $pattern .= ($allowdecimal ? '(\\.[0-9]+)?' : ''); 3771 $pattern .= '$#'; 3772 return preg_match($pattern, $numberstring); 3773 } 3774 3775 /** 3776 * @param string $datestamp 3777 * 3778 * @return bool 3779 */ 3780 public static function IsValidDateStampString($datestamp) { 3781 if (!preg_match('#^[12][0-9]{3}[01][0-9][0123][0-9]$#', $datestamp)) { 3782 return false; 3783 } 3784 $year = substr($datestamp, 0, 4); 3785 $month = substr($datestamp, 4, 2); 3786 $day = substr($datestamp, 6, 2); 3787 if (($year == 0) || ($month == 0) || ($day == 0)) { 3788 return false; 3789 } 3790 if ($month > 12) { 3791 return false; 3792 } 3793 if ($day > 31) { 3794 return false; 3795 } 3796 if (($day > 30) && (($month == 4) || ($month == 6) || ($month == 9) || ($month == 11))) { 3797 return false; 3798 } 3799 if (($day > 29) && ($month == 2)) { 3800 return false; 3801 } 3802 return true; 3803 } 3804 3805 /** 3806 * @param int $majorversion 3807 * 3808 * @return int 3809 */ 3810 public static function ID3v2HeaderLength($majorversion) { 3811 return (($majorversion == 2) ? 6 : 10); 3812 } 3813 3814 /** 3815 * @param string $frame_name 3816 * 3817 * @return string|false 3818 */ 3819 public static function ID3v22iTunesBrokenFrameName($frame_name) { 3820 // iTunes (multiple versions) has been known to write ID3v2.3 style frames 3821 // but use ID3v2.2 frame names, right-padded using either [space] or [null] 3822 // to make them fit in the 4-byte frame name space of the ID3v2.3 frame. 3823 // This function will detect and translate the corrupt frame name into ID3v2.3 standard. 3824 static $ID3v22_iTunes_BrokenFrames = array( 3825 'BUF' => 'RBUF', // Recommended buffer size 3826 'CNT' => 'PCNT', // Play counter 3827 'COM' => 'COMM', // Comments 3828 'CRA' => 'AENC', // Audio encryption 3829 'EQU' => 'EQUA', // Equalisation 3830 'ETC' => 'ETCO', // Event timing codes 3831 'GEO' => 'GEOB', // General encapsulated object 3832 'IPL' => 'IPLS', // Involved people list 3833 'LNK' => 'LINK', // Linked information 3834 'MCI' => 'MCDI', // Music CD identifier 3835 'MLL' => 'MLLT', // MPEG location lookup table 3836 'PIC' => 'APIC', // Attached picture 3837 'POP' => 'POPM', // Popularimeter 3838 'REV' => 'RVRB', // Reverb 3839 'RVA' => 'RVAD', // Relative volume adjustment 3840 'SLT' => 'SYLT', // Synchronised lyric/text 3841 'STC' => 'SYTC', // Synchronised tempo codes 3842 'TAL' => 'TALB', // Album/Movie/Show title 3843 'TBP' => 'TBPM', // BPM (beats per minute) 3844 'TCM' => 'TCOM', // Composer 3845 'TCO' => 'TCON', // Content type 3846 'TCP' => 'TCMP', // Part of a compilation 3847 'TCR' => 'TCOP', // Copyright message 3848 'TDA' => 'TDAT', // Date 3849 'TDY' => 'TDLY', // Playlist delay 3850 'TEN' => 'TENC', // Encoded by 3851 'TFT' => 'TFLT', // File type 3852 'TIM' => 'TIME', // Time 3853 'TKE' => 'TKEY', // Initial key 3854 'TLA' => 'TLAN', // Language(s) 3855 'TLE' => 'TLEN', // Length 3856 'TMT' => 'TMED', // Media type 3857 'TOA' => 'TOPE', // Original artist(s)/performer(s) 3858 'TOF' => 'TOFN', // Original filename 3859 'TOL' => 'TOLY', // Original lyricist(s)/text writer(s) 3860 'TOR' => 'TORY', // Original release year 3861 'TOT' => 'TOAL', // Original album/movie/show title 3862 'TP1' => 'TPE1', // Lead performer(s)/Soloist(s) 3863 'TP2' => 'TPE2', // Band/orchestra/accompaniment 3864 'TP3' => 'TPE3', // Conductor/performer refinement 3865 'TP4' => 'TPE4', // Interpreted, remixed, or otherwise modified by 3866 'TPA' => 'TPOS', // Part of a set 3867 'TPB' => 'TPUB', // Publisher 3868 'TRC' => 'TSRC', // ISRC (international standard recording code) 3869 'TRD' => 'TRDA', // Recording dates 3870 'TRK' => 'TRCK', // Track number/Position in set 3871 'TS2' => 'TSO2', // Album-Artist sort order 3872 'TSA' => 'TSOA', // Album sort order 3873 'TSC' => 'TSOC', // Composer sort order 3874 'TSI' => 'TSIZ', // Size 3875 'TSP' => 'TSOP', // Performer sort order 3876 'TSS' => 'TSSE', // Software/Hardware and settings used for encoding 3877 'TST' => 'TSOT', // Title sort order 3878 'TT1' => 'TIT1', // Content group description 3879 'TT2' => 'TIT2', // Title/songname/content description 3880 'TT3' => 'TIT3', // Subtitle/Description refinement 3881 'TXT' => 'TEXT', // Lyricist/Text writer 3882 'TXX' => 'TXXX', // User defined text information frame 3883 'TYE' => 'TYER', // Year 3884 'UFI' => 'UFID', // Unique file identifier 3885 'ULT' => 'USLT', // Unsynchronised lyric/text transcription 3886 'WAF' => 'WOAF', // Official audio file webpage 3887 'WAR' => 'WOAR', // Official artist/performer webpage 3888 'WAS' => 'WOAS', // Official audio source webpage 3889 'WCM' => 'WCOM', // Commercial information 3890 'WCP' => 'WCOP', // Copyright/Legal information 3891 'WPB' => 'WPUB', // Publishers official webpage 3892 'WXX' => 'WXXX', // User defined URL link frame 3893 ); 3894 if (strlen($frame_name) == 4) { 3895 if ((substr($frame_name, 3, 1) == ' ') || (substr($frame_name, 3, 1) == "\x00")) { 3896 if (isset($ID3v22_iTunes_BrokenFrames[substr($frame_name, 0, 3)])) { 3897 return $ID3v22_iTunes_BrokenFrames[substr($frame_name, 0, 3)]; 3898 } 3899 } 3900 } 3901 return false; 3902 } 3903 3904 } 3905
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sun Nov 29 08:20:01 2026 | Cross-referenced by PHPXref |