Search in sources :

Example 11 with SpotifyWebApiException

use of se.michaelthelin.spotify.exceptions.SpotifyWebApiException in project spotify-web-api-java by spotify-web-api-java.

the class GetListOfFeaturedPlaylistsExample method getListOfFeaturedPlaylists_Sync.

public static void getListOfFeaturedPlaylists_Sync() {
    try {
        final FeaturedPlaylists featuredPlaylists = getListOfFeaturedPlaylistsRequest.execute();
        System.out.println("Message: " + featuredPlaylists.getMessage());
    } catch (IOException | SpotifyWebApiException | ParseException e) {
        System.out.println("Error: " + e.getMessage());
    }
}
Also used : FeaturedPlaylists(se.michaelthelin.spotify.model_objects.special.FeaturedPlaylists) IOException(java.io.IOException) ParseException(org.apache.hc.core5.http.ParseException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException)

Example 12 with SpotifyWebApiException

use of se.michaelthelin.spotify.exceptions.SpotifyWebApiException in project spotify-web-api-java by spotify-web-api-java.

the class GetRecommendationsExample method getRecommendations_Sync.

public static void getRecommendations_Sync() {
    try {
        final Recommendations recommendations = getRecommendationsRequest.execute();
        System.out.println("Length: " + recommendations.getTracks().length);
    } catch (IOException | SpotifyWebApiException | ParseException e) {
        System.out.println("Error: " + e.getMessage());
    }
}
Also used : Recommendations(se.michaelthelin.spotify.model_objects.specification.Recommendations) IOException(java.io.IOException) ParseException(org.apache.hc.core5.http.ParseException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException)

Example 13 with SpotifyWebApiException

use of se.michaelthelin.spotify.exceptions.SpotifyWebApiException 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 14 with SpotifyWebApiException

use of se.michaelthelin.spotify.exceptions.SpotifyWebApiException in project lobster by lundylizard.

the class PlayCommand method action.

@Override
public void action(String[] args, @NotNull MessageReceivedEvent event) {
    var link = new StringBuilder();
    var channel = event.getTextChannel();
    var self = Objects.requireNonNull(event.getMember()).getGuild().getSelfMember();
    var selfVoiceState = self.getVoiceState();
    var member = event.getMember();
    var memberVoiceState = member.getVoiceState();
    var spotify = new SpotifyToYoutubeInterpreter();
    var top = false;
    assert memberVoiceState != null;
    if (!memberVoiceState.inVoiceChannel()) {
        channel.sendMessage(":warning: You are not in a voice channel.").queue();
        return;
    }
    assert selfVoiceState != null;
    if (!selfVoiceState.inVoiceChannel()) {
        var audioManager = event.getGuild().getAudioManager();
        var memberChannel = Objects.requireNonNull(event.getMember().getVoiceState()).getChannel();
        audioManager.openAudioConnection(memberChannel);
        assert memberChannel != null;
        event.getChannel().sendMessage(":loud_sound: Connecting to voice channel `\uD83D\uDD0A " + memberChannel.getName() + "`").queue();
    }
    if (args[0].equalsIgnoreCase("top")) {
        top = true;
    }
    for (var i = top ? 1 : 0; i < args.length; i++) {
        link.append(args[i]).append(" ");
    }
    if (!isUrl(link.toString())) {
        link.insert(0, "ytsearch:");
    }
    if (!event.getMessage().getAttachments().isEmpty()) {
        link.delete(0, link.length());
        link.append(event.getMessage().getAttachments().get(0).getUrl());
    }
    if (link.isEmpty()) {
        channel.sendMessage(":warning: Please provide a file or an URL.").queue();
        return;
    }
    // Spotify doesn't allow direct playback from their API, so it's getting the data from the song and searches it on YouTube
    if (spotify.isSpotifyLink(link.toString())) {
        if (Lobsterbot.DEBUG)
            System.out.println(spotify.isSpotifyPlaylist(link.toString()));
        if (Lobsterbot.DEBUG)
            System.out.println(link.toString().replace("\\?si=.*$", "").replace("https://open.spotify.com/", ""));
        if (!spotify.isSpotifyPlaylist(link.toString())) {
            var spotifyId = spotify.getSpotifyIdFromLink(link.toString());
            link.delete(0, link.length());
            try {
                link.append("ytsearch:").append(spotify.getArtistFromSpotify(spotifyId)).append(" ").append(spotify.getSongNameFromSpotify(spotifyId));
            } catch (IOException | ParseException | SpotifyWebApiException e) {
                e.printStackTrace();
            }
        } else {
            channel.sendMessage("Spotify Playlists may be a little buggy, gonna fix that sooner or later.").queue();
            var spotifyId = spotify.getSpotifyIdFromLink(link.toString());
            Playlist playlist = null;
            try {
                playlist = spotify.getSpotifyPlaylist(spotifyId);
            } catch (IOException | ParseException | SpotifyWebApiException e) {
                e.printStackTrace();
            }
            assert playlist != null;
            for (PlaylistTrack playlistTrack : playlist.getTracks().getItems()) {
                try {
                    if (playlistTrack.getTrack().getId() != null) {
                        PlayerManager.getInstance().loadAndPlay(event, ("ytsearch:" + spotify.getArtistFromSpotify(playlistTrack.getTrack().getId()) + " " + spotify.getSongNameFromSpotify(playlistTrack.getTrack().getId())).trim(), top, true);
                    }
                } catch (IOException | SpotifyWebApiException | ParseException e) {
                    e.printStackTrace();
                }
            }
            event.getChannel().sendMessage(":arrow_forward: Added " + playlist.getTracks().getTotal() + " songs to the queue.").queue();
        }
    }
    PlayerManager.getInstance().loadAndPlay(event, link.toString().trim(), top, false);
}
Also used : Playlist(se.michaelthelin.spotify.model_objects.specification.Playlist) SpotifyToYoutubeInterpreter(de.lundy.lobster.lavaplayer.spotify.SpotifyToYoutubeInterpreter) PlaylistTrack(se.michaelthelin.spotify.model_objects.specification.PlaylistTrack) IOException(java.io.IOException) ParseException(org.apache.hc.core5.http.ParseException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException)

