Search in sources :

Example 16 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class ScrobbleService method scrobbleFailedTracks.

protected void scrobbleFailedTracks() throws ApplicationException {
    while (failedScrobbles.size() > 0) {
        LOG.debug("Queue of failed scrobbles consists of " + failedScrobbles.size() + " elements.");
        Scrobble firstFailed = failedScrobbles.get(0);
        WSResponse wsResponse = scrobbleClient.scrobble(firstFailed);
        if (wsResponse.wasCallSuccessful()) {
            LOG.debug("Failed scrobble was re-sent.");
            failedScrobbles.remove(0);
        } else {
            LOG.debug("Failed scrobble could not be re-sent. Wait a minute before trying again.");
            LOG.debug("Response: " + wsResponse);
            return;
        }
    }
}
Also used : Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse)

Example 17 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class TagUpdateService method updateTags.

protected void updateTags() throws ApplicationException {
    resendFailedUpdates();
    ArtistUserTag aut;
    while (failedUpdates.isEmpty() && (aut = artistUserTags.poll()) != null) {
        if ((aut.isIncrease() && aut.getTagCount() >= MAX_THRESHOLD) || (!aut.isIncrease() && aut.getTagCount() <= MIN_THRESHOLD)) {
            WSResponse wsResponse = tagUpdateClient.updateTag(aut);
            if (!wsResponse.wasCallSuccessful()) {
                LOG.warn("updating " + aut + " failed! Add for re-sending.");
                LOG.debug("Response: " + wsResponse);
                failedUpdates.add(aut);
            }
        }
    }
}
Also used : ArtistUserTag(com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse)

Example 18 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class TagUpdateService method resendFailedUpdates.

protected void resendFailedUpdates() throws ApplicationException {
    while (failedUpdates.size() > 0) {
        LOG.debug("Queue of failed updates consists of " + failedUpdates.size() + " elements.");
        ArtistUserTag firstFailed = failedUpdates.get(0);
        WSResponse wsResponse = tagUpdateClient.updateTag(firstFailed);
        if (wsResponse.wasCallSuccessful()) {
            LOG.debug("Failed tag update was re-sent.");
            failedUpdates.remove(0);
        } else {
            LOG.debug("Failed tag update could not be re-sent. Wait a minute before trying again.");
            LOG.debug("Response: " + wsResponse);
            return;
        }
    }
}
Also used : ArtistUserTag(com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse)

Example 19 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class ArtistInfoService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_INFO);
    List<ArtistInfo> artistInfos = new ArrayList<>(artistNames.size());
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistInfoClient.getArtistInfo(new Artist(artistName), lastFmSettingsService.getLang());
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistInfoParser aiParser = new ArtistInfoParserImpl(stringUtil.getInputStream());
                if (aiParser.getArtistInfo() != null) {
                    artistInfos.add(aiParser.getArtistInfo());
                } else {
                    LOG.warn("Artist info response for " + artistName + " not parsed correctly. Response was " + wsResponse.getResponseBody());
                }
                if (artistInfos.size() == BATCH_SIZE) {
                    artistInfoDao.createArtistInfo(artistInfos);
                    artistInfos.clear();
                }
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching artist info for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
    artistInfoDao.createArtistInfo(artistInfos);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl) ArrayList(java.util.ArrayList) ArtistInfoParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)

Example 20 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse 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)

Aggregations

WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)25 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)15 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)11 ArrayList (java.util.ArrayList)8 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)7 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)5 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)5 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)4 Track (com.github.hakko.musiccabinet.domain.model.music.Track)3 Before (org.junit.Before)3 ArtistUserTag (com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag)2 UserRecommendedArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)2 UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)2 Period (com.github.hakko.musiccabinet.domain.model.library.Period)2 UserRecommendedArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl)2 Test (org.junit.Test)2 PlayCountDao (com.github.hakko.musiccabinet.dao.PlayCountDao)1 GroupWeeklyArtistChart (com.github.hakko.musiccabinet.domain.model.aggr.GroupWeeklyArtistChart)1 TagTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)1 UserLovedTracks (com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks)1