Search in sources :

Example 11 with AudioManager

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);
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) PlayableFactory(net.robinfriedli.aiode.audio.PlayableFactory) Playable(net.robinfriedli.aiode.audio.Playable) Collection(java.util.Collection) AudioQueue(net.robinfriedli.aiode.audio.AudioQueue)

Example 12 with AudioManager

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();
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) Guild(net.dv8tion.jda.api.entities.Guild)

Example 13 with AudioManager

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(", "));
    }
}
Also used : StringList(net.robinfriedli.stringlist.StringList) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException) PlayableFactory(net.robinfriedli.aiode.audio.PlayableFactory) UrlPlayable(net.robinfriedli.aiode.audio.UrlPlayable) YouTubePlaylist(net.robinfriedli.aiode.audio.youtube.YouTubePlaylist) SpotifyTrack(net.robinfriedli.aiode.audio.spotify.SpotifyTrack) Playable(net.robinfriedli.aiode.audio.Playable) Episode(se.michaelthelin.spotify.model_objects.specification.Episode) Callable(java.util.concurrent.Callable) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) Lists(com.google.common.collect.Lists) Playlist(net.robinfriedli.aiode.entities.Playlist) YouTubeVideo(net.robinfriedli.aiode.audio.youtube.YouTubeVideo) SearchEngine(net.robinfriedli.aiode.util.SearchEngine) Track(se.michaelthelin.spotify.model_objects.specification.Track) CommandContribution(net.robinfriedli.aiode.entities.xml.CommandContribution) SpotifyUri(net.robinfriedli.aiode.audio.spotify.SpotifyUri) UnavailableResourceException(net.robinfriedli.aiode.exceptions.UnavailableResourceException) ArtistSimplified(se.michaelthelin.spotify.model_objects.specification.ArtistSimplified) CommandManager(net.robinfriedli.aiode.command.CommandManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) IOException(java.io.IOException) AudioManager(net.robinfriedli.aiode.audio.AudioManager) NoSpotifyResultsFoundException(net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException) AudioItem(com.sedmelluq.discord.lavaplayer.track.AudioItem) UrlValidator(org.apache.commons.validator.routines.UrlValidator) Aiode(net.robinfriedli.aiode.Aiode) ShowSimplified(se.michaelthelin.spotify.model_objects.specification.ShowSimplified) List(java.util.List) AudioTrackLoader(net.robinfriedli.aiode.audio.AudioTrackLoader) SpotifyTrackResultHandler(net.robinfriedli.aiode.audio.spotify.SpotifyTrackResultHandler) SpotifyService(net.robinfriedli.aiode.audio.spotify.SpotifyService) CommandContext(net.robinfriedli.aiode.command.CommandContext) PlaylistSimplified(se.michaelthelin.spotify.model_objects.specification.PlaylistSimplified) AlbumSimplified(se.michaelthelin.spotify.model_objects.specification.AlbumSimplified) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) TrackLoadingExecutor(net.robinfriedli.aiode.audio.exec.TrackLoadingExecutor) YouTubeService(net.robinfriedli.aiode.audio.youtube.YouTubeService) PlayableFactory(net.robinfriedli.aiode.audio.PlayableFactory) UrlPlayable(net.robinfriedli.aiode.audio.UrlPlayable) Playable(net.robinfriedli.aiode.audio.Playable) AlbumSimplified(se.michaelthelin.spotify.model_objects.specification.AlbumSimplified) StringList(net.robinfriedli.stringlist.StringList) List(java.util.List) SpotifyTrack(net.robinfriedli.aiode.audio.spotify.SpotifyTrack) Track(se.michaelthelin.spotify.model_objects.specification.Track) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) NoSpotifyResultsFoundException(net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException)

