Search in sources :

Example 1 with Album

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

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

the class JdbcLibraryBrowserDaoAggregationTest method prepareTestData.

@Before
public void prepareTestData() throws ApplicationException {
    PostgreSQLUtil.loadFunction(browserDao, ADD_TO_LIBRARY);
    browserDao.getJdbcTemplate().execute("truncate music.artist cascade");
    browserDao.getJdbcTemplate().execute("truncate library.file cascade");
    submitFile(additionDao, UnittestLibraryUtil.getFile(artistName1, albumName1, trackName1));
    submitFile(additionDao, UnittestLibraryUtil.getFile(artistName1, albumName2, trackName1));
    List<Artist> artists = browserDao.getArtists();
    Assert.assertEquals(1, artists.size());
    artist1 = artists.get(0);
    List<Album> albums = browserDao.getAlbums(artists.get(0).getId(), true);
    Assert.assertEquals(2, albums.size());
    Assert.assertEquals(1, albums.get(0).getTrackIds().size());
    Assert.assertEquals(1, albums.get(1).getTrackIds().size());
    Collections.sort(albums, getAlbumComparator());
    album1 = albums.get(0);
    album2 = albums.get(1);
    track1 = browserDao.getTracks(album1.getTrackIds()).get(0);
    track2 = browserDao.getTracks(album2.getTrackIds()).get(0);
    user1 = new LastFmUser(userName1);
    lastFmDao.createOrUpdateLastFmUser(user1);
    user2 = new LastFmUser(userName2);
    lastFmDao.createOrUpdateLastFmUser(user2);
    artistInfoDao.createArtistInfo(asList(new ArtistInfo(new Artist(artistName1), "img")));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) Album(com.github.hakko.musiccabinet.domain.model.music.Album) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) Before(org.junit.Before)

Example 3 with Album

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

the class LibraryBrowserServiceTest method addsCoverArtPathForTrack.

@Test
public void addsCoverArtPathForTrack() throws Exception {
    Artist artist = new Artist("Artist Name");
    int artistId = musicDao.getArtistId(artist);
    scannerService.add(set(media3));
    List<Album> albums = browserService.getAlbums(artistId, false, true);
    int trackId = albums.get(0).getTrackIds().get(0);
    List<Track> tracks = browserService.getTracks(asList(trackId));
    Assert.assertNotNull(tracks);
    Assert.assertEquals(1, tracks.size());
    Assert.assertNull(tracks.get(0).getMetaData().getArtworkPath());
    browserService.addArtwork(tracks);
    String artworkPath = tracks.get(0).getMetaData().getArtworkPath();
    Assert.assertNotNull(artworkPath);
    Assert.assertTrue(artworkPath.endsWith("Embedded artwork" + separatorChar + "Embedded artwork.mp3"));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) Album(com.github.hakko.musiccabinet.domain.model.music.Album) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 4 with Album

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

the class LibraryBrowserServiceTest method findsTracks.

@Test
public void findsTracks() throws Exception {
    scannerService.add(set(media1));
    Artist artist = new Artist("The Beatles");
    int artistId = musicDao.getArtistId(artist);
    List<Album> albums = browserService.getAlbums(artistId, true);
    Album redAlbum = getAlbum(albums, "1962-1966");
    List<Track> tracks = browserService.getTracks(redAlbum.getTrackIds());
    List<Track> expectedTracks = new ArrayList<>();
    for (String title : asList("Love Me Do", "Please Please Me", "From Me To You", "She Loves You", "Help!")) {
        expectedTracks.add(new Track("The Beatles", title));
    }
    assertTracks(tracks, expectedTracks);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ArrayList(java.util.ArrayList) Album(com.github.hakko.musiccabinet.domain.model.music.Album) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 5 with Album

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

the class LibraryBrowserServiceTest method findsVariousArtistsTracks.

@Test
public void findsVariousArtistsTracks() throws Exception {
    scannerService.add(set(media5));
    Artist artist = new Artist("Various Artists");
    int artistId = musicDao.getArtistId(artist);
    List<Album> albums = browserService.getAlbums(artistId, true);
    assertAlbums(albums, artist, "Music From Searching For Wrong-Eyed Jesus");
    Album album = albums.get(0);
    List<Track> tracks = browserService.getTracks(album.getTrackIds());
    List<Track> expectedTracks = asList(new Track("Harry Crews", "Everything Was Stories"), new Track("Jim White", "Still Waters"), new Track("The Handsome Family", "My Sister's Tiny Hands"));
    assertTracks(tracks, expectedTracks);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) Album(com.github.hakko.musiccabinet.domain.model.music.Album) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Aggregations

Album (com.github.hakko.musiccabinet.domain.model.music.Album)22 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)11 Test (org.junit.Test)10 Track (com.github.hakko.musiccabinet.domain.model.music.Track)5 AlbumInfo (com.github.hakko.musiccabinet.domain.model.music.AlbumInfo)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)2 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 AlbumRowMapper (com.github.hakko.musiccabinet.dao.jdbc.rowmapper.AlbumRowMapper)1 NameSearchResult (com.github.hakko.musiccabinet.domain.model.aggr.NameSearchResult)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)1 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)1 AlbumInfoParser (com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParser)1 AlbumInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl)1 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1