public JAudioTagReader(String filename) { try { MP3File.logger.setLevel(Level.OFF); this.filename = filename; if (log.isTraceEnabled()) log.trace("JAudioTagReader(): filename=" + filename); MP3File mp3file; try { // mp3file = new MP3File(filename); mp3file = new MP3File(new File(filename), MP3File.LOAD_ALL, true); } catch (ReadOnlyFileException roe) { mp3file = new MP3File(new File(filename), MP3File.LOAD_ALL, true); } if (log.isTraceEnabled()) log.trace("JAudioTagReader(): mp3file=" + mp3file.displayStructureAsPlainText()); id3v1 = mp3file.getID3v1Tag(); id3v2 = mp3file.getID3v2TagAsv24(); if (id3v2 != null) { String identifier = id3v2.getIdentifier(); if (log.isTraceEnabled()) log.trace("JAudioTagReader(): id3v2 identifier=" + identifier); } if (id3v1 instanceof ID3v11Tag) { id3v11 = (ID3v11Tag) id3v1; } // if (log.isDebugEnabled()) // log.debug("JAudioTagReader(): GEOB frames=" + getFrames(FRAME_GENERAL)); } catch (java.lang.OutOfMemoryError e) { log.error("JAudioTagReader(): error out of memory, filename=" + filename, e); } catch (Exception e) { log.error("JAudioTagReader(): error Exception, filename=" + filename, e); } }
public void process() throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException { artistSet = new HashSet<>(); albumSet = new HashSet<>(); yearSet = new HashSet<>(); nameSet = new ArrayList<>(); for (File file : fileArray) { MP3File mp3file = (MP3File) AudioFileIO.read(file); Tag tag = mp3file.getTag(); if (!tag.getFirst(FieldKey.YEAR).isEmpty()) { yearSet.add(tag.getFirst(FieldKey.YEAR)); } if (tag.getFirst(FieldKey.TITLE).isEmpty()) { nameSet.add(file.getName()); } else { nameSet.add(tag.getFirst(FieldKey.TITLE)); } if (tag.getFirst(FieldKey.ALBUM).isEmpty()) { albumSet.add(file.getParentFile().getName()); } else { albumSet.add(tag.getFirst(FieldKey.ALBUM)); } if (tag.getFirst(FieldKey.ARTIST).isEmpty()) { if (file.getParentFile().getParentFile().exists()) { artistSet.add(file.getParentFile().getParentFile().getName()); } else { artistSet.add(file.getParentFile().getName()); } } else { artistSet.add(tag.getFirst(FieldKey.ARTIST)); } if (tag.getFirst(FieldKey.DISC_NO).isEmpty()) { if (file.getParentFile().getName().toLowerCase().contentEquals("cd")) {} } else { cd = tag.getFirst(FieldKey.DISC_NO); } } if (artistSet.size() == 1) { setTypeFlag(1); } else if (artistSet.size() == 2) { setTypeFlag(2); } else if (artistSet.size() > 2) { setTypeFlag(3); } try { parse(); } catch (SQLException ex) { Logger.getLogger(Aggregator.class.getName()).log(Level.SEVERE, null, ex); } }
public void createStructure() { MP3File.getStructureFormatter().openHeadingElement(TYPE_TAG, getIdentifier()); // Header MP3File.getStructureFormatter().addElement(TYPE_TITLE, this.title); MP3File.getStructureFormatter().addElement(TYPE_ARTIST, this.artist); MP3File.getStructureFormatter().addElement(TYPE_ALBUM, this.album); MP3File.getStructureFormatter().addElement(TYPE_YEAR, this.year); MP3File.getStructureFormatter().addElement(TYPE_COMMENT, this.comment); MP3File.getStructureFormatter().addElement(TYPE_TRACK, this.track); MP3File.getStructureFormatter().addElement(TYPE_GENRE, this.genre); MP3File.getStructureFormatter().closeHeadingElement(TYPE_TAG); }
public void saveChanges() { try { mp3File.save(); } catch (IOException | TagException e) { throw new RuntimeException(e); } }
private void parse() throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException, SQLException { int idLabel = 1; int idAlbum = 1; int idArtist = 1; ArrayList<Integer> arrGenres = null; for (File file : fileArray) { MP3File mp3file = (MP3File) AudioFileIO.read(file); Tag tag = mp3file.getTag(); Artists artist = new Artists(sqlWorker, tag); if (artistSet.size() == 2) { artist.setSplit(true); artist.setArtistSet(artistSet); } else if (artistSet.size() > 2) { artist.setVA(true); } artist.addFromTag(); try { idArtist = artist.getId(tag.getFirst(FieldKey.ARTIST)); artist.updateImagePath(defaultPersonPicture.getAbsolutePath()); } catch (NullPointerException e) { System.out.println("Aggr !!!!! У исполнителя не заполнен тег"); } Labels label = new Labels(sqlWorker); label.addFromTag(tag); idLabel = label.getId(); if (!tag.getFirst(FieldKey.GENRE).isEmpty()) { Genres genre = new Genres(sqlWorker); genre.addFromTag(tag); arrGenres = genre.getGenres(); } if (!tag.getFirst(FieldKey.ALBUM).isEmpty()) { setAlbum(new Albums(sqlWorker, idLabel, tag)); if (artistSet.size() > 1) { getAlbum().setVA(true); } getAlbum().addFromTag(); idAlbum = getAlbum().getId(tag.getFirst(FieldKey.ALBUM)); if (arrGenres != null) { for (int j = 0; j < arrGenres.size(); j++) { try { String query = "INSERT INTO albums_has_genres (albums_idalbum, genres_idgenre) " + "VALUES (?, ?)"; PreparedStatement stmt = sqlWorker.getConnection().prepareStatement(query); stmt.setInt(1, idAlbum); stmt.setInt(2, arrGenres.get(j)); stmt.executeUpdate(); } catch (SQLException e) { System.out.println( "##### Ошибка вставки в albums_has_genres. Значения уже существуют"); } } } try { String query = "INSERT INTO artist_has_albums (artist_idartist, album_idalbum) " + "VALUES (?, ?)"; PreparedStatement stmt = sqlWorker.getConnection().prepareStatement(query); if (artistSet.size() > 2) {} stmt.setInt(1, idArtist); stmt.setInt(2, idAlbum); stmt.executeUpdate(); } catch (SQLException e) { System.out.println("##### Ошибка вставки в artist_has_albums. Значения уже существуют"); } Songs song = new Songs(sqlWorker, mp3file, idAlbum); song.setCd(cd); song.addFromTag(tag); } } }
public Path file() { return mp3File.getFile().toPath(); }