use of net.robinfriedli.aiode.audio.exec.TrackLoadingExecutor in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadSpotifyAlbum.
private void loadSpotifyAlbum(AudioManager audioManager) throws Exception {
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
Callable<List<AlbumSimplified>> albumLoadCallable = () -> getSpotifyService().searchAlbum(getCommandInput(), argumentSet("own"), limit);
List<AlbumSimplified> albums;
if (argumentSet("own")) {
albums = runWithLogin(albumLoadCallable);
} else {
albums = runWithCredentials(albumLoadCallable);
}
if (albums.size() == 1) {
AlbumSimplified album = albums.get(0);
List<Track> tracks = runWithCredentials(() -> getSpotifyService().getAlbumTracks(album.getId()));
PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), trackLoadingExecutor);
List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), tracks);
handleResults(playables);
loadedAlbum = album;
} else if (albums.isEmpty()) {
throw new NoSpotifyResultsFoundException(String.format("No albums found for '%s'", getCommandInput()));
} else {
askQuestion(albums, AlbumSimplified::getName, album -> StringList.create(album.getArtists(), ArtistSimplified::getName).toSeparatedString(", "));
}
}
Aggregations