Search in sources :

Example 1 with YoutubeAudioTrack

use of com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack in project FredBoat by Frederikam.

the class AudioLoader method loadSplit.

private void loadSplit(AudioTrack at, IdentifierContext ic) {
    if (!(at instanceof YoutubeAudioTrack)) {
        ic.reply(ic.i18n("loadSplitNotYouTube"));
        return;
    }
    YoutubeAudioTrack yat = (YoutubeAudioTrack) at;
    YoutubeVideo yv = youtubeAPI.getVideoFromID(yat.getIdentifier(), true);
    String desc = yv.getDescription();
    Matcher m = SPLIT_DESCRIPTION_PATTERN.matcher(desc);
    ArrayList<Pair<Long, String>> pairs = new ArrayList<>();
    while (m.find()) {
        long timestamp;
        try {
            timestamp = TextUtils.parseTimeString(m.group(2));
        } catch (NumberFormatException e) {
            continue;
        }
        String title1 = m.group(1);
        String title2 = m.group(3);
        if (title1.length() > title2.length()) {
            pairs.add(new ImmutablePair<>(timestamp, title1));
        } else {
            pairs.add(new ImmutablePair<>(timestamp, title2));
        }
    }
    if (pairs.size() < 2) {
        ic.reply(ic.i18n("loadSplitNotResolves"));
        return;
    }
    ArrayList<SplitAudioTrackContext> list = new ArrayList<>();
    int i = 0;
    for (Pair<Long, String> pair : pairs) {
        long startPos;
        long endPos;
        if (i != pairs.size() - 1) {
            // Not last
            startPos = pair.getLeft();
            endPos = pairs.get(i + 1).getLeft();
        } else {
            // Last
            startPos = pair.getLeft();
            endPos = at.getDuration();
        }
        AudioTrack newAt = at.makeClone();
        newAt.setPosition(startPos);
        SplitAudioTrackContext atc = new SplitAudioTrackContext(jdaEntityProvider, newAt, ic.getMember(), startPos, endPos, pair.getRight());
        list.add(atc);
        gplayer.queue(atc);
        i++;
    }
    MessageBuilder mb = CentralMessaging.getClearThreadLocalMessageBuilder().append(ic.i18n("loadFollowingTracksAdded")).append("\n");
    for (SplitAudioTrackContext atc : list) {
        mb.append("`[").append(TextUtils.formatTime(atc.getEffectiveDuration())).append("]` ").append(TextUtils.escapeAndDefuse(atc.getEffectiveTitle())).append("\n");
    }
    // This is pretty spammy .. let's use a shorter one
    if (mb.length() > 800) {
        mb = CentralMessaging.getClearThreadLocalMessageBuilder().append(ic.i18nFormat("loadPlaylistTooMany", list.size()));
    }
    context.reply(mb.build());
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) YoutubeVideo(fredboat.util.rest.YoutubeVideo) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) YoutubeAudioTrack(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack) YoutubeAudioTrack(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 2 with YoutubeAudioTrack

use of com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack in project FredBoat by Frederikam.

the class NowplayingCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player != null && player.isPlaying()) {
        AudioTrackContext atc = player.getPlayingTrack();
        AudioTrack at = atc.getTrack();
        EmbedBuilder builder;
        if (at instanceof YoutubeAudioTrack) {
            builder = getYoutubeEmbed(atc, player, (YoutubeAudioTrack) at);
        } else if (at instanceof SoundCloudAudioTrack) {
            builder = getSoundcloudEmbed(atc, player, (SoundCloudAudioTrack) at);
        } else if (at instanceof HttpAudioTrack && at.getIdentifier().contains("gensokyoradio.net")) {
            // Special handling for GR
            builder = getGensokyoRadioEmbed(context);
        } else if (at instanceof HttpAudioTrack) {
            builder = getHttpEmbed(atc, player, (HttpAudioTrack) at);
        } else if (at instanceof BandcampAudioTrack) {
            builder = getBandcampResponse(atc, player, (BandcampAudioTrack) at);
        } else if (at instanceof TwitchStreamAudioTrack) {
            builder = getTwitchEmbed(atc, (TwitchStreamAudioTrack) at);
        } else if (at instanceof BeamAudioTrack) {
            builder = getBeamEmbed(atc, (BeamAudioTrack) at);
        } else {
            builder = getDefaultEmbed(atc, player, at);
        }
        Member requester = atc.getMember() != null ? atc.getMember() : context.guild.getSelfMember();
        builder = CentralMessaging.addNpFooter(builder, requester);
        context.reply(builder.build());
    } else {
        context.reply(context.i18n("npNotPlaying"));
    }
}
Also used : TwitchStreamAudioTrack(com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioTrack) HttpAudioTrack(com.sedmelluq.discord.lavaplayer.source.http.HttpAudioTrack) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) YoutubeAudioTrack(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack) HttpAudioTrack(com.sedmelluq.discord.lavaplayer.source.http.HttpAudioTrack) BeamAudioTrack(com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioTrack) YoutubeAudioTrack(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack) SoundCloudAudioTrack(com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BandcampAudioTrack(com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioTrack) TwitchStreamAudioTrack(com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioTrack) BeamAudioTrack(com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioTrack) SoundCloudAudioTrack(com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack) BandcampAudioTrack(com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioTrack) Member(net.dv8tion.jda.core.entities.Member)

Aggregations

YoutubeAudioTrack (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 BandcampAudioTrack (com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioTrack)1 BeamAudioTrack (com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioTrack)1 HttpAudioTrack (com.sedmelluq.discord.lavaplayer.source.http.HttpAudioTrack)1 SoundCloudAudioTrack (com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack)1 TwitchStreamAudioTrack (com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioTrack)1 GuildPlayer (fredboat.audio.player.GuildPlayer)1 AudioTrackContext (fredboat.audio.queue.AudioTrackContext)1 YoutubeVideo (fredboat.util.rest.YoutubeVideo)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)1 Member (net.dv8tion.jda.core.entities.Member)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1