Search in sources :

Example 6 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil 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 7 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil 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 8 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil 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 9 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.

the class ScrobbledTracksService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    short page = 0, totalPages = 0;
    do {
        WSResponse wsResponse = client.getLibraryTracks(page, lastFmSettingsService.getLastFmUsername());
        if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
            StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
            ScrobbledTracksParser parser = new ScrobbledTracksParserImpl(stringUtil.getInputStream());
            totalPages = parser.getTotalPages();
            trackPlayCountDao.createTrackPlayCounts(parser.getTrackPlayCounts());
            setTotalOperations(totalPages);
            addFinishedOperation();
        }
    } while (++page < totalPages);
}
Also used : ScrobbledTracksParser(com.github.hakko.musiccabinet.parser.lastfm.ScrobbledTracksParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ScrobbledTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ScrobbledTracksParserImpl)

Example 10 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil 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

StringUtil (com.github.hakko.musiccabinet.util.StringUtil)19 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)15 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)14 ArrayList (java.util.ArrayList)10 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)5 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)4 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)3 Test (org.junit.Test)3 UserRecommendedArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)2 MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)2 ArtistInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl)2 ArtistTopTracksParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl)2 UserRecommendedArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl)2 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 RecommendedArtist (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)1 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)1 UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)1 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)1