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);
}
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")));
}
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"));
}
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);
}
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);
}
Aggregations