use of com.sedmelluq.discord.lavaplayer.track.AudioPlaylist 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.track.AudioPlaylist in project FredBoat by Frederikam.
the class PlayCommand method searchForVideos.
private void searchForVideos(CommandContext context) {
// Now remove all punctuation
String query = context.rawArgs.replaceAll(TrackSearcher.PUNCTUATION_REGEX, "");
context.reply(context.i18n("playSearching").replace("{q}", query), outMsg -> {
AudioPlaylist list;
try {
list = trackSearcher.searchForTracks(query, searchProviders);
} catch (TrackSearcher.SearchingException e) {
context.reply(context.i18n("playYoutubeSearchError"));
log.error("YouTube search exception", e);
return;
}
if (list == null || list.getTracks().isEmpty()) {
CentralMessaging.editMessage(outMsg, context.i18n("playSearchNoResults").replace("{q}", query));
} else {
// Get at most 5 tracks
List<AudioTrack> selectable = list.getTracks().subList(0, Math.min(TrackSearcher.MAX_RESULTS, list.getTracks().size()));
VideoSelection oldSelection = videoSelectionCache.remove(context.invoker);
if (oldSelection != null) {
oldSelection.deleteMessage();
}
MessageBuilder builder = CentralMessaging.getClearThreadLocalMessageBuilder();
builder.append(context.i18nFormat("playSelectVideo", TextUtils.escapeMarkdown(context.getPrefix())));
int i = 1;
for (AudioTrack track : selectable) {
builder.append("\n**").append(String.valueOf(i)).append(":** ").append(TextUtils.escapeAndDefuse(track.getInfo().title)).append(" (").append(TextUtils.formatTime(track.getInfo().length)).append(")");
i++;
}
CentralMessaging.editMessage(outMsg, builder.build());
videoSelectionCache.put(context.invoker, selectable, outMsg);
}
});
}
use of com.sedmelluq.discord.lavaplayer.track.AudioPlaylist 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.track.AudioPlaylist 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.track.AudioPlaylist 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();
}
});
}
Aggregations