wp/wp-includes/ID3/module.tag.lyrics3.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 16 a86126ab1dd4
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    22 		$info = &$this->getid3->info;
    22 		$info = &$this->getid3->info;
    23 
    23 
    24 		// http://www.volweb.cz/str/tags.htm
    24 		// http://www.volweb.cz/str/tags.htm
    25 
    25 
    26 		if (!getid3_lib::intValueSupported($info['filesize'])) {
    26 		if (!getid3_lib::intValueSupported($info['filesize'])) {
    27 			$info['warning'][] = 'Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
    27 			$this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
    28 			return false;
    28 			return false;
    29 		}
    29 		}
    30 
    30 
    31 		$this->fseek((0 - 128 - 9 - 6), SEEK_END);          // end - ID3v1 - "LYRICSEND" - [Lyrics3size]
    31 		$this->fseek((0 - 128 - 9 - 6), SEEK_END);          // end - ID3v1 - "LYRICSEND" - [Lyrics3size]
    32 		$lyrics3_id3v1 = $this->fread(128 + 9 + 6);
    32 		$lyrics3_id3v1 = $this->fread(128 + 9 + 6);
    78 
    78 
    79 					$lyrics3size    = 5100;
    79 					$lyrics3size    = 5100;
    80 					$lyrics3offset  = $info['ape']['tag_offset_start'] - $lyrics3size;
    80 					$lyrics3offset  = $info['ape']['tag_offset_start'] - $lyrics3size;
    81 					$info['avdataend'] = $lyrics3offset;
    81 					$info['avdataend'] = $lyrics3offset;
    82 					$lyrics3version = 1;
    82 					$lyrics3version = 1;
    83 					$info['warning'][] = 'APE tag located after Lyrics3, will probably break Lyrics3 compatability';
    83 					$this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability');
    84 
    84 
    85 				} elseif ($lyrics3end == 'LYRICS200') {
    85 				} elseif ($lyrics3end == 'LYRICS200') {
    86 					// Lyrics3v2, APE, maybe ID3v1
    86 					// Lyrics3v2, APE, maybe ID3v1
    87 
    87 
    88 					$lyrics3size    = $lyrics3lsz + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
    88 					$lyrics3size    = $lyrics3lsz + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
    89 					$lyrics3offset  = $info['ape']['tag_offset_start'] - $lyrics3size;
    89 					$lyrics3offset  = $info['ape']['tag_offset_start'] - $lyrics3size;
    90 					$lyrics3version = 2;
    90 					$lyrics3version = 2;
    91 					$info['warning'][] = 'APE tag located after Lyrics3, will probably break Lyrics3 compatability';
    91 					$this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability');
    92 
    92 
    93 				}
    93 				}
    94 
    94 
    95 			}
    95 			}
    96 
    96 
    99 		if (isset($lyrics3offset)) {
    99 		if (isset($lyrics3offset)) {
   100 			$info['avdataend'] = $lyrics3offset;
   100 			$info['avdataend'] = $lyrics3offset;
   101 			$this->getLyrics3Data($lyrics3offset, $lyrics3version, $lyrics3size);
   101 			$this->getLyrics3Data($lyrics3offset, $lyrics3version, $lyrics3size);
   102 
   102 
   103 			if (!isset($info['ape'])) {
   103 			if (!isset($info['ape'])) {
   104 				$GETID3_ERRORARRAY = &$info['warning'];
   104 				if (isset($info['lyrics3']['tag_offset_start'])) {
   105 				getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true);
   105 					$GETID3_ERRORARRAY = &$info['warning'];
   106 				$getid3_temp = new getID3();
   106 					getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true);
   107 				$getid3_temp->openfile($this->getid3->filename);
   107 					$getid3_temp = new getID3();
   108 				$getid3_apetag = new getid3_apetag($getid3_temp);
   108 					$getid3_temp->openfile($this->getid3->filename);
   109 				$getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start'];
   109 					$getid3_apetag = new getid3_apetag($getid3_temp);
   110 				$getid3_apetag->Analyze();
   110 					$getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start'];
   111 				if (!empty($getid3_temp->info['ape'])) {
   111 					$getid3_apetag->Analyze();
   112 					$info['ape'] = $getid3_temp->info['ape'];
   112 					if (!empty($getid3_temp->info['ape'])) {
   113 				}
   113 						$info['ape'] = $getid3_temp->info['ape'];
   114 				if (!empty($getid3_temp->info['replay_gain'])) {
   114 					}
   115 					$info['replay_gain'] = $getid3_temp->info['replay_gain'];
   115 					if (!empty($getid3_temp->info['replay_gain'])) {
   116 				}
   116 						$info['replay_gain'] = $getid3_temp->info['replay_gain'];
   117 				unset($getid3_temp, $getid3_apetag);
   117 					}
       
   118 					unset($getid3_temp, $getid3_apetag);
       
   119 				} else {
       
   120 					$this->warning('Lyrics3 and APE tags appear to have become entangled (most likely due to updating the APE tags with a non-Lyrics3-aware tagger)');
       
   121 				}
   118 			}
   122 			}
   119 
   123 
   120 		}
   124 		}
   121 
   125 
   122 		return true;
   126 		return true;
   126 		// http://www.volweb.cz/str/tags.htm
   130 		// http://www.volweb.cz/str/tags.htm
   127 
   131 
   128 		$info = &$this->getid3->info;
   132 		$info = &$this->getid3->info;
   129 
   133 
   130 		if (!getid3_lib::intValueSupported($endoffset)) {
   134 		if (!getid3_lib::intValueSupported($endoffset)) {
   131 			$info['warning'][] = 'Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
   135 			$this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
   132 			return false;
   136 			return false;
   133 		}
   137 		}
   134 
   138 
   135 		$this->fseek($endoffset);
   139 		$this->fseek($endoffset);
   136 		if ($length <= 0) {
   140 		if ($length <= 0) {
   144 		$ParsedLyrics3['tag_offset_end']        = $endoffset + $length - 1;
   148 		$ParsedLyrics3['tag_offset_end']        = $endoffset + $length - 1;
   145 
   149 
   146 		if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') {
   150 		if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') {
   147 			if (strpos($rawdata, 'LYRICSBEGIN') !== false) {
   151 			if (strpos($rawdata, 'LYRICSBEGIN') !== false) {
   148 
   152 
   149 				$info['warning'][] = '"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version;
   153 				$this->warning('"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version);
   150 				$info['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN');
   154 				$info['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN');
   151 				$rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN'));
   155 				$rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN'));
   152 				$length = strlen($rawdata);
   156 				$length = strlen($rawdata);
   153 				$ParsedLyrics3['tag_offset_start'] = $info['avdataend'];
   157 				$ParsedLyrics3['tag_offset_start'] = $info['avdataend'];
   154 				$ParsedLyrics3['raw']['lyrics3tagsize'] = $length;
   158 				$ParsedLyrics3['raw']['lyrics3tagsize'] = $length;
   155 
   159 
   156 			} else {
   160 			} else {
   157 
   161 
   158 				$info['error'][] = '"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead';
   162 				$this->error('"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead');
   159 				return false;
   163 				return false;
   160 
   164 
   161 			}
   165 			}
   162 
   166 
   163 		}
   167 		}
   167 			case 1:
   171 			case 1:
   168 				if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICSEND') {
   172 				if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICSEND') {
   169 					$ParsedLyrics3['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9));
   173 					$ParsedLyrics3['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9));
   170 					$this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
   174 					$this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
   171 				} else {
   175 				} else {
   172 					$info['error'][] = '"LYRICSEND" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead';
   176 					$this->error('"LYRICSEND" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead');
   173 					return false;
   177 					return false;
   174 				}
   178 				}
   175 				break;
   179 				break;
   176 
   180 
   177 			case 2:
   181 			case 2:
   215 					}
   219 					}
   216 					if (isset($ParsedLyrics3['raw']['LYR'])) {
   220 					if (isset($ParsedLyrics3['raw']['LYR'])) {
   217 						$this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
   221 						$this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
   218 					}
   222 					}
   219 				} else {
   223 				} else {
   220 					$info['error'][] = '"LYRICS200" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead';
   224 					$this->error('"LYRICS200" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead');
   221 					return false;
   225 					return false;
   222 				}
   226 				}
   223 				break;
   227 				break;
   224 
   228 
   225 			default:
   229 			default:
   226 				$info['error'][] = 'Cannot process Lyrics3 version '.$version.' (only v1 and v2)';
   230 				$this->error('Cannot process Lyrics3 version '.$version.' (only v1 and v2)');
   227 				return false;
   231 				return false;
   228 				break;
   232 				break;
   229 		}
   233 		}
   230 
   234 
   231 
   235 
   232 		if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] <= $ParsedLyrics3['tag_offset_end'])) {
   236 		if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] <= $ParsedLyrics3['tag_offset_end'])) {
   233 			$info['warning'][] = 'ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data';
   237 			$this->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data');
   234 			unset($info['id3v1']);
   238 			unset($info['id3v1']);
   235 			foreach ($info['warning'] as $key => $value) {
   239 			foreach ($info['warning'] as $key => $value) {
   236 				if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
   240 				if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
   237 					unset($info['warning'][$key]);
   241 					unset($info['warning'][$key]);
   238 					sort($info['warning']);
   242 					sort($info['warning']);