Search in sources :

Example 1 with ReleaseParser

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

the class MusicBrainzService method updateArtistDiscographies.

protected void updateArtistDiscographies() {
    List<MBArtist> outdatedArtists = artistDao.getOutdatedArtists();
    List<MBRelease> mbReleases = new ArrayList<>();
    ReleaseParser parser;
    discographies = outdatedArtists.size();
    for (MBArtist artist : outdatedArtists) {
        try {
            int offset = 0;
            do {
                StringUtil response = new StringUtil(releaseClient.get(artist.getName(), artist.getMbid(), offset));
                parser = new ReleaseParserImpl(response.getInputStream());
                for (MBRelease album : parser.getReleases()) {
                    album.setArtistId(artist.getId());
                }
                mbReleases.addAll(parser.getReleases());
                offset += 100;
            } while (offset < parser.getTotalReleases());
            ++discography;
            if (mbReleases.size() > 1000) {
                albumDao.createAlbums(mbReleases);
                mbReleases.clear();
            }
        } catch (ApplicationException e) {
            LOG.warn("Couldn't read discography for " + artist.getName(), e);
        }
    }
    albumDao.createAlbums(mbReleases);
}
Also used : MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) ReleaseParser(com.github.hakko.musiccabinet.parser.musicbrainz.ReleaseParser) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ReleaseParserImpl(com.github.hakko.musiccabinet.parser.musicbrainz.ReleaseParserImpl) MBRelease(com.github.hakko.musiccabinet.domain.model.music.MBRelease)

Aggregations

MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)1 MBRelease (com.github.hakko.musiccabinet.domain.model.music.MBRelease)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 ReleaseParser (com.github.hakko.musiccabinet.parser.musicbrainz.ReleaseParser)1 ReleaseParserImpl (com.github.hakko.musiccabinet.parser.musicbrainz.ReleaseParserImpl)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 ArrayList (java.util.ArrayList)1