Example 15 with SpotifyWebApiException

use of se.michaelthelin.spotify.exceptions.SpotifyWebApiException in project spotify-web-api-java by spotify-web-api-java.

the class GetAudioFeaturesForTrackExample method getAudioFeaturesForTrack_Sync.

public static void getAudioFeaturesForTrack_Sync() {
    try {
        final AudioFeatures audioFeatures = getAudioFeaturesForTrackRequest.execute();
        System.out.println("ID: " + audioFeatures.getId());
    } catch (IOException | SpotifyWebApiException | ParseException e) {
        System.out.println("Error: " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) ParseException(org.apache.hc.core5.http.ParseException) AudioFeatures(se.michaelthelin.spotify.model_objects.specification.AudioFeatures) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException)

Aggregations

IOException (java.io.IOException)27 ParseException (org.apache.hc.core5.http.ParseException)27 SpotifyWebApiException (se.michaelthelin.spotify.exceptions.SpotifyWebApiException)27 AuthorizationCodeCredentials (se.michaelthelin.spotify.model_objects.credentials.AuthorizationCodeCredentials)5 SnapshotResult (se.michaelthelin.spotify.model_objects.special.SnapshotResult)3 Playlist (se.michaelthelin.spotify.model_objects.specification.Playlist)3 User (se.michaelthelin.spotify.model_objects.specification.User)2 SpotifyToYoutubeInterpreter (de.lundy.lobster.lavaplayer.spotify.SpotifyToYoutubeInterpreter)1 BotInstanceManagementService (de.notecho.spotify.bot.BotInstanceManagementService)1 BaseModule (de.notecho.spotify.bot.modules.BaseModule)1 TokenPair (de.notecho.spotify.database.user.entities.TokenPair)1 UserRepository (de.notecho.spotify.database.user.repository.UserRepository)1 BadRequestException (se.michaelthelin.spotify.exceptions.detailed.BadRequestException)1 ClientCredentials (se.michaelthelin.spotify.model_objects.credentials.ClientCredentials)1 AudioAnalysis (se.michaelthelin.spotify.model_objects.miscellaneous.AudioAnalysis)1 CurrentlyPlaying (se.michaelthelin.spotify.model_objects.miscellaneous.CurrentlyPlaying)1 CurrentlyPlayingContext (se.michaelthelin.spotify.model_objects.miscellaneous.CurrentlyPlayingContext)1 FeaturedPlaylists (se.michaelthelin.spotify.model_objects.special.FeaturedPlaylists)1 SearchResult (se.michaelthelin.spotify.model_objects.special.SearchResult)1 Album (se.michaelthelin.spotify.model_objects.specification.Album)1