Search in sources :

Example 1 with ArtistQueryParserImpl

use of com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParserImpl in project musiccabinet by hakko.

the class MusicBrainzService method updateArtistIds.

protected void updateArtistIds() {
    List<Artist> missingArtists = artistDao.getMissingArtists();
    List<MBArtist> mbArtists = new ArrayList<>();
    mbids = missingArtists.size();
    for (Artist artist : artistDao.getMissingArtists()) {
        try {
            StringUtil response = new StringUtil(artistQueryClient.get(artist.getName()));
            ArtistQueryParser parser = new ArtistQueryParserImpl(response.getInputStream());
            if (parser.getArtist() != null) {
                mbArtists.add(parser.getArtist());
                if (mbArtists.size() > 100) {
                    artistDao.createArtists(mbArtists);
                    mbArtists.clear();
                }
            }
            ++mbid;
        } catch (ApplicationException e) {
            LOG.warn("Couldn't read mbid for " + artist.getName(), e);
        }
    }
    artistDao.createArtists(mbArtists);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) ArtistQueryParser(com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParser) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistQueryParserImpl(com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParserImpl)

Aggregations

Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)1 MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 ArtistQueryParser (com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParser)1 ArtistQueryParserImpl (com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParserImpl)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 ArrayList (java.util.ArrayList)1