Search in sources :

Example 6 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class ArtistInfoClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = ArtistInfoClient.METHOD;
    final String artistName = "madonna";
    final String lang = Locale.FRANCE.getLanguage();
    new ArtistInfoClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ARTIST_GET_INFO, wi.getCallType());
            Assert.assertTrue(artistName.equals(wi.getArtist().getName()));
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, artistName);
            assertHasParameter(params, PARAM_LANG, lang);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getArtistInfo(new Artist(artistName), lang);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 7 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class ArtistTopTagsClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = ArtistTopTagsClient.METHOD;
    final String artistName = "madonna";
    new ArtistTopTagsClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ARTIST_GET_TOP_TAGS, wi.getCallType());
            Assert.assertTrue(artistName.equals(wi.getArtist().getName()));
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, artistName);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getTopTags(new Artist(artistName));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 8 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist 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 9 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class MusicBrainzService method updateArtistIds.

protected void updateArtistIds() {
    List<Artist> missingArtists = artistDao.getMissingArtists();
    List<MBArtist> mbArtists = new ArrayList<>();
    mbids = missingArtists.size();
    for (Artist artist : artistDao.getMissingArtists()) {
        try {
            StringUtil response = new StringUtil(artistQueryClient.get(artist.getName()));
            ArtistQueryParser parser = new ArtistQueryParserImpl(response.getInputStream());
            if (parser.getArtist() != null) {
                mbArtists.add(parser.getArtist());
                if (mbArtists.size() > 100) {
                    artistDao.createArtists(mbArtists);
                    mbArtists.clear();
                }
            }
            ++mbid;
        } catch (ApplicationException e) {
            LOG.warn("Couldn't read mbid for " + artist.getName(), e);
        }
    }
    artistDao.createArtists(mbArtists);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) ArtistQueryParser(com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParser) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistQueryParserImpl(com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParserImpl)

Example 10 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class ArtistQueryClient method get.

public String get(String artistName) throws ApplicationException {
    WebserviceInvocation invocation = new WebserviceInvocation(MB_ARTIST_QUERY, new Artist(artistName));
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair(QUERY, ARTIST + escape(artistName)));
    params.add(new BasicNameValuePair(LIMIT, ONE));
    return executeWSRequest(invocation, PATH, params);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)

Aggregations

Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)66 Test (org.junit.Test)33 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)19 ArrayList (java.util.ArrayList)13 Album (com.github.hakko.musiccabinet.domain.model.music.Album)11 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)11 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)10 Track (com.github.hakko.musiccabinet.domain.model.music.Track)9 File (com.github.hakko.musiccabinet.domain.model.library.File)8 NameValuePair (org.apache.http.NameValuePair)8 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)7 Before (org.junit.Before)6 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)5 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)5 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)5 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)5 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)4 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)4 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)4 ResultSet (java.sql.ResultSet)4