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;
}
}
}
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);
}
}
}
}
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;
}
}
}
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);
}
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();
}
}
Aggregations