Search in sources :

Example 1 with AudioPlaylist

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");
    }
}
Also used : Utils(net.kodehawa.mantarobot.utils.Utils) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) Message(net.dv8tion.jda.core.entities.Message) MantaroBot(net.kodehawa.mantarobot.MantaroBot) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) DBUser(net.kodehawa.mantarobot.db.entities.DBUser) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) SentryHelper(net.kodehawa.mantarobot.utils.SentryHelper) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) AudioUtils(net.kodehawa.mantarobot.commands.music.utils.AudioUtils) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Optional(java.util.Optional) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 2 with AudioPlaylist

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());
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 3 with AudioPlaylist

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();
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 4 with AudioPlaylist

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();
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) List(java.util.List) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 5 with AudioPlaylist

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;
}
Also used : AudioSourceManager(com.sedmelluq.discord.lavaplayer.source.AudioSourceManager) InternalAudioTrack(com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioItem(com.sedmelluq.discord.lavaplayer.track.AudioItem) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

Aggregations

AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)18 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)17 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)14 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)14 List (java.util.List)8 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)7 YoutubeAudioSourceManager (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager)5 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)5 Optional (java.util.Optional)4 TimeUnit (java.util.concurrent.TimeUnit)4 Permission (net.dv8tion.jda.core.Permission)4 Color (java.awt.Color)3 ArrayList (java.util.ArrayList)3 Slf4j (lombok.extern.slf4j.Slf4j)3 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)3 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)3 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)2 AudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager)2 DefaultAudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager)2 AudioSourceManager (com.sedmelluq.discord.lavaplayer.source.AudioSourceManager)2