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());
}
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"));
}
}
Aggregations