107 {
108
109
110 fseek($fd, $endoffset, SEEK_SET);
111 if ($length <= 0) {
112 return false;
113 }
114 $rawdata = fread($fd, $length);
115
116 if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') {
117 if (strpos($rawdata, 'LYRICSBEGIN') !== false) {
118
119 $ThisFileInfo['warning'][] = '"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version;
120 $ThisFileInfo['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN');
121 $ParsedLyrics3['tag_offset_start'] = $ThisFileInfo['avdataend'];
122 $rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN'));
123 $length = strlen($rawdata);
124
125 } else {
126
127 $ThisFileInfo['error'][] = '"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead';
128 return false;
129
130 }
131
132 }
133
134 $ParsedLyrics3['raw']['lyrics3version'] = $version;
135 $ParsedLyrics3['raw']['lyrics3tagsize'] = $length;
136 $ParsedLyrics3['tag_offset_start'] = $endoffset;
137 $ParsedLyrics3['tag_offset_end'] = $endoffset + $length;
138
139 switch ($version) {
140
141 case 1:
142 if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICSEND') {
143 $ParsedLyrics3['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9));
145 } else {
146 $ThisFileInfo['error'][] = '"LYRICSEND" expected at '.(ftell($fd) - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead';
147 return false;
148 }
149 break;
150
151 case 2:
152 if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICS200') {
153 $ParsedLyrics3['raw']['unparsed'] = substr($rawdata, 11, strlen($rawdata) - 11 - 9 - 6);
154 $rawdata = $ParsedLyrics3['raw']['unparsed'];
155 while (strlen($rawdata) > 0) {
156 $fieldname = substr($rawdata, 0, 3);
157 $fieldsize = (int) substr($rawdata, 3, 5);
158 $ParsedLyrics3['raw'][$fieldname] = substr($rawdata, 8, $fieldsize);
159 $rawdata = substr($rawdata, 3 + 5 + $fieldsize);
160 }
161
162 if (isset($ParsedLyrics3['raw']['IND'])) {
163 $i = 0;
164 $flagnames = array('lyrics', 'timestamps', 'inhibitrandom');
165 foreach ($flagnames as $flagname) {
166 if (strlen($ParsedLyrics3['raw']['IND']) > ++$i) {
167 $ParsedLyrics3[
'flags'][$flagname] = $this->
IntString2Bool(substr($ParsedLyrics3[
'raw'][
'IND'], $i, 1));
168 }
169 }
170 }
171
172 $fieldnametranslation = array('ETT'=>'title', 'EAR'=>'artist', 'EAL'=>'album', 'INF'=>'comment', 'AUT'=>'author');
173 foreach ($fieldnametranslation as $key => $value) {
174 if (isset($ParsedLyrics3['raw'][$key])) {
175 $ParsedLyrics3['comments'][$value][] = trim($ParsedLyrics3['raw'][$key]);
176 }
177 }
178
179 if (isset($ParsedLyrics3['raw']['IMG'])) {
180 $imagestrings = explode("\r\n", $ParsedLyrics3['raw']['IMG']);
181 foreach ($imagestrings as $key => $imagestring) {
182 if (strpos($imagestring, '||') !== false) {
183 $imagearray = explode('||', $imagestring);
184 $ParsedLyrics3['images'][$key]['filename'] = $imagearray[0];
185 $ParsedLyrics3['images'][$key]['description'] = $imagearray[1];
187 }
188 }
189 }
190 if (isset($ParsedLyrics3['raw']['LYR'])) {
192 }
193 } else {
194 $ThisFileInfo['error'][] = '"LYRICS200" expected at '.(ftell($fd) - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead';
195 return false;
196 }
197 break;
198
199 default:
200 $ThisFileInfo['error'][] = 'Cannot process Lyrics3 version '.$version.' (only v1 and v2)';
201 return false;
202 break;
203 }
204
205
206 if (isset($ThisFileInfo['id3v1']['tag_offset_start']) && ($ThisFileInfo['id3v1']['tag_offset_start'] < $ParsedLyrics3['tag_offset_end'])) {
207 $ThisFileInfo['warning'][] = 'ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data';
208 unset($ThisFileInfo['id3v1']);
209 foreach ($ThisFileInfo['warning'] as $key => $value) {
210 if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
211 unset($ThisFileInfo['warning'][$key]);
212 sort($ThisFileInfo['warning']);
213 break;
214 }
215 }
216 }
217
218 $ThisFileInfo['lyrics3'] = $ParsedLyrics3;
219
220 return true;
221 }
Lyrics3LyricsTimestampParse(&$Lyrics3data)
Lyrics3Timestamp2Seconds($rawtimestamp)