Search in sources :

Example 1 with Episode

use of se.michaelthelin.spotify.model_objects.specification.Episode in project spotify-web-api-java by spotify-web-api-java.

the class GetEpisodeExample method getEpisode_Sync.

public static void getEpisode_Sync() {
    try {
        final Episode episode = getEpisodeRequest.execute();
        System.out.println("Name: " + episode.getName());
    } catch (IOException | SpotifyWebApiException | ParseException e) {
        System.out.println("Error: " + e.getMessage());
    }
}
Also used : Episode(se.michaelthelin.spotify.model_objects.specification.Episode) IOException(java.io.IOException) ParseException(org.apache.hc.core5.http.ParseException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException)

Example 2 with Episode

use of se.michaelthelin.spotify.model_objects.specification.Episode 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 3 with Episode

use of se.michaelthelin.spotify.model_objects.specification.Episode 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 4 with Episode

use of se.michaelthelin.spotify.model_objects.specification.Episode 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)

Example 5 with Episode

use of se.michaelthelin.spotify.model_objects.specification.Episode in project aiode by robinfriedli.

the class QueueCommand method getPlayablesForOption.

private List<Playable> getPlayablesForOption(Object chosenOption, PlayableFactory playableFactory) throws Exception {
    if (chosenOption instanceof Track || chosenOption instanceof YouTubeVideo || chosenOption instanceof Episode) {
        Playable track = playableFactory.createPlayable(shouldRedirectSpotify(), chosenOption);
        loadedTrack = track;
        return Collections.singletonList(track);
    } else if (chosenOption instanceof PlaylistSimplified) {
        PlaylistSimplified playlist = (PlaylistSimplified) chosenOption;
        List<SpotifyTrack> tracks = runWithCredentials(() -> getSpotifyService().getPlaylistTracks(playlist));
        List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), tracks);
        loadedSpotifyPlaylist = playlist;
        return playables;
    } else if (chosenOption instanceof YouTubePlaylist) {
        YouTubePlaylist youTubePlaylist = (YouTubePlaylist) chosenOption;
        List<Playable> playables = playableFactory.createPlayables(youTubePlaylist);
        loadedYouTubePlaylist = youTubePlaylist;
        return playables;
    } else if (chosenOption instanceof AlbumSimplified) {
        AlbumSimplified album = (AlbumSimplified) chosenOption;
        List<Track> tracks = runWithCredentials(() -> getSpotifyService().getAlbumTracks(album.getId()));
        List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), tracks);
        loadedAlbum = album;
        return playables;
    } else if (chosenOption instanceof AudioTrack) {
        Playable playable = playableFactory.createPlayable(shouldRedirectSpotify(), chosenOption);
        loadedAudioTrack = (AudioTrack) chosenOption;
        return Collections.singletonList(playable);
    } else if (chosenOption instanceof AudioPlaylist) {
        List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), chosenOption);
        loadedAudioPlaylist = (AudioPlaylist) chosenOption;
        return playables;
    } else if (chosenOption instanceof ShowSimplified) {
        ShowSimplified show = (ShowSimplified) chosenOption;
        List<Episode> episodes = runWithCredentials(() -> getSpotifyService().getShowEpisodes(show.getId()));
        List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), episodes);
        loadedShow = show;
        return playables;
    }
    throw new UnsupportedOperationException("Unsupported chosen option type: " + chosenOption.getClass());
}
Also used : ShowSimplified(se.michaelthelin.spotify.model_objects.specification.ShowSimplified) Episode(se.michaelthelin.spotify.model_objects.specification.Episode) Playable(net.robinfriedli.aiode.audio.Playable) YouTubePlaylist(net.robinfriedli.aiode.audio.youtube.YouTubePlaylist) AlbumSimplified(se.michaelthelin.spotify.model_objects.specification.AlbumSimplified) List(java.util.List) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) YouTubeVideo(net.robinfriedli.aiode.audio.youtube.YouTubeVideo) SpotifyTrack(net.robinfriedli.aiode.audio.spotify.SpotifyTrack) Track(se.michaelthelin.spotify.model_objects.specification.Track) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) PlaylistSimplified(se.michaelthelin.spotify.model_objects.specification.PlaylistSimplified) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

Aggregations

Episode (se.michaelthelin.spotify.model_objects.specification.Episode)11 List (java.util.List)8 IOException (java.io.IOException)7 StringList (net.robinfriedli.stringlist.StringList)7 Track (se.michaelthelin.spotify.model_objects.specification.Track)7 SpotifyTrack (net.robinfriedli.aiode.audio.spotify.SpotifyTrack)6 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)5 YouTubePlaylist (net.robinfriedli.aiode.audio.youtube.YouTubePlaylist)5 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)5 AlbumSimplified (se.michaelthelin.spotify.model_objects.specification.AlbumSimplified)5 PlaylistSimplified (se.michaelthelin.spotify.model_objects.specification.PlaylistSimplified)5 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)4 YouTubeVideo (net.robinfriedli.aiode.audio.youtube.YouTubeVideo)4 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)4 NoSpotifyResultsFoundException (net.robinfriedli.aiode.exceptions.NoSpotifyResultsFoundException)4 ParseException (org.apache.hc.core5.http.ParseException)4 SpotifyWebApiException (se.michaelthelin.spotify.exceptions.SpotifyWebApiException)4 ShowSimplified (se.michaelthelin.spotify.model_objects.specification.ShowSimplified)4 Lists (com.google.common.collect.Lists)3 AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)3