use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class YoutubeMixProvider method loadTracksAsynchronously.
private AudioPlaylist loadTracksAsynchronously(List<String> videoIds, String selectedVideoId) {
ExecutorCompletionService<AudioItem> completion = new ExecutorCompletionService<>(mixLoadingExecutor);
List<AudioTrack> tracks = new ArrayList<>();
for (final String videoId : videoIds) {
completion.submit(() -> sourceManager.loadTrackWithVideoId(videoId, true));
}
try {
fetchTrackResultsFromExecutor(completion, tracks, videoIds.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
AudioTrack selectedTrack = sourceManager.findSelectedTrack(tracks, selectedVideoId);
if (tracks.isEmpty()) {
throw new FriendlyException("No tracks from the mix loaded succesfully.", SUSPICIOUS, null);
} else if (selectedTrack == null) {
throw new FriendlyException("The selected track of the mix failed to load.", SUSPICIOUS, null);
}
return new BasicAudioPlaylist("YouTube mix", tracks, selectedTrack, false);
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project FlareBot by FlareBot.
the class RandomExtractor method process.
@Override
public void process(String input, Player player, Message message, User user) throws Exception {
int i = 0;
for (String s : input.split(",")) {
try {
AudioItem probablyATrack = player.resolve(s);
if (probablyATrack == null)
continue;
Track track = new Track((AudioTrack) probablyATrack);
track.getMeta().put("requester", user.getId());
track.getMeta().put("guildId", player.getGuildId());
player.queue(track);
i++;
} catch (FriendlyException ignored) {
}
}
MessageUtils.editMessage(null, MessageUtils.getEmbed().setDescription("Added " + i + " random songs to the playlist!"), message);
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project FlareBot by FlareBot.
the class SavedPlaylistExtractor method process.
@Override
public void process(String input, Player player, Message message, User user) throws Exception {
input = input.substring(input.indexOf('\u200B') + 1).replaceAll("\\[? ?]?", "");
int i = 0;
ArrayList<Track> playlist = new ArrayList<>();
for (String s : input.split(",")) {
String url = YouTubeExtractor.WATCH_URL + s;
Document doc;
try {
doc = Jsoup.connect(url).get();
} catch (Exception e) {
continue;
}
if (!doc.title().endsWith("YouTube") || doc.title().equals("YouTube")) {
continue;
}
try {
Track track = new Track((AudioTrack) player.resolve(url));
track.getMeta().put("requester", user.getId());
track.getMeta().put("guildId", player.getGuildId());
playlist.add(track);
if (playlist.size() == 10) {
player.queue(new Playlist(playlist));
playlist.clear();
}
i++;
} catch (FriendlyException ignored) {
}
}
if (!playlist.isEmpty()) {
player.queue(new Playlist(playlist));
}
MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription(String.format("*Loaded %s songs!*", i)), message);
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project Ardent by adamint.
the class Music method loadAndPlay.
static void loadAndPlay(Message message, User user, Command command, final TextChannel channel, String trackUrl, final VoiceChannel voiceChannel, boolean search, boolean useEmbedSelect) {
if (trackUrl.contains("spotify.com")) {
String[] parsed = trackUrl.split("/track/");
if (parsed.length == 2) {
final TrackRequest request = spotifyApi.getTrack(parsed[1]).build();
try {
trackUrl = request.get().getName();
} catch (Exception e) {
new BotException(e);
}
}
}
Guild guild = channel.getGuild();
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild(), channel);
String finalTrackUrl = trackUrl;
GuildUtils.getShard(guild).playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
if (!UserUtils.hasTierTwoPermissions(user) && !EntityGuild.get(guild).isPremium()) {
try {
if (!shouldContinue(user, guild, channel, track)) {
return;
}
} catch (Exception e) {
new BotException(e);
}
}
try {
command.sendTranslatedMessage("Adding {0} to the queue".replace("{0}", track.getInfo().title) + " " + getDuration(track), channel, user);
} catch (Exception e) {
new BotException(e);
}
play(user, guild, voiceChannel, musicManager, track, channel);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
if (playlist.isSearchResult()) {
try {
if (!useEmbedSelect) {
AudioTrack[] possible;
if (playlist.getTracks().size() >= 5)
possible = playlist.getTracks().subList(0, 5).toArray(new AudioTrack[5]);
else
possible = playlist.getTracks().toArray(new AudioTrack[playlist.getTracks().size()]);
ArrayList<String> names = new ArrayList<>();
for (AudioTrack audioTrack : possible) {
names.add(audioTrack.getInfo().title);
}
Message embed = command.sendEmbed(command.chooseFromList("Choose Song", guild, user, command, names.toArray(new String[5])), channel, user);
interactiveOperation(channel, message, selectionMessage -> {
try {
AudioTrack selected = possible[Integer.parseInt(selectionMessage.getContent()) - 1];
if (!UserUtils.hasTierTwoPermissions(user) && !EntityGuild.get(guild).isPremium()) {
try {
if (!shouldContinue(user, guild, channel, selected)) {
return;
}
} catch (Exception e) {
new BotException(e);
}
}
try {
embed.delete().queue();
selectionMessage.delete().queue();
} catch (Exception ignored) {
}
play(user, guild, voiceChannel, musicManager, selected, channel);
command.sendTranslatedMessage("Adding {0} to the queue".replace("{0}", selected.getInfo().title) + " " + getDuration(selected), channel, user);
} catch (Exception e) {
command.sendTranslatedMessage("Invalid response", channel, user);
}
});
} else {
AudioTrack track = playlist.getTracks().get(0);
play(user, guild, voiceChannel, musicManager, track, channel);
command.sendTranslatedMessage("Adding {0} to the queue".replace("{0}", track.getInfo().title) + " " + getDuration(track), channel, user);
}
} catch (Exception e) {
new BotException(e);
}
} else {
if (!UserUtils.hasTierTwoPermissions(user) && !EntityGuild.get(guild).isPremium()) {
try {
if (!shouldContinue(user, guild, channel, 1)) {
return;
}
} catch (Exception e) {
new BotException(e);
}
}
try {
command.sendTranslatedMessage("Adding {0} songs to the queue".replace("{0}", String.valueOf(tracks.size())), channel, user);
} catch (Exception e) {
new BotException(e);
}
for (AudioTrack track : tracks) {
play(user, guild, voiceChannel, musicManager, track, channel);
}
}
}
@Override
public void noMatches() {
if (!search) {
loadAndPlay(message, user, command, channel, "ytsearch: " + finalTrackUrl, voiceChannel, true, useEmbedSelect);
} else {
try {
command.sendTranslatedMessage("I couldn't find a song with that name", channel, user);
} catch (Exception e) {
new BotException(e);
}
}
}
@Override
public void loadFailed(FriendlyException exception) {
try {
sendTo(channel, guild).sendMessage("I wasn't able to play that track... **Reason: **" + exception.getLocalizedMessage()).queue();
} catch (Exception e) {
new BotException(e);
}
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project Ardent by adamint.
the class TrackScheduler method onTrackStuck.
@Override
public void onTrackStuck(AudioPlayer player, AudioTrack track, long thresholdMs) {
manager.nextTrack();
onException(player, track, new FriendlyException("Track got stuck", FriendlyException.Severity.COMMON, new Exception()));
}
Aggregations