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); } }
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); } } }