use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class MusicController method addTrack.
private void addTrack(final Message message, final String identifier, final boolean now) {
outputChannel.set((TextChannel) message.getChannel());
manager.loadItemOrdered(this, identifier, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
connectToFirstVoiceChannel(guild.getAudioManager());
message.getChannel().sendMessage("Starting now: " + track.getInfo().title + " (length " + track.getDuration() + ")").queue();
if (now) {
scheduler.playNow(track, true);
} else {
scheduler.addToQueue(track);
}
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
message.getChannel().sendMessage("Loaded playlist: " + playlist.getName() + " (" + tracks.size() + ")").queue();
connectToFirstVoiceChannel(guild.getAudioManager());
AudioTrack selected = playlist.getSelectedTrack();
if (selected != null) {
message.getChannel().sendMessage("Selected track from playlist: " + selected.getInfo().title).queue();
} else {
selected = tracks.get(0);
message.getChannel().sendMessage("Added first track from playlist: " + selected.getInfo().title).queue();
}
if (now) {
scheduler.playNow(selected, true);
} else {
scheduler.addToQueue(selected);
}
for (int i = 0; i < Math.min(10, playlist.getTracks().size()); i++) {
if (tracks.get(i) != selected) {
scheduler.addToQueue(tracks.get(i));
}
}
}
@Override
public void noMatches() {
message.getChannel().sendMessage("Nothing found for " + identifier).queue();
}
@Override
public void loadFailed(FriendlyException throwable) {
message.getChannel().sendMessage("Failed with message: " + throwable.getMessage() + " (" + throwable.getClass().getSimpleName() + ")").queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project Rubicon by Rubicon-Bot.
the class MusicManager method loadSong.
public void loadSong(boolean force) {
TextChannel textChannel = parsedCommandInvocation.getMessage().getTextChannel();
boolean isURL = false;
StringBuilder searchParam = new StringBuilder();
for (int i = 0; i < args.length; i++) searchParam.append(args[i]);
if (searchParam.toString().startsWith("http://") || searchParam.toString().startsWith("https://"))
isURL = true;
if (!isURL)
searchParam.insert(0, "ytsearch: ");
final EmbedBuilder embedBuilder = new EmbedBuilder();
final boolean isURLFinal = isURL;
playerManager.loadItemOrdered(getCurrentMusicManager(), searchParam.toString(), new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack audioTrack) {
String trackName = audioTrack.getInfo().title;
String trackAuthor = audioTrack.getInfo().author;
String trackURL = audioTrack.getInfo().uri;
boolean isStream = audioTrack.getInfo().isStream;
long trackDuration = audioTrack.getDuration();
if (!force) {
getCurrentMusicManager().getScheduler().queue(audioTrack);
embedBuilder.setAuthor("Added a new song to queue", trackURL, null);
embedBuilder.addField("Title", trackName, true);
embedBuilder.addField("Author", trackAuthor, true);
embedBuilder.addField("Duration", (isStream) ? "Stream" : getTimestamp(trackDuration), false);
embedBuilder.setColor(Colors.COLOR_PRIMARY);
textChannel.sendMessage(embedBuilder.build()).queue();
}
}
@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
AudioTrack firstTrack = audioPlaylist.getSelectedTrack();
List<AudioTrack> playlistTracks = audioPlaylist.getTracks();
playlistTracks = playlistTracks.stream().limit(QUEUE_MAXIMUM - getCurrentMusicManager().getScheduler().getQueue().size()).collect(Collectors.toList());
if (firstTrack == null)
firstTrack = playlistTracks.get(0);
if (force) {
getCurrentMusicManager().getPlayer().playTrack(firstTrack);
return;
}
if (isURLFinal) {
playlistTracks.forEach(getCurrentMusicManager().getScheduler()::queue);
embedBuilder.setTitle("Added playlist to queue");
embedBuilder.setDescription("Added `" + playlistTracks.size() + "` songs from `" + audioPlaylist.getName() + "` to queue.\n" + "\n" + "**Now playing** `" + firstTrack.getInfo().title + "`");
embedBuilder.addField("Author", firstTrack.getInfo().author, true);
embedBuilder.addField("Duration", (firstTrack.getInfo().isStream) ? "Stream" : getTimestamp(firstTrack.getDuration()), false);
textChannel.sendMessage(embedBuilder.build()).queue();
embedBuilder.setColor(Colors.COLOR_PRIMARY);
textChannel.sendMessage(embedBuilder.build()).queue();
} else {
MusicSearchResult musicSearchResult = new MusicSearchResult(parsedCommandInvocation.getAuthor(), guild, getCurrentMusicManager());
audioPlaylist.getTracks().stream().limit(5).collect(Collectors.toList()).forEach(track -> {
try {
musicSearchResult.addTrack(track);
} catch (Exception e) {
e.printStackTrace();
}
});
musicSearchResult.setMessage(textChannel.sendMessage(musicSearchResult.generateEmbed().build()).complete());
musicChoose.add(musicSearchResult);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
if (musicChoose.contains(musicSearchResult)) {
musicSearchResult.getMessage().delete().queue();
musicChoose.remove(musicSearchResult);
}
}
}, 15000);
}
}
@Override
public void noMatches() {
embedBuilder.setTitle("No matches!");
embedBuilder.setDescription("There are no matches.");
embedBuilder.setColor(Colors.COLOR_NOT_IMPLEMENTED);
textChannel.sendMessage(embedBuilder.build()).queue();
}
@Override
public void loadFailed(FriendlyException e) {
embedBuilder.setTitle(":warning: Error!");
embedBuilder.setDescription("Could not play this song: " + e.getMessage());
embedBuilder.setColor(Colors.COLOR_ERROR);
textChannel.sendMessage(embedBuilder.build()).queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project c0debaseBot by Biospheere.
the class MusicManager method loadTrack.
public void loadTrack(TextChannel channel, User requester, String trackUrl) {
Guild guild = channel.getGuild();
loadTrack(guild, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
queue(guild, track);
EmbedBuilder eb = getEmbed(guild, requester).setAuthor("Track geladen", trackUrl.startsWith("http") ? trackUrl : null, bot.getJda().getSelfUser().getEffectiveAvatarUrl());
AudioTrackInfo trackInfo = track.getInfo();
String length;
if (TimeUnit.MILLISECONDS.toHours(trackInfo.length) >= 24) {
length = String.format("%dd %02d:%02d:%02d", TimeUnit.MILLISECONDS.toDays(trackInfo.length), TimeUnit.MILLISECONDS.toHours(trackInfo.length) % 24, TimeUnit.MILLISECONDS.toMinutes(trackInfo.length) % 60, TimeUnit.MILLISECONDS.toSeconds(trackInfo.length) % 60);
} else {
length = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(trackInfo.length) % 24, TimeUnit.MILLISECONDS.toMinutes(trackInfo.length) % 60, TimeUnit.MILLISECONDS.toSeconds(trackInfo.length) % 60);
}
eb.addField(trackInfo.title, "`" + trackInfo.author + " - " + (trackInfo.isStream ? "STREAM" : length) + "`", false);
channel.sendMessage(eb.build()).queue();
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
if (playlist.isSearchResult()) {
trackLoaded(tracks.get(0));
return;
}
EmbedBuilder eb = getEmbed(guild, requester).setAuthor("Playlist geladen", playlist.isSearchResult() ? null : trackUrl, bot.getJda().getSelfUser().getEffectiveAvatarUrl());
eb.addField(playlist.getName(), "`" + tracks.size() + " Videos gefunden`", false);
channel.sendMessage(eb.build()).queue();
queue(guild, tracks);
nextTrack(guild, false);
}
@Override
public void noMatches() {
channel.sendMessage(getEmbed(guild, requester).setAuthor("Nichts gefunden", null, bot.getJda().getSelfUser().getEffectiveAvatarUrl()).addField("Keine Übereinstimmung", "`" + trackUrl + "`", false).build()).queue();
}
@Override
public void loadFailed(FriendlyException exception) {
channel.sendMessage(getEmbed(guild, requester).setAuthor("Fehler aufgetreten", null, bot.getJda().getSelfUser().getEffectiveAvatarUrl()).addField("Fehlermeldung", "`" + exception.getMessage() + "`", false).build()).queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project BoltBot by DiscordBolt.
the class VoiceManager method queue.
public void queue(IGuild guild, IUser requester, String songID) throws CommandPermissionException, CommandRuntimeException, CommandStateException {
if (songID.toLowerCase().contains("twitch.tv") && !MusicModule.hasAdminPermissions(requester, guild))
throw new CommandPermissionException("You must be a \"" + MusicModule.ADMIN_ROLE + "\" to add Twitch.tv live streams!");
if (requester.getVoiceStateForGuild(guild).getChannel() == null)
throw new CommandStateException("You must be connected to a voice channel to execute this command!");
if (getDJ(guild).getVoiceChannel() != null && !requester.getVoiceStateForGuild(guild).getChannel().equals(getDJ(guild).getVoiceChannel()))
throw new CommandStateException("You must be in my voice channel to control the music!");
DJ dj = getDJ(guild);
if ((dj.getPlaying() != null && songID.contains(dj.getPlaying().getIdentifier())) || dj.getQueue().stream().anyMatch(t -> songID.contains(t.getIdentifier()))) {
throw new CommandStateException("That song is already in the queue!");
}
playerManager.loadItemOrdered(dj, songID, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
dj.queue(requester, track);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
for (AudioTrack track : playlist.getTracks()) {
dj.queue(requester, track);
}
}
@Override
public void noMatches() {
throw new CommandRuntimeException("Sorry, I was unable to find the song you specified.");
}
@Override
public void loadFailed(FriendlyException exception) {
if (exception.severity == FriendlyException.Severity.COMMON)
throw new CommandRuntimeException(exception.getMessage());
throw new CommandRuntimeException("Sorry, an error occurred while loading your song. Please try again later.");
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project FredBoat by Frederikam.
the class HttpSourceManager method detectContainerWithClient.
private MediaContainerDetectionResult detectContainerWithClient(HttpInterface httpInterface, AudioReference reference, boolean ignoreHtml) throws IOException {
try (PersistentHttpStream inputStream = new PersistentHttpStream(httpInterface, new URI(reference.identifier), Long.MAX_VALUE)) {
int statusCode = inputStream.checkStatusCode();
String redirectUrl = HttpClientTools.getRedirectLocation(reference.identifier, inputStream.getCurrentResponse());
if (redirectUrl != null) {
return new MediaContainerDetectionResult(null, new AudioReference(redirectUrl, null));
} else if (statusCode == HttpStatus.SC_NOT_FOUND) {
return null;
} else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
throw new FriendlyException("That URL is not playable.", COMMON, new IllegalStateException("Status code " + statusCode));
}
MediaContainerHints hints = MediaContainerHints.from(getHeaderValue(inputStream.getCurrentResponse(), "Content-Type"), null);
/* START CUSTOM CHANGES */
MediaContainerDetectionResult detection = MediaContainerDetection.detectContainer(reference, inputStream, hints);
if (!ignoreHtml && !detection.isReference() && !detection.isContainerDetected() && hints.mimeType.startsWith("text/html")) {
return checkHtmlResponse(reference, inputStream, hints);
}
return detection;
/* END CUSTOM CHANGES */
} catch (URISyntaxException e) {
throw new FriendlyException("Not a valid URL.", COMMON, e);
}
}
Aggregations