}
public IMusicMetadata parseTags(MyID3Listener listener, byte bytes[],
boolean strict)
{
IMusicMetadata result = new MusicMetadata("ID3v1");
int counter = 3;
String title = getField(listener, bytes, counter, 30);
counter += 30;
result.setSongTitle(title);
if (null != listener)
listener.logWithLength("id3v1 title", title);
String artist = getField(listener, bytes, counter, 30);
counter += 30;
result.setArtist(artist);
if (null != listener)
listener.logWithLength("id3v1 artist", artist);
String album = getField(listener, bytes, counter, 30);
counter += 30;
result.setAlbum(album);
if (null != listener)
listener.logWithLength("id3v1 album", album);
String yearString = getField(listener, bytes, counter, 4);
counter += 4;
Number year = null;
try
{
if (null != yearString)
year = Integer.valueOf(yearString);
} catch (NumberFormatException e)
{
// ignore
}
result.setYear(year);
if (null != listener)
{
listener.logWithLength("id3v1 year", yearString);
if (null != yearString)
listener.log("id3v1 year", year);
}
String comment = getField(listener, bytes, counter, 30);
counter += 30;
if (null != comment)
result.addComment(comment);
if (null != listener)
listener.logWithLength("id3v1 comment", comment);
if (bytes[counter - 2] == 0 && bytes[counter - 1] != 0)
{
int trackNumber = 0xff & bytes[counter - 1];
// TODO: should we ignore 0x00 and 0xff track numbers?
result.setTrackNumberNumeric(new Integer(trackNumber));
if (null != listener)
listener.log("id3v1 trackNumber: " + trackNumber);
}
int genre = 0xff & bytes[counter];
if (genre < 80 && genre > 0)
{
result.setGenreID(new Integer(genre));
result.setGenreName(ID3v1Genre.getNameForID(new Integer(genre)));
if (null != listener)
listener.log("id3v1 genre: " + genre);
}