String extension = getExtension(file.getFilename()).toUpperCase();
if (!ALLOWED_EXTENSIONS.contains(extension)) {
return;
}
MetaData metaData = new MetaData();
metaData.setMediaType(Mediatype.valueOf(extension));
try {
AudioFile audioFile = AudioFileIO.read(new java.io.File(
file.getDirectory(), file.getFilename()));
Tag tag = audioFile.getTag();
if (tag != null) {
metaData.setArtist(getTagField(tag, ARTIST));
metaData.setArtistSort(getTagField(tag, ARTIST_SORT));
metaData.setAlbumArtist(toAlbumArtist(tag));
metaData.setAlbumArtistSort(getTagField(tag, ALBUM_ARTIST_SORT));
metaData.setAlbum(toAlbum(getTagField(tag, ALBUM)));
metaData.setTitle(getTagField(tag, TITLE));
metaData.setYear(getTagField(tag, YEAR));
metaData.setGenre(toGenre(getTagField(tag, GENRE)));
metaData.setLyrics(getTagField(tag, LYRICS));
metaData.setComposer(getTagField(tag, COMPOSER));
metaData.setDiscNr(toFirstNumber(getTagField(tag, DISC_NO)));
metaData.setDiscNrs(toShort(getTagField(tag, DISC_TOTAL)));
metaData.setTrackNr(toFirstNumber(getTagField(tag, TRACK)));
metaData.setTrackNrs(toShort(getTagField(tag, TRACK_TOTAL)));
metaData.setCoverArtEmbedded(tag.getFirstArtwork() != null);
}
AudioHeader audioHeader = audioFile.getAudioHeader();
if (audioHeader != null) {
metaData.setVbr(audioHeader.isVariableBitRate());
metaData.setBitrate((short) audioHeader.getBitRateAsNumber());
metaData.setDuration((short) audioHeader.getTrackLength());
}
file.setMetaData(metaData);
} catch (CannotReadException | IOException | TagException