use of net.robinfriedli.aiode.exceptions.NoResultsFoundException in project aiode by robinfriedli.
the class SearchCommand method listYouTubePlaylists.
private void listYouTubePlaylists() throws IOException {
YouTubeService youTubeService = Aiode.get().getAudioManager().getYouTubeService();
if (argumentSet("select")) {
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 10);
List<YouTubePlaylist> playlists = youTubeService.searchSeveralPlaylists(limit, getCommandInput());
if (playlists.size() == 1) {
listYouTubePlaylist(playlists.get(0));
} else if (playlists.isEmpty()) {
throw new NoResultsFoundException(String.format("No YouTube playlist found for '%s'", getCommandInput()));
} else {
askQuestion(playlists, YouTubePlaylist::getTitle, YouTubePlaylist::getChannelTitle);
}
} else {
listYouTubePlaylist(youTubeService.searchPlaylist(getCommandInput()));
}
}
use of net.robinfriedli.aiode.exceptions.NoResultsFoundException in project aiode by robinfriedli.
the class SearchCommand method listLocalList.
private void listLocalList() {
if (getCommandInput().isBlank()) {
Session session = getContext().getSession();
List<Playlist> playlists = getQueryBuilderFactory().find(Playlist.class).build(session).getResultList();
EmbedBuilder embedBuilder = new EmbedBuilder();
if (playlists.isEmpty()) {
embedBuilder.setDescription("No playlists");
} else {
EmbedTable table = new EmbedTable(embedBuilder);
table.addColumn("Playlist", playlists, Playlist::getName);
table.addColumn("Duration", playlists, playlist -> Util.normalizeMillis(playlist.getDuration()));
table.addColumn("Items", playlists, playlist -> String.valueOf(playlist.getSize()));
table.build();
}
sendMessage(embedBuilder);
} else {
Playlist playlist = SearchEngine.searchLocalList(getContext().getSession(), getCommandInput());
if (playlist == null) {
throw new NoResultsFoundException(String.format("No local list found for '%s'", getCommandInput()));
}
String createdUserId = playlist.getCreatedUserId();
String createdUser;
if (createdUserId.equals("system")) {
createdUser = playlist.getCreatedUser();
} else {
ShardManager shardManager = Aiode.get().getShardManager();
User userById;
try {
userById = shardManager.retrieveUserById(createdUserId).complete();
} catch (ErrorResponseException e) {
if (e.getErrorResponse() == ErrorResponse.UNKNOWN_USER) {
userById = null;
} else {
throw e;
}
}
createdUser = userById != null ? userById.getName() : playlist.getCreatedUser();
}
SpringPropertiesConfig springPropertiesConfig = Aiode.get().getSpringPropertiesConfig();
String baseUri = springPropertiesConfig.requireApplicationProperty("aiode.server.base_uri");
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.addField("Name", playlist.getName(), true);
embedBuilder.addField("Duration", Util.normalizeMillis(playlist.getDuration()), true);
embedBuilder.addField("Created by", createdUser, true);
embedBuilder.addField("Tracks", String.valueOf(playlist.getSize()), true);
embedBuilder.addBlankField(false);
String url = baseUri + String.format("/list?name=%s&guildId=%s", URLEncoder.encode(playlist.getName(), StandardCharsets.UTF_8), playlist.getGuildId());
embedBuilder.addField("First tracks:", "[Full list](" + url + ")", false);
List<PlaylistItem> items = playlist.getItemsSorted();
Util.appendEmbedList(embedBuilder, items.size() > 5 ? items.subList(0, 5) : items, item -> item.display() + " - " + Util.normalizeMillis(item.getDuration()), "Track - Duration");
sendWithLogo(embedBuilder);
}
}
use of net.robinfriedli.aiode.exceptions.NoResultsFoundException in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadUrlItems.
private void loadUrlItems(AudioManager audioManager, AudioPlayback playback) throws IOException {
PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), trackLoadingExecutor);
List<Playable> playables = playableFactory.createPlayables(getCommandInput(), getContext().getSpotifyApi(), shouldRedirectSpotify());
if (playables.isEmpty()) {
throw new NoResultsFoundException("Result is empty!");
}
handleResults(playables);
loadedAmount = playables.size();
}
use of net.robinfriedli.aiode.exceptions.NoResultsFoundException in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadSoundCloudTrack.
private void loadSoundCloudTrack(AudioManager audioManager) {
AudioTrackLoader audioTrackLoader = new AudioTrackLoader(audioManager.getPlayerManager());
String commandInput = getCommandInput();
AudioItem audioItem = audioTrackLoader.loadByIdentifier("scsearch:" + commandInput);
if (audioItem instanceof AudioTrack) {
AudioTrack audioTrack = (AudioTrack) audioItem;
handleResults(Lists.newArrayList(new UrlPlayable(audioTrack)));
this.loadedAudioTrack = audioTrack;
} else if (audioItem == null) {
throw new NoResultsFoundException(String.format("No soundcloud track found for '%s'", commandInput));
} else if (audioItem instanceof AudioPlaylist) {
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
List<AudioTrack> tracks = ((AudioPlaylist) audioItem).getTracks();
if (tracks.isEmpty()) {
throw new NoResultsFoundException(String.format("No soundcloud track found for '%s'", commandInput));
}
if (tracks.size() > limit) {
tracks = tracks.subList(0, limit);
}
askQuestion(tracks, audioTrack -> audioTrack.getInfo().title, audioTrack -> audioTrack.getInfo().author);
}
}
use of net.robinfriedli.aiode.exceptions.NoResultsFoundException in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadLocalList.
private void loadLocalList(AudioManager audioManager) throws Exception {
Playlist playlist = SearchEngine.searchLocalList(getContext().getSession(), getCommandInput());
if (playlist == null) {
throw new NoResultsFoundException(String.format("No local playlist found for '%s'", getCommandInput()));
}
List<Object> items = runWithCredentials(() -> playlist.getTracks(getContext().getSpotifyApi()));
if (items.isEmpty()) {
throw new NoResultsFoundException("Playlist is empty");
}
PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), trackLoadingExecutor);
List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), items);
handleResults(playables);
loadedLocalList = playlist;
}
Aggregations