use of com.sedmelluq.discord.lavaplayer.track.AudioPlaylist in project MantaroBot by Mantaro.
the class AudioLoader method playlistLoaded.
@Override
public void playlistLoaded(AudioPlaylist playlist) {
if (playlist.isSearchResult()) {
if (!skipSelection)
onSearch(playlist);
else
loadSingle(playlist.getTracks().get(0), false);
return;
}
try {
int i = 0;
for (AudioTrack track : playlist.getTracks()) {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
if (guildData.getMusicQueueSizeLimit() != null) {
if (i < guildData.getMusicQueueSizeLimit()) {
loadSingle(track, true);
} else {
event.getChannel().sendMessage(String.format(":warning: The queue you added had more than %d songs, so we added songs until this limit and ignored the rest.", guildData.getMusicQueueSizeLimit())).queue();
break;
}
} else {
if (i > MAX_QUEUE_LENGTH && !dbGuild.isPremium()) {
event.getChannel().sendMessage(":warning: The queue you added had more than " + MAX_QUEUE_LENGTH + " songs, so we added songs until this limit and ignored the rest.").queue();
// stop adding songs
break;
} else {
loadSingle(track, true);
}
}
i++;
}
event.getChannel().sendMessage(String.format("%sAdded **%d songs** to queue on playlist: **%s** *(%s)*", EmoteReference.CORRECT, i, playlist.getName(), Utils.getDurationMinutes(playlist.getTracks().stream().mapToLong(temp -> temp.getInfo().length).sum()))).queue();
} catch (Exception e) {
SentryHelper.captureExceptionContext("Cannot load playlist. I guess something broke pretty hard. Please check", e, this.getClass(), "Music Loader");
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioPlaylist in project lavaplayer by sedmelluq.
the class Main method loadAndPlay.
private void loadAndPlay(final IChannel channel, final String trackUrl) {
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
sendMessageToChannel(channel, "Adding to queue " + track.getInfo().title);
play(channel.getGuild(), musicManager, track);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
sendMessageToChannel(channel, "Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")");
play(channel.getGuild(), musicManager, firstTrack);
}
@Override
public void noMatches() {
sendMessageToChannel(channel, "Nothing found by " + trackUrl);
}
@Override
public void loadFailed(FriendlyException exception) {
sendMessageToChannel(channel, "Could not play: " + exception.getMessage());
}
});
}
use of com.sedmelluq.discord.lavaplayer.track.AudioPlaylist in project lavaplayer by sedmelluq.
the class Main method loadAndPlay.
private void loadAndPlay(final TextChannel channel, final String trackUrl) {
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);
}
@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);
}
@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 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.track.AudioPlaylist in project lavaplayer by sedmelluq.
the class DefaultAudioPlayerManager method checkSourcesForItemOnce.
private AudioItem checkSourcesForItemOnce(AudioReference reference, AudioLoadResultHandler resultHandler, boolean[] reported) {
for (AudioSourceManager sourceManager : sourceManagers) {
AudioItem item = sourceManager.loadItem(this, reference);
if (item != null) {
if (item instanceof AudioTrack) {
log.debug("Loaded a track with identifier {} using {}.", reference.identifier, sourceManager.getClass().getSimpleName());
reported[0] = true;
resultHandler.trackLoaded((AudioTrack) item);
} else if (item instanceof AudioPlaylist) {
log.debug("Loaded a playlist with identifier {} using {}.", reference.identifier, sourceManager.getClass().getSimpleName());
reported[0] = true;
resultHandler.playlistLoaded((AudioPlaylist) item);
}
return item;
}
}
return null;
}
Aggregations