Search in sources :

Example 1 with TrackLoadingExecutor

use of net.robinfriedli.aiode.audio.exec.TrackLoadingExecutor 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)

Aggregations

Lists (com.google.common.collect.Lists)1 AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)1 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 IOException (java.io.IOException)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 Aiode (net.robinfriedli.aiode.Aiode)1 AudioManager (net.robinfriedli.aiode.audio.AudioManager)1 AudioPlayback (net.robinfriedli.aiode.audio.AudioPlayback)1 AudioTrackLoader (net.robinfriedli.aiode.audio.AudioTrackLoader)1 Playable (net.robinfriedli.aiode.audio.Playable)1 PlayableFactory (net.robinfriedli.aiode.audio.PlayableFactory)1 UrlPlayable (net.robinfriedli.aiode.audio.UrlPlayable)1 TrackLoadingExecutor (net.robinfriedli.aiode.audio.exec.TrackLoadingExecutor)1 SpotifyService (net.robinfriedli.aiode.audio.spotify.SpotifyService)1 SpotifyTrack (net.robinfriedli.aiode.audio.spotify.SpotifyTrack)1 SpotifyTrackResultHandler (net.robinfriedli.aiode.audio.spotify.SpotifyTrackResultHandler)1 SpotifyUri (net.robinfriedli.aiode.audio.spotify.SpotifyUri)1 YouTubePlaylist (net.robinfriedli.aiode.audio.youtube.YouTubePlaylist)1