Search in sources :

Example 1 with ArtistSimilarityParser

use of com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParser in project musiccabinet by hakko.

the class ArtistRelationService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_SIMILAR);
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistSimilarityClient.getArtistSimilarity(new Artist(artistName));
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistSimilarityParser asParser = new ArtistSimilarityParserImpl(stringUtil.getInputStream());
                artistRelationDao.createArtistRelations(asParser.getArtist(), asParser.getArtistRelations());
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching artist relations for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ArtistSimilarityParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParser) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistSimilarityParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 2 with ArtistSimilarityParser

use of com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParser in project musiccabinet by hakko.

the class JdbcPlaylistGeneratorDaoTest method prepareTestdataForArtist.

private int prepareTestdataForArtist() throws ApplicationException {
    ArtistSimilarityParser asParser = new ArtistSimilarityParserImpl(new ResourceUtil(CHER_SIMILAR_ARTISTS).getInputStream());
    artistRelationDao.createArtistRelations(asParser.getArtist(), asParser.getArtistRelations());
    ArtistTopTracksParser attParser = new ArtistTopTracksParserImpl(new ResourceUtil(CHER_TOP_TRACKS).getInputStream());
    artistTopTracksDao.createTopTracks(attParser.getArtist(), attParser.getTopTracks());
    List<File> files = new ArrayList<>();
    for (Track topTrack : attParser.getTopTracks()) {
        files.add(UnittestLibraryUtil.getFile(topTrack));
    }
    UnittestLibraryUtil.submitFile(additionDao, files);
    int artistId = musicDao.getArtistId(asParser.getArtist());
    playlistGeneratorDao.updateSearchIndex();
    return artistId;
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ArtistSimilarityParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParser) ArtistSimilarityParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParserImpl) ArrayList(java.util.ArrayList) ArtistTopTracksParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParser) ArtistTopTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) Track(com.github.hakko.musiccabinet.domain.model.music.Track)

Aggregations

ArtistSimilarityParser (com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParser)2 ArtistSimilarityParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParserImpl)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)1 Track (com.github.hakko.musiccabinet.domain.model.music.Track)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 ArtistTopTracksParser (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParser)1 ArtistTopTracksParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1