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());
}
}
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());
}
}
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());
}
}
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);
}
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());
}
}
Aggregations