use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException in project aiode by robinfriedli.
the class SearchCommand method searchSpotifyEpisode.
private void searchSpotifyEpisode() throws Exception {
if (getCommandInput().isBlank()) {
throw new InvalidCommandException("No search term entered");
}
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
Callable<List<Episode>> loadTrackCallable = () -> getSpotifyService().searchEpisode(getCommandInput(), argumentSet("own"), limit);
List<Episode> found;
if (argumentSet("own")) {
found = runWithLogin(loadTrackCallable);
} else {
found = runWithCredentials(loadTrackCallable);
}
if (!found.isEmpty()) {
EmbedBuilder embedBuilder = new EmbedBuilder();
Util.appendEmbedList(embedBuilder, found, episode -> episode.getName() + " - " + episode.getShow().getName() + " - " + episode.getShow().getPublisher(), "Episode - Show - Publisher");
sendMessage(embedBuilder);
} else {
throw new NoSpotifyResultsFoundException(String.format("No podcast episode found for '%s'", getCommandInput()));
}
}
use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException in project aiode by robinfriedli.
the class SearchCommand method searchSpotifyTrack.
private void searchSpotifyTrack() throws Exception {
if (getCommandInput().isBlank()) {
throw new InvalidCommandException("No search term entered");
}
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.isEmpty()) {
EmbedBuilder embedBuilder = new EmbedBuilder();
Util.appendEmbedList(embedBuilder, found, track -> track.getName() + " - " + track.getAlbum().getName() + " - " + StringList.create(track.getArtists(), ArtistSimplified::getName).toSeparatedString(", "), "Track - Album - Artist");
sendMessage(embedBuilder);
} else {
throw new NoSpotifyResultsFoundException(String.format("No Spotify track found for '%s'", getCommandInput()));
}
}
use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException 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);
}
}
}
use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadSpotifyShow.
private void loadSpotifyShow(AudioManager audioManager) throws Exception {
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
Callable<List<ShowSimplified>> albumLoadCallable = () -> getSpotifyService().searchShow(getCommandInput(), argumentSet("own"), limit);
List<ShowSimplified> shows;
if (argumentSet("own")) {
shows = runWithLogin(albumLoadCallable);
} else {
shows = runWithCredentials(albumLoadCallable);
}
if (shows.size() == 1) {
ShowSimplified show = shows.get(0);
List<Episode> episodes = runWithCredentials(() -> getSpotifyService().getShowEpisodes(show.getId()));
PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), trackLoadingExecutor);
List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), episodes);
handleResults(playables);
loadedShow = show;
} else if (shows.isEmpty()) {
throw new NoSpotifyResultsFoundException(String.format("No shows found for '%s'", getCommandInput()));
} else {
askQuestion(shows, ShowSimplified::getName, ShowSimplified::getPublisher);
}
}
use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadSpotifyEpisode.
private void loadSpotifyEpisode(AudioManager audioManager) throws Exception {
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
Callable<List<Episode>> loadTrackCallable = () -> getSpotifyService().searchEpisode(getCommandInput(), argumentSet("own"), limit);
List<Episode> found;
if (argumentSet("own")) {
found = runWithLogin(loadTrackCallable);
} else {
found = runWithCredentials(loadTrackCallable);
}
if (found.size() == 1) {
createPlayableForEpisode(found.get(0), audioManager);
} else if (found.isEmpty()) {
throw new NoSpotifyResultsFoundException(String.format("No Spotify episode found for '%s'", getCommandInput()));
} else {
askQuestion(found, episode -> String.format("%s by %s", episode.getName(), episode.getShow().getName()));
}
}
Aggregations