use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project FredBoat by Frederikam.
the class SpotifyPlaylistSourceManager method loadItem.
@Override
public AudioItem loadItem(final DefaultAudioPlayerManager manager, final AudioReference ar) {
String[] data = parse(ar.identifier);
if (data == null)
return null;
final String spotifyUser = data[0];
final String spotifyListId = data[1];
PlaylistInfo plData;
try {
plData = spotifyAPIWrapper.getPlaylistDataBlocking(spotifyUser, spotifyListId);
} catch (Exception e) {
log.warn("Could not retrieve playlist " + spotifyListId + " of user " + spotifyUser, e);
throw new FriendlyException("Couldn't load playlist. Either Spotify is down or the playlist does not exist.", FriendlyException.Severity.COMMON, e);
}
String playlistName = plData.getName();
if (playlistName == null || "".equals(playlistName))
playlistName = "Spotify Playlist";
int tracksTotal = plData.getTotalTracks();
final List<AudioTrack> trackList = new ArrayList<>();
final List<String> trackListSearchTerms;
try {
trackListSearchTerms = spotifyAPIWrapper.getPlaylistTracksSearchTermsBlocking(spotifyUser, spotifyListId);
} catch (Exception e) {
log.warn("Could not retrieve tracks for playlist " + spotifyListId + " of user " + spotifyUser, e);
throw new FriendlyException("Couldn't load playlist. Either Spotify is down or the playlist does not exist.", FriendlyException.Severity.COMMON, e);
}
log.info("Retrieved playlist data for " + playlistName + " from Spotify, loading up " + tracksTotal + " tracks");
// build a task list
List<CompletableFuture<AudioTrack>> taskList = new ArrayList<>();
for (final String s : trackListSearchTerms) {
// remove all punctuation
final String query = s.replaceAll(TrackSearcher.PUNCTUATION_REGEX, "");
CompletableFuture<AudioTrack> f = CompletableFuture.supplyAsync(() -> searchSingleTrack(query), loader);
taskList.add(f);
}
// build a tracklist from that task list
for (CompletableFuture<AudioTrack> futureTrack : taskList) {
try {
final AudioTrack audioItem = futureTrack.get();
if (audioItem == null) {
// skip the track if we couldn't find it
continue;
}
trackList.add(audioItem);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
} catch (ExecutionException ignored) {
// this is fine, loop will go for the next item
}
}
return new BasicAudioPlaylist(playlistName, trackList, null, true);
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project FredBoat by Frederikam.
the class SpotifyPlaylistSourceManager method getPlaylistDataBlocking.
@Override
public PlaylistInfo getPlaylistDataBlocking(String identifier) {
String[] data = parse(identifier);
if (data == null)
return null;
final String spotifyUser = data[0];
final String spotifyListId = data[1];
try {
return spotifyAPIWrapper.getPlaylistDataBlocking(spotifyUser, spotifyListId);
} catch (Exception e) {
log.warn("Could not retrieve playlist " + spotifyListId + " of user " + spotifyUser, e);
throw new FriendlyException("Couldn't load playlist. Either Spotify is down or the playlist does not exist.", FriendlyException.Severity.COMMON, e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project PorkBot by DaMatrix.
the class AudioUtils method loadAndPlay.
public static void loadAndPlay(final TextChannel channel, final String trackUrl, final Member user, final boolean notify) {
GuildAudioInfo musicManager = getGuildAudioPlayer(channel.getGuild(), true, user, channel);
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
if (notify)
channel.sendMessage("Adding to queue: " + track.getInfo().title).queue();
play(channel.getGuild(), musicManager, track, user, channel);
synchronized (trackUrl) {
trackUrl.notifyAll();
}
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
if (tracks == null || tracks.size() == 0) {
channel.sendMessage("Empty or invalid playlist, not loading");
}
if (notify)
channel.sendMessage("Adding " + tracks.size() + " tracks from playlist " + playlist.getName() + " to queue").queue();
playList(channel.getGuild(), musicManager, tracks, user, channel);
synchronized (trackUrl) {
trackUrl.notifyAll();
}
}
@Override
public void noMatches() {
channel.sendMessage("Nothing found by " + trackUrl).queue();
}
@Override
public void loadFailed(FriendlyException exception) {
channel.sendMessage("Could not play: " + exception.getMessage()).queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project BoltBot by DiscordBolt.
the class VoiceManager method getSongTitle.
public String getSongTitle(String songURL) {
Semaphore s = new Semaphore(0);
Info title = new Info();
playerManager.loadItem(songURL, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
title.title = track.getInfo().title;
s.release();
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
s.release();
}
@Override
public void noMatches() {
s.release();
}
@Override
public void loadFailed(FriendlyException exception) {
s.release();
}
});
s.acquireUninterruptibly();
return title.title;
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project Ardent by adamint.
the class TrackScheduler method onException.
private void onException(AudioPlayer player, AudioTrack track, FriendlyException exception) {
manager.setCurrentlyPlaying(null);
manager.nextTrack();
try {
manager.getChannel().sendMessage("I wasn't able to play that track, skipping... **Reason: **" + exception.getLocalizedMessage()).queue();
} catch (Exception ex) {
new BotException(ex);
}
}
Aggregations