@Override
public void prepare(RawDocument rawDocument) throws RegainException {
File rawFile = rawDocument.getContentAsFile(false);
try {
MP3File mp3file = new MP3File(rawFile);
ArrayList<String> info = new ArrayList<String>();
if (mp3file.hasID3v2Tag()) {
ID3v24Tag id3v24tag = mp3file.getID3v2TagAsv24();
info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_ARTIST).trim());
info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_ALBUM).trim());
info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_TITLE).trim());
try {
int year = new Integer(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_YEAR).trim()).intValue();
if (year > 0) {
info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_YEAR).trim());
}
} catch (Exception ex) {
}
info.add(mp3file.getMP3AudioHeader().getTrackLengthAsString().trim());
info.add(mp3file.getMP3AudioHeader().getBitRate().trim() + "kbps");
setCleanedContent(concatenateStringParts(info, Integer.MAX_VALUE));
setTitle(concatenateStringParts(info, 2));
} else if (mp3file.hasID3v1Tag()) {
ID3v1Tag tag = mp3file.getID3v1Tag();
info.add(tag.getFirst(FieldKey.ARTIST).trim());
info.add(tag.getFirst(FieldKey.ALBUM).trim());
info.add(tag.getFirst(FieldKey.TITLE).trim());
try {
int year = new Integer(tag.getFirst(FieldKey.YEAR).trim()).intValue();
if (year > 0) {
info.add(tag.getFirst(FieldKey.YEAR).trim());
}
} catch (Exception ex) {
}
info.add(mp3file.getMP3AudioHeader().getTrackLengthAsString().trim());
info.add(mp3file.getMP3AudioHeader().getBitRate().trim() + "kbps");
setCleanedContent(concatenateStringParts(info, Integer.MAX_VALUE));
setTitle(concatenateStringParts(info, 2));
} else {