use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project lavaplayer by sedmelluq.
the class DefaultAudioPlayerManager method encodeTrack.
@Override
public void encodeTrack(MessageOutput stream, AudioTrack track) throws IOException {
DataOutput output = stream.startMessage();
output.write(TRACK_INFO_VERSION);
AudioTrackInfo trackInfo = track.getInfo();
output.writeUTF(trackInfo.title);
output.writeUTF(trackInfo.author);
output.writeLong(trackInfo.length);
output.writeUTF(trackInfo.identifier);
output.writeBoolean(trackInfo.isStream);
DataFormatTools.writeNullableText(output, trackInfo.uri);
encodeTrackDetails(track, output);
output.writeLong(track.getPosition());
stream.commitMessage(TRACK_INFO_VERSIONED);
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project lavaplayer by sedmelluq.
the class TrackStartRequestCodec method decode.
@Override
public TrackStartRequestMessage decode(DataInput in, int version) throws IOException {
long executorId = in.readLong();
AudioTrackInfo trackInfo = new AudioTrackInfo(in.readUTF(), in.readUTF(), in.readLong(), in.readUTF(), in.readBoolean(), null);
byte[] encodedTrack = new byte[in.readInt()];
in.readFully(encodedTrack);
int volume = in.readInt();
AudioConfiguration configuration = new AudioConfiguration();
configuration.setResamplingQuality(AudioConfiguration.ResamplingQuality.valueOf(in.readUTF()));
configuration.setOpusEncodingQuality(in.readInt());
if (version >= VERSION_WITH_FORMAT) {
AudioDataFormat format = new AudioDataFormat(in.readInt(), in.readInt(), in.readInt(), AudioDataFormat.Codec.valueOf(in.readUTF()));
configuration.setOutputFormat(format);
}
long position = 0;
if (version >= VERSION_WITH_POSITION) {
position = in.readLong();
}
return new TrackStartRequestMessage(executorId, trackInfo, encodedTrack, volume, configuration, position);
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project MantaroBot by Mantaro.
the class AudioLoader method loadSingle.
private void loadSingle(AudioTrack audioTrack, boolean silent) {
AudioTrackInfo trackInfo = audioTrack.getInfo();
audioTrack.setUserData(event.getAuthor().getId());
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
DBUser dbUser = MantaroData.db().getUser(event.getMember());
GuildData guildData = dbGuild.getData();
String title = trackInfo.title;
long length = trackInfo.length;
long queueLimit = !Optional.ofNullable(dbGuild.getData().getMusicQueueSizeLimit()).isPresent() ? MAX_QUEUE_LENGTH : dbGuild.getData().getMusicQueueSizeLimit();
int fqSize = guildData.getMaxFairQueue();
if (musicManager.getTrackScheduler().getQueue().size() > queueLimit && !dbUser.isPremium() && !dbGuild.isPremium()) {
if (!silent)
event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Surpassed queue song limit!", title)).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
return;
}
if (audioTrack.getInfo().length > MAX_SONG_LENGTH && !dbUser.isPremium() && !dbGuild.isPremium()) {
event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Track is longer than 32 minutes! (%s)", title, AudioUtils.getLength(length))).queue();
return;
}
// Comparing if the URLs are the same to be 100% sure they're just not spamming the same url over and over again.
if (musicManager.getTrackScheduler().getQueue().stream().filter(track -> track.getInfo().uri.equals(audioTrack.getInfo().uri)).count() > fqSize && !silent) {
event.getChannel().sendMessage(EmoteReference.ERROR + String.format("**Surpassed fair queue level of %d (Too many songs which are exactly equal)**", fqSize + 1)).queue();
return;
}
musicManager.getTrackScheduler().queue(audioTrack, insertFirst);
musicManager.getTrackScheduler().setRequestedChannel(event.getChannel().getIdLong());
if (!silent) {
event.getChannel().sendMessage(new MessageBuilder().append(String.format("\uD83D\uDCE3 Added to queue -> **%s** **(%s)**", title, AudioUtils.getLength(length))).stripMentions(event.getGuild(), Message.MentionType.EVERYONE, Message.MentionType.HERE).build()).queue();
}
MantaroBot.getInstance().getStatsClient().increment("tracks_loaded");
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project c0debaseBot by Biospheere.
the class MusicManager method loadTrack.
public void loadTrack(TextChannel channel, User requester, String trackUrl) {
Guild guild = channel.getGuild();
loadTrack(guild, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
queue(guild, track);
EmbedBuilder eb = getEmbed(guild, requester).setAuthor("Track geladen", trackUrl.startsWith("http") ? trackUrl : null, bot.getJda().getSelfUser().getEffectiveAvatarUrl());
AudioTrackInfo trackInfo = track.getInfo();
String length;
if (TimeUnit.MILLISECONDS.toHours(trackInfo.length) >= 24) {
length = String.format("%dd %02d:%02d:%02d", TimeUnit.MILLISECONDS.toDays(trackInfo.length), TimeUnit.MILLISECONDS.toHours(trackInfo.length) % 24, TimeUnit.MILLISECONDS.toMinutes(trackInfo.length) % 60, TimeUnit.MILLISECONDS.toSeconds(trackInfo.length) % 60);
} else {
length = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(trackInfo.length) % 24, TimeUnit.MILLISECONDS.toMinutes(trackInfo.length) % 60, TimeUnit.MILLISECONDS.toSeconds(trackInfo.length) % 60);
}
eb.addField(trackInfo.title, "`" + trackInfo.author + " - " + (trackInfo.isStream ? "STREAM" : length) + "`", false);
channel.sendMessage(eb.build()).queue();
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
if (playlist.isSearchResult()) {
trackLoaded(tracks.get(0));
return;
}
EmbedBuilder eb = getEmbed(guild, requester).setAuthor("Playlist geladen", playlist.isSearchResult() ? null : trackUrl, bot.getJda().getSelfUser().getEffectiveAvatarUrl());
eb.addField(playlist.getName(), "`" + tracks.size() + " Videos gefunden`", false);
channel.sendMessage(eb.build()).queue();
queue(guild, tracks);
nextTrack(guild, false);
}
@Override
public void noMatches() {
channel.sendMessage(getEmbed(guild, requester).setAuthor("Nichts gefunden", null, bot.getJda().getSelfUser().getEffectiveAvatarUrl()).addField("Keine Übereinstimmung", "`" + trackUrl + "`", false).build()).queue();
}
@Override
public void loadFailed(FriendlyException exception) {
channel.sendMessage(getEmbed(guild, requester).setAuthor("Fehler aufgetreten", null, bot.getJda().getSelfUser().getEffectiveAvatarUrl()).addField("Fehlermeldung", "`" + exception.getMessage() + "`", false).build()).queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project MantaroBot by Mantaro.
the class TrackScheduler method announce.
private void announce() {
try {
DBGuild dbGuild = MantaroData.db().getGuild(guildId);
GuildData guildData = dbGuild.getData();
if (guildData.isMusicAnnounce()) {
AudioTrackContext atc = getCurrentTrack();
if (atc == null)
return;
TextChannel req = atc.getRequestedChannel();
if (req == null)
return;
VoiceChannel vc = req.getGuild().getSelfMember().getVoiceState().getChannel();
AudioTrackInfo trackInfo = getCurrentTrack().getInfo();
String title = trackInfo.title;
long trackLength = trackInfo.length;
if (req.canTalk()) {
getCurrentTrack().getRequestedChannel().sendMessage(String.format("📣 Now playing in **%s**: %s (%s)%s", vc.getName(), title, AudioUtils.getLength(trackLength), getCurrentTrack().getDJ() != null ? " requested by **" + getCurrentTrack().getDJ().getName() + "**" : "")).queue(message -> message.delete().queueAfter(90, TimeUnit.SECONDS));
}
}
} catch (Exception ignored) {
}
}
Aggregations