* Construst a SongData from an MP3 at the given absolute path
* @param path the absolute path of the MP3
*/
public SongData( String path ) throws SongDataException {
this.path = tagPrep(path);
AbstractMP3Tag tag = null;
try {
MP3File mp3file = new MP3File(path);
if (mp3file.hasID3v2Tag()) {
tag = mp3file.getID3v2Tag();
} else if (mp3file.hasID3v1Tag()) {
tag = mp3file.getID3v1Tag();
} else {
throw new SongDataException( "No MP3 ID tag found for \""+path+"\"" );
}
} catch (TagException tE) {
throw new SongDataException( "(TagException) Broken MP3 ID tag found for \""+path+"\"" );
} catch (IOException ioE) {
log.warn("", ioE);
throw new SongDataException( "IOE for \""+path+"\"" );
}
try { //unfortunately jd3lib isn't perfect...grr...
title = tagPrep(tag.getSongTitle());
album = tagPrep(tag.getAlbumTitle());
artist = tagPrep(tag.getLeadArtist());
genre = tagPrep(tag.getSongGenre());
if (genre.length() > 1) { // ensure that genres do not have mutiples because of case
char firstChar = genre.toUpperCase().charAt(0);
genre = firstChar+genre.substring(1);
}
track = Integer.parseInt(tag.getTrackNumberOnAlbum());
} catch (NullPointerException npE) {
throw new SongDataException( "(NPE) Broken MP3 ID tag found for \""+path+"\"" );
} catch (NumberFormatException nfE) {
log.warn("No track number for " + title);