Search in sources :

Example 1 with SpotifyTrackResultHandler

use of net.robinfriedli.aiode.audio.spotify.SpotifyTrackResultHandler 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);
        }
    }
}
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) SpotifyTrackResultHandler(net.robinfriedli.aiode.audio.spotify.SpotifyTrackResultHandler) ArtistSimplified(se.michaelthelin.spotify.model_objects.specification.ArtistSimplified) 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