Search in sources :

Example 11 with ApplicationException

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();
}
Also used : AudioFile(org.jaudiotagger.audio.AudioFile) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) TagException(org.jaudiotagger.tag.TagException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) FlacTag(org.jaudiotagger.tag.flac.FlacTag) Tag(org.jaudiotagger.tag.Tag) AbstractID3v2Tag(org.jaudiotagger.tag.id3.AbstractID3v2Tag) IOException(java.io.IOException)

Example 12 with ApplicationException

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);
}
Also used : AlbumInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) ArrayList(java.util.ArrayList) AlbumInfoParser(com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParser) Album(com.github.hakko.musiccabinet.domain.model.music.Album) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 13 with ApplicationException

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();
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ArtistTopTagsParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParser) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistTopTagsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 14 with ApplicationException

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);
}
Also used : LastFmGroup(com.github.hakko.musiccabinet.domain.model.library.LastFmGroup) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) GroupWeeklyArtistChart(com.github.hakko.musiccabinet.domain.model.aggr.GroupWeeklyArtistChart) GroupWeeklyArtistChartParser(com.github.hakko.musiccabinet.parser.lastfm.GroupWeeklyArtistChartParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) GroupWeeklyArtistChartParserImpl(com.github.hakko.musiccabinet.parser.lastfm.GroupWeeklyArtistChartParserImpl)

Example 15 with ApplicationException

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);
}
Also used : TagTopArtistsParser(com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParser) TagTopArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParserImpl) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) TagTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)

Aggregations

ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)43 Test (org.junit.Test)20 NameValuePair (org.apache.http.NameValuePair)18 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)14 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)11 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)11 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)10 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)10 ArrayList (java.util.ArrayList)8 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)7 IOException (java.io.IOException)6 Track (com.github.hakko.musiccabinet.domain.model.music.Track)4 ArtistUserTag (com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag)2 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)2 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)2 Period (com.github.hakko.musiccabinet.domain.model.library.Period)2 Album (com.github.hakko.musiccabinet.domain.model.music.Album)2 MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)2 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)2 ArtistInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl)2