Search in sources :

Example 11 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class ScrobbleServiceTest method createTestData.

@Before
public void createTestData() throws ApplicationException {
    scrobbleService = new ScrobbleService();
    UpdateNowPlayingClient nowPlayinglient = mock(UpdateNowPlayingClient.class);
    when(nowPlayinglient.updateNowPlaying(Mockito.any(Scrobble.class))).thenReturn(new WSResponse(false, 404, "Not found"));
    scrobbleService.setUpdateNowPlayingClient(nowPlayinglient);
    ScrobbleClient scrobbleClient = mock(ScrobbleClient.class);
    when(scrobbleClient.scrobble(Mockito.any(Scrobble.class))).thenReturn(new WSResponse("<lfm status=\"ok\"></lfm>"));
    scrobbleService.setScrobbleClient(scrobbleClient);
    PlayCountDao playCountDao = mock(PlayCountDao.class);
    scrobbleService.setPlayCountDao(playCountDao);
    MetaData metaData1 = new MetaData();
    metaData1.setArtist("artist 1");
    metaData1.setArtistId(artist1Id);
    metaData1.setAlbum("album 1");
    metaData1.setAlbumId(album1Id);
    track1 = new Track(track1Id, "track 1", metaData1);
    track2 = new Track(track2Id, "track 2", metaData1);
    user1 = new LastFmUser(username1, sessionKey1);
    user2 = new LastFmUser(username2, sessionKey2);
}
Also used : ScrobbleClient(com.github.hakko.musiccabinet.ws.lastfm.ScrobbleClient) MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) UpdateNowPlayingClient(com.github.hakko.musiccabinet.ws.lastfm.UpdateNowPlayingClient) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) Track(com.github.hakko.musiccabinet.domain.model.music.Track) PlayCountDao(com.github.hakko.musiccabinet.dao.PlayCountDao) Before(org.junit.Before)

Example 12 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class TagUpdateServiceTest method createTestData.

@Before
public void createTestData() throws ApplicationException {
    responseOK = new WSResponse("<lfm status=\"ok\"></lfm>");
    responseFail = new WSResponse(false, 404, "Not found");
}
Also used : WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) Before(org.junit.Before)

Example 13 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class JdbcUserRecommendedArtistsDaoTest method loadFunctionDependency.

@Before
public void loadFunctionDependency() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_USER_RECOMMENDED_ARTISTS);
    joanRec = new UserRecommendedArtists(joan, new UserRecommendedArtistsParserImpl(new ResourceUtil(JOAN_FILE).getInputStream()).getArtists());
    rjRec = new UserRecommendedArtists(rj, new UserRecommendedArtistsParserImpl(new ResourceUtil(RJ_FILE).getInputStream()).getArtists());
    String body = new WSResponse(new ResourceUtil(FTPAREA_FILE).getContent()).getResponseBody();
    ftpareaRec = new UserRecommendedArtists(ftparea, new UserRecommendedArtistsParserImpl(new StringUtil(body).getInputStream()).getArtists());
    createArtistMetaData();
}
Also used : UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserRecommendedArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) Before(org.junit.Before)

Example 14 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class LastFmService method identifyLastFmUser.

public LastFmUser identifyLastFmUser(String token) throws ApplicationException {
    LOG.debug("identifyLastFmUser(" + token + ")");
    WSResponse wsResponse = authSessionClient.getAuthSession(token);
    if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
        StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
        AuthSessionParser authSessionParser = new AuthSessionParserImpl(stringUtil.getInputStream());
        return authSessionParser.getLastFmUser();
    } else {
        LOG.debug("wsResponse: " + wsResponse.getResponseBody());
        throw new ApplicationException("Could not get session key for user! (code " + wsResponse.getErrorCode() + ", " + wsResponse.getErrorMessage() + ")");
    }
}
Also used : AuthSessionParser(com.github.hakko.musiccabinet.parser.lastfm.AuthSessionParser) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) AuthSessionParserImpl(com.github.hakko.musiccabinet.parser.lastfm.AuthSessionParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 15 with WSResponse

use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.

the class ScrobbleService method scrobbleTracks.

protected void scrobbleTracks() throws ApplicationException {
    scrobbleFailedTracks();
    Scrobble head;
    for (LastFmUser lastFmUser : userScrobbles.keySet()) {
        ConcurrentLinkedDeque<Scrobble> deque = userScrobbles.get(lastFmUser);
        while ((head = deque.peekFirst()) != null && !tooClose(head, new DateTime())) {
            playCountDao.addPlayCount(head.getLastFmUser(), head.getTrack());
            WSResponse wsResponse = scrobbleClient.scrobble(head);
            if (!wsResponse.wasCallSuccessful()) {
                LOG.warn("scrobbling " + head + " failed! Add for re-sending.");
                LOG.debug("Scrobble response: " + wsResponse);
                failedScrobbles.add(head);
            }
            deque.pollFirst();
        }
    }
}
Also used : LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) DateTime(org.joda.time.DateTime)

Aggregations

WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)25 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)15 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)11 ArrayList (java.util.ArrayList)8 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)7 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)5 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)5 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)4 Track (com.github.hakko.musiccabinet.domain.model.music.Track)3 Before (org.junit.Before)3 ArtistUserTag (com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag)2 UserRecommendedArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)2 UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)2 Period (com.github.hakko.musiccabinet.domain.model.library.Period)2 UserRecommendedArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl)2 Test (org.junit.Test)2 PlayCountDao (com.github.hakko.musiccabinet.dao.PlayCountDao)1 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