use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class AudioTagService method getArtwork.
public Artwork getArtwork(java.io.File file) throws ApplicationException {
Tag tag = null;
try {
AudioFile audioFile = AudioFileIO.read(file);
tag = audioFile.getTag();
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException | RuntimeException e) {
throw new ApplicationException("Failed reading artwork from file " + file, e);
}
return tag == null ? null : tag.getFirstArtwork();
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class AlbumInfoService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<Album> albums = albumInfoDao.getAlbumsWithoutInfo();
List<AlbumInfo> albumInfos = new ArrayList<>();
setTotalOperations(albums.size());
for (Album album : albums) {
try {
WSResponse wsResponse = albumInfoClient.getAlbumInfo(album);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
AlbumInfoParser aiParser = new AlbumInfoParserImpl(stringUtil.getInputStream());
albumInfos.add(aiParser.getAlbumInfo());
if (albumInfos.size() == BATCH_SIZE) {
albumInfoDao.createAlbumInfo(albumInfos);
albumInfos.clear();
}
}
} catch (ApplicationException e) {
LOG.warn("Fetching album info for " + album.getName() + " failed.", e);
}
addFinishedOperation();
}
albumInfoDao.createAlbumInfo(albumInfos);
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class ArtistTopTagsService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_TOP_TAGS);
setTotalOperations(artistNames.size());
for (String artistName : artistNames) {
try {
WSResponse wsResponse = artistTopTagsClient.getTopTags(new Artist(artistName));
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
ArtistTopTagsParser attParser = new ArtistTopTagsParserImpl(stringUtil.getInputStream());
removeTagsWithLowTagCount(attParser.getTopTags());
artistTopTagsDao.createTopTags(attParser.getArtist(), attParser.getTopTags());
}
} catch (ApplicationException e) {
LOG.warn("Fetching top tags for " + artistName + " failed.", e);
}
addFinishedOperation();
}
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class GroupWeeklyArtistChartService method updateSearchIndex.
@Override
public void updateSearchIndex() throws ApplicationException {
List<GroupWeeklyArtistChart> artistCharts = new ArrayList<>();
List<LastFmGroup> groups = lastFmDao.getLastFmGroups();
setTotalOperations(groups.size());
for (LastFmGroup group : groups) {
try {
WSResponse wsResponse = client.getWeeklyArtistChart(group);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
GroupWeeklyArtistChartParser parser = new GroupWeeklyArtistChartParserImpl(stringUtil.getInputStream());
artistCharts.add(new GroupWeeklyArtistChart(group.getName(), parser.getArtistPlayCount()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching weekly artist chart for " + group.getName() + " failed.", e);
}
addFinishedOperation();
}
dao.createArtistCharts(artistCharts);
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class TagTopArtistsService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<TagTopArtists> topArtists = new ArrayList<>();
List<Tag> tags = tagDao.getTagsWithoutTopArtists();
setTotalOperations(tags.size());
for (Tag tag : tags) {
try {
WSResponse wsResponse = tagTopArtistsClient.getTopArtists(tag);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
TagTopArtistsParser parser = new TagTopArtistsParserImpl(stringUtil.getInputStream());
topArtists.add(new TagTopArtists(tag.getName(), parser.getArtists()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching top artist for " + tag.getName() + " failed.", e);
}
addFinishedOperation();
}
tagDao.createTopArtists(topArtists);
}
Aggregations