Search in sources :

Example 1 with MBRelease

use of com.github.hakko.musiccabinet.domain.model.music.MBRelease in project musiccabinet by hakko.

the class JdbcMusicBrainzAlbumDao method batchInsert.

private void batchInsert(List<MBRelease> releases) {
    String sql = "insert into music.mb_album_import" + " (artist_id, title, type_id, release_year, label_name," + " label_mbid, format, release_group_mbid) values (?,?,?,?,?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("title", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("type_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("release_year", Types.SMALLINT));
    batchUpdate.declareParameter(new SqlParameter("label_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("label_mbid", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("format", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("release_group_mbid", Types.VARCHAR));
    for (MBRelease r : releases) {
        if (r.isValid()) {
            batchUpdate.update(new Object[] { r.getArtistId(), r.getTitle(), r.getAlbumType().ordinal(), r.getReleaseYear(), r.getLabelName(), r.getLabelMbid(), r.getFormat(), r.getReleaseGroupMbid() });
        } else {
            LOG.warn("Invalid MusicBrainz release ignored: " + r);
        }
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) MBRelease(com.github.hakko.musiccabinet.domain.model.music.MBRelease)

Example 2 with MBRelease

use of com.github.hakko.musiccabinet.domain.model.music.MBRelease in project musiccabinet by hakko.

the class JdbcMusicBrainzAlbumDaoTest method prepareTestData.

@Before
public void prepareTestData() throws ApplicationException {
    PostgreSQLUtil.loadFunction(albumDao, UPDATE_MB_ALBUM);
    additionDao.getJdbcTemplate().execute("truncate music.artist cascade");
    additionDao.getJdbcTemplate().execute("truncate library.file cascade");
    artist = new Artist(ARTIST);
    musicDao.setArtistId(artist);
    album1 = new MBRelease(MBID1, null, null, TITLE1, TYPE1, YEAR1, null);
    album2 = new MBRelease(MBID2, null, null, TITLE2, TYPE2, YEAR2, null);
    album1.setArtistId(artist.getId());
    album2.setArtistId(artist.getId());
    albumDao.createAlbums(Arrays.asList(album1, album2));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) MBRelease(com.github.hakko.musiccabinet.domain.model.music.MBRelease) Before(org.junit.Before)

Example 3 with MBRelease

use of com.github.hakko.musiccabinet.domain.model.music.MBRelease 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)

Example 4 with MBRelease

use of com.github.hakko.musiccabinet.domain.model.music.MBRelease in project musiccabinet by hakko.

the class ReleaseHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    if (TAG_RELEASE_LIST.equals(qName)) {
        totalAlbums = toInt(attributes.getValue(ATTR_COUNT));
    } else if (TAG_RELEASE.equals(qName)) {
        releases.add(currentRelease = new MBRelease());
    } else if (TAG_RELEASE_GROUP.equals(qName)) {
        currentRelease.setReleaseGroupMbid(attributes.getValue(ATTR_ID));
        currentRelease.setAlbumType(attributes.getValue(ATTR_TYPE));
    } else if (TAG_LABEL.equals(qName)) {
        currentRelease.setLabelMbid(attributes.getValue(ATTR_ID));
        label = true;
    }
    characterData = new StringBuilder();
}
Also used : MBRelease(com.github.hakko.musiccabinet.domain.model.music.MBRelease)

Aggregations

MBRelease (com.github.hakko.musiccabinet.domain.model.music.MBRelease)4 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 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 Before (org.junit.Before)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1