Search in sources :

Example 16 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project FredBoat by Frederikam.

the class ForwardCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player == null || player.isQueueEmpty()) {
        context.replyWithName(context.i18n("unpauseQueueEmpty"));
        return;
    }
    if (!context.hasArguments()) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    long t;
    try {
        t = TextUtils.parseTimeString(context.args[0]);
    } catch (IllegalStateException e) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    AudioTrackContext atc = player.getPlayingTrack();
    AudioTrack at = atc.getTrack();
    // Ensure bounds
    t = Math.max(0, t);
    t = Math.min(atc.getEffectiveDuration(), t);
    player.seekTo(player.getPosition() + t);
    context.reply(context.i18nFormat("fwdSuccess", TextUtils.escapeAndDefuse(atc.getEffectiveTitle()), TextUtils.formatTime(t)));
}
Also used : GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 17 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack 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);
        }
    });
}
Also used : VideoSelection(fredboat.audio.player.VideoSelectionCache.VideoSelection) TrackSearcher(fredboat.util.rest.TrackSearcher) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

Example 18 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project FredBoat by Frederikam.

the class SelectCommand method select.

static void select(CommandContext context, VideoSelectionCache videoSelectionCache) {
    Member invoker = context.invoker;
    VideoSelection selection = videoSelectionCache.get(invoker);
    if (selection == null) {
        context.reply(context.i18n("selectSelectionNotGiven"));
        return;
    }
    try {
        // Step 1: Parse the issued command for numbers
        // LinkedHashSet to handle order of choices + duplicates
        LinkedHashSet<Integer> requestChoices = new LinkedHashSet<>();
        // Combine all args and the command trigger if it is numeric
        String commandOptions = context.rawArgs;
        if (StringUtils.isNumeric(context.trigger)) {
            commandOptions = (context.trigger + " " + commandOptions).trim();
        }
        if (StringUtils.isNumeric(commandOptions)) {
            requestChoices.add(Integer.valueOf(commandOptions));
        } else if (TextUtils.isSplitSelect(commandOptions)) {
            requestChoices.addAll(TextUtils.getSplitSelect(commandOptions));
        }
        // Step 2: Use only valid numbers (usually 1-5)
        ArrayList<Integer> validChoices = new ArrayList<>();
        // Only include valid values which are 1 to <size> of the offered selection
        for (Integer value : requestChoices) {
            if (1 <= value && value <= selection.choices.size()) {
                validChoices.add(value);
                Metrics.selectionChoiceChosen.labels(value.toString()).inc();
            }
        }
        // any valid choices at all?
        if (validChoices.isEmpty()) {
            throw new NumberFormatException();
        } else {
            if (validChoices.size() > 1) {
                Metrics.multiSelections.labels(Integer.toString(validChoices.size())).inc();
            }
            AudioTrack[] selectedTracks = new AudioTrack[validChoices.size()];
            StringBuilder outputMsgBuilder = new StringBuilder();
            GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getOrCreate(context.guild);
            for (int i = 0; i < validChoices.size(); i++) {
                selectedTracks[i] = selection.choices.get(validChoices.get(i) - 1);
                String msg = context.i18nFormat("selectSuccess", validChoices.get(i), TextUtils.escapeAndDefuse(selectedTracks[i].getInfo().title), TextUtils.formatTime(selectedTracks[i].getInfo().length));
                if (i < validChoices.size()) {
                    outputMsgBuilder.append("\n");
                }
                outputMsgBuilder.append(msg);
                player.queue(new AudioTrackContext(Launcher.getBotController().getJdaEntityProvider(), selectedTracks[i], invoker));
            }
            videoSelectionCache.remove(invoker);
            TextChannel tc = Launcher.getBotController().getJdaEntityProvider().getTextChannelById(selection.channelId);
            if (tc != null) {
                CentralMessaging.editMessage(tc, selection.outMsgId, CentralMessaging.from(outputMsgBuilder.toString()));
            }
            player.setPause(false);
            context.deleteMessage();
        }
    } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
        context.reply(context.i18nFormat("selectInterval", selection.choices.size()));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) VideoSelection(fredboat.audio.player.VideoSelectionCache.VideoSelection) TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Member(net.dv8tion.jda.core.entities.Member)

Example 19 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Shadbot by Shadorc.

the class PlaylistCmd method formatPlaylist.

private String formatPlaylist(BlockingQueue<AudioTrack> queue) {
    if (queue.isEmpty()) {
        return "**The playlist is empty.**";
    }
    StringBuilder playlist = new StringBuilder(String.format("**%s in the playlist:**\n", StringUtils.pluralOf(queue.size(), "music")));
    int count = 1;
    for (AudioTrack track : queue) {
        String name = String.format("%n\t**%d.** %s", count, FormatUtils.formatTrackName(track.getInfo()));
        if (playlist.length() + name.length() < 1800) {
            playlist.append(name);
        } else {
            playlist.append("\n\t...");
            break;
        }
        count++;
    }
    return playlist.toString();
}
Also used : AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 20 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Shadbot by Shadorc.

the class TrackScheduler method skipTo.

public void skipTo(int num) {
    AudioTrack track = null;
    for (int i = 0; i < num; i++) {
        track = queue.poll();
    }
    audioPlayer.playTrack(track.makeClone());
    this.currentTrack = track;
}
Also used : AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Aggregations

AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)85 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)26 ArrayList (java.util.ArrayList)23 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)21 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)18 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)17 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)11 List (java.util.List)10 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)9 IOException (java.io.IOException)9 BasicAudioPlaylist (com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist)8 TimeUnit (java.util.concurrent.TimeUnit)7 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)7 YoutubeAudioSourceManager (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager)6 Optional (java.util.Optional)6 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)6 Permission (net.dv8tion.jda.core.Permission)6 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)5 InternalAudioTrack (com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)5 Slf4j (lombok.extern.slf4j.Slf4j)5