use of com.sedmelluq.discord.lavaplayer.track.AudioPlaylist in project FlareBot by FlareBot.
the class YouTubeExtractor method process.
@Override
public void process(String input, Player player, Message message, User user) throws Exception {
AudioItem item;
try {
item = GeneralUtils.resolveItem(player, input);
} catch (IllegalArgumentException e) {
MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("Could not get that video/playlist! Make sure the URL is correct!").setColor(Color.RED), message);
return;
} catch (IllegalStateException e) {
if (e.getMessage().contains("Vevo")) {
MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("We are blocked from playing this video as it is from Vevo! " + "Sorry for any inconvenience.").setColor(Color.RED), message);
return;
}
MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("There was a problem with that video!\n" + "If the error continues, join our support discord: " + Constants.INVITE_URL + "\n" + "Input: " + input + "\n" + "Error Message: " + e.getMessage() + "\n" + "Stacktrace: " + MessageUtils.paste(GeneralUtils.getStackTrace(e))).setColor(Color.RED), message);
return;
}
List<AudioTrack> audioTracks = new ArrayList<>();
String name;
if (item instanceof AudioPlaylist) {
AudioPlaylist audioPlaylist = (AudioPlaylist) item;
audioTracks.addAll(audioPlaylist.getTracks());
name = audioPlaylist.getName();
} else {
AudioTrack track = (AudioTrack) item;
/*if (track.getInfo().length == 0 || track.getInfo().isStream) {
EmbedBuilder builder = MessageUtils.getEmbed(user).setDescription("Cannot queue a livestream!");
MessageUtils.editMessage(null, builder, message);
return;
}*/
audioTracks.add(track);
name = track.getInfo().title;
if (track.getInfo().identifier.equals("dQw4w9WgXcQ") && (random.nextInt(1000) + 1) == 1000) {
GeneralUtils.sendImage("https://flarebot.stream/img/rick_roll.jpg", "rick_roll.jpg", user);
Constants.logEG("You can't rick roll me!", null, message.getGuild(), user);
}
}
if (name != null) {
List<Track> tracks = audioTracks.stream().map(Track::new).peek(track -> {
track.getMeta().put("requester", user.getId());
track.getMeta().put("guildId", player.getGuildId());
}).collect(Collectors.toList());
if (tracks.size() > 1) {
// Double `if` https://giphy.com/gifs/ng1xAzwIkDgfm
Playlist p = new Playlist(tracks);
player.queue(p);
} else {
player.queue(tracks.get(0));
}
EmbedBuilder builder = MessageUtils.getEmbed(user);
builder.setDescription(String.format("%s added the %s [`%s`](%s)", user.getAsMention(), audioTracks.size() == 1 ? "song" : "playlist", name.replace("`", "'"), input));
if (audioTracks.size() > 1)
builder.addField("Song count:", String.valueOf(audioTracks.size()), true);
MessageUtils.editMessage(null, builder, message);
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioPlaylist 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.track.AudioPlaylist in project legendarybot by greatman.
the class MusicManager method loadAndPlay.
/**
* Load a song
* @param channel The channel to send the alert in.
* @param trackUrl The song URL
* @param voiceChannel the voice channel to play the music in.
*/
public void loadAndPlay(final TextChannel channel, final String trackUrl, VoiceChannel voiceChannel) {
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
channel.sendMessage("Adding to queue " + track.getInfo().title).queue();
play(channel.getGuild(), musicManager, track, voiceChannel);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
channel.sendMessage("Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")").queue();
play(channel.getGuild(), musicManager, firstTrack, voiceChannel);
}
@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();
}
});
}
Aggregations