use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.
the class QueueCommand method withUserResponse.
@Override
public void withUserResponse(Object chosenOption) throws Exception {
AudioManager audioManager = Aiode.get().getAudioManager();
PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), getTrackLoadingExecutor());
AudioQueue queue = audioManager.getQueue(getContext().getGuild());
List<Playable> playables;
if (chosenOption instanceof Collection) {
playables = playableFactory.createPlayables(shouldRedirectSpotify(), chosenOption);
loadedAmount = playables.size();
} else {
playables = getPlayablesForOption(chosenOption, playableFactory);
}
queue.add(playables);
}
use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.
the class StopCommand method doRun.
@Override
public void doRun() {
Guild guild = getContext().getGuild();
AudioManager audioManager = Aiode.get().getAudioManager();
AudioPlayback playback = audioManager.getPlaybackForGuild(guild);
getContext().getGuildContext().getReplaceableTrackLoadingExecutor().abort();
playback.stop();
playback.getAudioQueue().clear();
}
use of net.robinfriedli.aiode.audio.AudioManager 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(", "));
}
}
use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadYouTubeVideo.
private void loadYouTubeVideo(AudioManager audioManager) throws IOException {
YouTubeService youTubeService = audioManager.getYouTubeService();
if (argumentSet("select")) {
int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 10);
List<YouTubeVideo> youTubeVideos = youTubeService.searchSeveralVideos(limit, getCommandInput());
if (youTubeVideos.size() == 1) {
Playable playable = youTubeVideos.get(0);
handleResults(Lists.newArrayList(playable));
loadedTrack = playable;
} else if (youTubeVideos.isEmpty()) {
throw new NoResultsFoundException(String.format("No YouTube video found for '%s'", getCommandInput()));
} else {
askQuestion(youTubeVideos, youTubeVideo -> {
try {
return youTubeVideo.getDisplay();
} catch (UnavailableResourceException e) {
// Unreachable since only HollowYouTubeVideos might get interrupted
throw new RuntimeException(e);
}
});
}
} else {
YouTubeVideo youTubeVideo = youTubeService.searchVideo(getCommandInput());
handleResults(Lists.newArrayList(youTubeVideo));
loadedTrack = youTubeVideo;
}
}
use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method doRun.
@Override
public void doRun() throws Exception {
AudioManager audioManager = Aiode.get().getAudioManager();
AudioPlayback playback = audioManager.getPlaybackForGuild(getContext().getGuild());
if (UrlValidator.getInstance().isValid(getCommandInput())) {
loadUrlItems(audioManager, playback);
} else if (SpotifyUri.isSpotifyUri(getCommandInput())) {
loadSpotifyUri(audioManager);
} else if (argumentSet("list")) {
Source source = getSource();
if (source.isSpotify()) {
loadSpotifyList(audioManager);
} else if (source.isYouTube()) {
loadYouTubeList(audioManager);
} else {
loadLocalList(audioManager);
}
} else if (argumentSet("episode")) {
loadSpotifyEpisode(audioManager);
} else if (argumentSet("podcast")) {
loadSpotifyShow(audioManager);
} else {
Source source = getSource();
if (source.isYouTube()) {
loadYouTubeVideo(audioManager);
} else if (source.isSoundCloud()) {
loadSoundCloudTrack(audioManager);
} else if (argumentSet("album")) {
loadSpotifyAlbum(audioManager);
} else {
loadTrack(audioManager);
}
}
}
Aggregations