Example 14 with AudioManager

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;
    }
}
Also used : StringList(net.robinfriedli.stringlist.StringList) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException) PlayableFactory(net.robinfriedli.aiode.audio.PlayableFactory) UrlPlayable(net.robinfriedli.aiode.audio.UrlPlayable) YouTubePlaylist(net.robinfriedli.aiode.audio.youtube.YouTubePlaylist) SpotifyTrack(net.robinfriedli.aiode.audio.spotify.SpotifyTrack) Playable(net.robinfriedli.aiode.audio.Playable) Episode(se.michaelthelin.spotify.model_objects.specification.Episode) Callable(java.util.concurrent.Callable) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) Lists(com.google.common.collect.Lists) Playlist(net.robinfriedli.aiode.entities.Playlist) YouTubeVideo(net.robinfriedli.aiode.audio.youtube.YouTubeVideo) SearchEngine(net.robinfriedli.aiode.util.SearchEngine) Track(se.michaelthelin.spotify.model_objects.specification.Track) CommandContribution(net.robinfriedli.aiode.entities.xml.CommandContribution) SpotifyUri(net.robinfriedli.aiode.audio.spotify.SpotifyUri) UnavailableResourceException(net.robinfriedli.aiode.exceptions.UnavailableResourceException) ArtistSimplified(se.michaelthelin.spotify.model_objects.specification.ArtistSimplified) CommandManager(net.robinfriedli.aiode.command.CommandManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) IOException(java.io.IOException) AudioManager(net.robinfriedli.aiode.audio.AudioManager) NoSpotifyResultsFoundException(net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException) AudioItem(com.sedmelluq.discord.lavaplayer.track.AudioItem) UrlValidator(org.apache.commons.validator.routines.UrlValidator) Aiode(net.robinfriedli.aiode.Aiode) ShowSimplified(se.michaelthelin.spotify.model_objects.specification.ShowSimplified) List(java.util.List) AudioTrackLoader(net.robinfriedli.aiode.audio.AudioTrackLoader) SpotifyTrackResultHandler(net.robinfriedli.aiode.audio.spotify.SpotifyTrackResultHandler) SpotifyService(net.robinfriedli.aiode.audio.spotify.SpotifyService) CommandContext(net.robinfriedli.aiode.command.CommandContext) PlaylistSimplified(se.michaelthelin.spotify.model_objects.specification.PlaylistSimplified) AlbumSimplified(se.michaelthelin.spotify.model_objects.specification.AlbumSimplified) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) TrackLoadingExecutor(net.robinfriedli.aiode.audio.exec.TrackLoadingExecutor) YouTubeService(net.robinfriedli.aiode.audio.youtube.YouTubeService) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException) UrlPlayable(net.robinfriedli.aiode.audio.UrlPlayable) Playable(net.robinfriedli.aiode.audio.Playable) UnavailableResourceException(net.robinfriedli.aiode.exceptions.UnavailableResourceException) YouTubeVideo(net.robinfriedli.aiode.audio.youtube.YouTubeVideo) YouTubeService(net.robinfriedli.aiode.audio.youtube.YouTubeService)

Example 15 with AudioManager

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);
        }
    }
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback)

Aggregations

AudioManager (net.robinfriedli.aiode.audio.AudioManager)15 AudioPlayback (net.robinfriedli.aiode.audio.AudioPlayback)12 Guild (net.dv8tion.jda.api.entities.Guild)9 Playable (net.robinfriedli.aiode.audio.Playable)7 PlayableFactory (net.robinfriedli.aiode.audio.PlayableFactory)7 Aiode (net.robinfriedli.aiode.Aiode)6 CommandContext (net.robinfriedli.aiode.command.CommandContext)6 AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)5 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)5 AudioQueue (net.robinfriedli.aiode.audio.AudioQueue)5 AudioTrackLoader (net.robinfriedli.aiode.audio.AudioTrackLoader)5 Playlist (net.robinfriedli.aiode.entities.Playlist)5 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)5 Lists (com.google.common.collect.Lists)4 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)4 IOException (java.io.IOException)4 List (java.util.List)4 Callable (java.util.concurrent.Callable)4 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)4 UrlPlayable (net.robinfriedli.aiode.audio.UrlPlayable)4