Search in sources :

Example 1 with NoSpotifyResultsFoundException

use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException in project aiode by robinfriedli.

the class SearchCommand method searchSpotifyEpisode.

private void searchSpotifyEpisode() throws Exception {
    if (getCommandInput().isBlank()) {
        throw new InvalidCommandException("No search term entered");
    }
    int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
    Callable<List<Episode>> loadTrackCallable = () -> getSpotifyService().searchEpisode(getCommandInput(), argumentSet("own"), limit);
    List<Episode> found;
    if (argumentSet("own")) {
        found = runWithLogin(loadTrackCallable);
    } else {
        found = runWithCredentials(loadTrackCallable);
    }
    if (!found.isEmpty()) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        Util.appendEmbedList(embedBuilder, found, episode -> episode.getName() + " - " + episode.getShow().getName() + " - " + episode.getShow().getPublisher(), "Episode - Show - Publisher");
        sendMessage(embedBuilder);
    } else {
        throw new NoSpotifyResultsFoundException(String.format("No podcast episode found for '%s'", getCommandInput()));
    }
}
Also used : Episode(se.michaelthelin.spotify.model_objects.specification.Episode) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) StringList(net.robinfriedli.stringlist.StringList) List(java.util.List) NoSpotifyResultsFoundException(net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException)

Example 2 with NoSpotifyResultsFoundException

use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException in project aiode by robinfriedli.

the class SearchCommand method searchSpotifyTrack.

private void searchSpotifyTrack() throws Exception {
    if (getCommandInput().isBlank()) {
        throw new InvalidCommandException("No search term entered");
    }
    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.isEmpty()) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        Util.appendEmbedList(embedBuilder, found, track -> track.getName() + " - " + track.getAlbum().getName() + " - " + StringList.create(track.getArtists(), ArtistSimplified::getName).toSeparatedString(", "), "Track - Album - Artist");
        sendMessage(embedBuilder);
    } else {
        throw new NoSpotifyResultsFoundException(String.format("No Spotify track found for '%s'", getCommandInput()));
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) StringList(net.robinfriedli.stringlist.StringList) List(java.util.List) SpotifyTrack(net.robinfriedli.aiode.audio.spotify.SpotifyTrack) Track(se.michaelthelin.spotify.model_objects.specification.Track) NoSpotifyResultsFoundException(net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException)

Example 3 with NoSpotifyResultsFoundException

use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException 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)

Example 4 with NoSpotifyResultsFoundException

use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException in project aiode by robinfriedli.

the class AbstractPlayableLoadingCommand method loadSpotifyShow.

private void loadSpotifyShow(AudioManager audioManager) throws Exception {
    int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
    Callable<List<ShowSimplified>> albumLoadCallable = () -> getSpotifyService().searchShow(getCommandInput(), argumentSet("own"), limit);
    List<ShowSimplified> shows;
    if (argumentSet("own")) {
        shows = runWithLogin(albumLoadCallable);
    } else {
        shows = runWithCredentials(albumLoadCallable);
    }
    if (shows.size() == 1) {
        ShowSimplified show = shows.get(0);
        List<Episode> episodes = runWithCredentials(() -> getSpotifyService().getShowEpisodes(show.getId()));
        PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), trackLoadingExecutor);
        List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), episodes);
        handleResults(playables);
        loadedShow = show;
    } else if (shows.isEmpty()) {
        throw new NoSpotifyResultsFoundException(String.format("No shows found for '%s'", getCommandInput()));
    } else {
        askQuestion(shows, ShowSimplified::getName, ShowSimplified::getPublisher);
    }
}
Also used : Episode(se.michaelthelin.spotify.model_objects.specification.Episode) PlayableFactory(net.robinfriedli.aiode.audio.PlayableFactory) ShowSimplified(se.michaelthelin.spotify.model_objects.specification.ShowSimplified) UrlPlayable(net.robinfriedli.aiode.audio.UrlPlayable) Playable(net.robinfriedli.aiode.audio.Playable) StringList(net.robinfriedli.stringlist.StringList) List(java.util.List) NoSpotifyResultsFoundException(net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException)

Example 5 with NoSpotifyResultsFoundException

use of net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException in project aiode by robinfriedli.

the class AbstractPlayableLoadingCommand method loadSpotifyEpisode.

private void loadSpotifyEpisode(AudioManager audioManager) throws Exception {
    int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
    Callable<List<Episode>> loadTrackCallable = () -> getSpotifyService().searchEpisode(getCommandInput(), argumentSet("own"), limit);
    List<Episode> found;
    if (argumentSet("own")) {
        found = runWithLogin(loadTrackCallable);
    } else {
        found = runWithCredentials(loadTrackCallable);
    }
    if (found.size() == 1) {
        createPlayableForEpisode(found.get(0), audioManager);
    } else if (found.isEmpty()) {
        throw new NoSpotifyResultsFoundException(String.format("No Spotify episode found for '%s'", getCommandInput()));
    } else {
        askQuestion(found, episode -> String.format("%s by %s", episode.getName(), episode.getShow().getName()));
    }
}
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) Episode(se.michaelthelin.spotify.model_objects.specification.Episode) StringList(net.robinfriedli.stringlist.StringList) List(java.util.List) NoSpotifyResultsFoundException(net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException)

Aggregations

List (java.util.List)9 NoSpotifyResultsFoundException (net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException)9 StringList (net.robinfriedli.stringlist.StringList)9 SpotifyTrack (net.robinfriedli.aiode.audio.spotify.SpotifyTrack)7 Episode (se.michaelthelin.spotify.model_objects.specification.Episode)7 ShowSimplified (se.michaelthelin.spotify.model_objects.specification.ShowSimplified)7 Track (se.michaelthelin.spotify.model_objects.specification.Track)6 IOException (java.io.IOException)5 Callable (java.util.concurrent.Callable)5 Aiode (net.robinfriedli.aiode.Aiode)5 YouTubePlaylist (net.robinfriedli.aiode.audio.youtube.YouTubePlaylist)5 YouTubeService (net.robinfriedli.aiode.audio.youtube.YouTubeService)5 YouTubeVideo (net.robinfriedli.aiode.audio.youtube.YouTubeVideo)5 CommandContext (net.robinfriedli.aiode.command.CommandContext)5 CommandManager (net.robinfriedli.aiode.command.CommandManager)5 Playlist (net.robinfriedli.aiode.entities.Playlist)5 CommandContribution (net.robinfriedli.aiode.entities.xml.CommandContribution)5 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)5 UnavailableResourceException (net.robinfriedli.aiode.exceptions.UnavailableResourceException)5 SearchEngine (net.robinfriedli.aiode.util.SearchEngine)5