/** * Parse the tmp file for tag data and create associated song * * @param dfi * @return song created from tag data */ public static Song parseFileForSong(DiskFileItem dfi) { // TODO Think about where to move this. File audioFile = new File(dfi.getStoreLocation().toString().replace(".tmp", ".mp3")); // "."+dfi.getContentType().substring(dfi.getContentType().indexOf("/")+1))); if (!dfi.getStoreLocation().renameTo(audioFile)) { log.error( "rename failed - store location:" + dfi.getStoreLocation() + ", audio file:" + audioFile); } AudioFile f = null; try { f = AudioFileIO.read(audioFile); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Tag tag = f.getTag(); if (tag == null) { tag = f.getTagOrCreateAndSetDefault(); } Song song = new Song(); try { song.setArtist(tag.getFirst(FieldKey.ARTIST)); song.setAlbum(tag.getFirst(FieldKey.ALBUM)); song.setTitle(tag.getFirst(FieldKey.TITLE)); song.setYear(tag.getFirst(FieldKey.YEAR)); song.setTrack(tag.getFirst(FieldKey.TRACK)); song.setFilename(dfi.getName()); } catch (KeyNotFoundException knfe) { log.error("song key not found", knfe); } return song; }