use of net.robinfriedli.aiode.audio.spotify.SpotifyTrackResultHandler in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadTrack.
private void loadTrack(AudioManager audioManager) throws Exception {
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
Callable<List<Track>> loadTrackCallable = () -> getSpotifyService().searchTrack(getCommandInput(), argumentSet("own"), limit);
List<Track> found;
if (argumentSet("own")) {
found = runWithLogin(loadTrackCallable);
} else {
found = runWithCredentials(loadTrackCallable);
}
if (found.size() == 1) {
createPlayableForTrack(found.get(0), audioManager);
} else if (found.isEmpty()) {
throw new NoSpotifyResultsFoundException(String.format("No Spotify track found for '%s'", getCommandInput()));
} else {
if (argumentSet("select")) {
askQuestion(found, track -> {
String artistString = StringList.create(track.getArtists(), ArtistSimplified::getName).toSeparatedString(", ");
return String.format("%s by %s", track.getName(), artistString);
}, track -> track.getAlbum().getName());
} else {
SpotifyTrackResultHandler resultHandler = new SpotifyTrackResultHandler(getContext().getGuild(), getContext().getSession());
createPlayableForTrack(resultHandler.getBestResult(getCommandInput(), found), audioManager);
}
}
}
Aggregations