Search in sources :

Example 1 with AudioTrackInfo

use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project MantaroBot by Mantaro.

the class AudioRequester method loadSingle.

private void loadSingle(AudioTrack audioTrack, boolean silent) {
    AudioTrackInfo trackInfo = audioTrack.getInfo();
    DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
    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 (getMusicManager().getTrackScheduler().getQueue().size() > queueLimit && !MantaroData.db().getUser(event.getMember()).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));
        if (musicManager.getTrackScheduler().isStopped())
            event.getGuild().getAudioManager().closeAudioConnection();
        return;
    }
    if (audioTrack.getInfo().length > MAX_SONG_LENGTH && !MantaroData.db().getUser(event.getMember()).isPremium() && !dbGuild.isPremium()) {
        event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Track is longer than 21 minutes! (%s)", title, AudioUtils.getLength(length))).queue();
        if (musicManager.getTrackScheduler().isStopped())
            //do you?
            event.getGuild().getAudioManager().closeAudioConnection();
        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) {
        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(new AudioTrackContext(event.getAuthor(), event.getChannel(), audioTrack.getSourceManager() instanceof YoutubeAudioSourceManager ? "https://www.youtube.com/watch?v=" + audioTrack.getIdentifier() : trackUrl, audioTrack));
    if (!silent) {
        event.getChannel().sendMessage(String.format("📣 Added to queue -> **%s** **!(%s)**", title, AudioUtils.getLength(length))).queue();
    }
}
Also used : FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) Color(java.awt.Color) Utils(net.kodehawa.mantarobot.utils.Utils) IntConsumer(java.util.function.IntConsumer) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) ReactionOperations(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperations) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) YoutubeAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager) GuildData(net.kodehawa.mantarobot.data.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) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) YoutubeAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 2 with AudioTrackInfo

use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project c0debaseBot by Biospheere.

the class SkipCommand method execute.

@Override
public void execute(String[] args, Message msg) {
    EmbedBuilder embedBuilder = getEmbed(msg.getGuild(), msg.getAuthor());
    if (msg.getMember().getVoiceState().inVoiceChannel() && msg.getMember().getVoiceState().getChannel().getMembers().contains(msg.getGuild().getSelfMember())) {
        CodebaseBot.getInstance().getMusicManager().skip(msg.getGuild());
        if (CodebaseBot.getInstance().getMusicManager().getPlayingTrack(msg.getGuild()) != null) {
            AudioTrackInfo trackInfo = CodebaseBot.getInstance().getMusicManager().getPlayingTrack(msg.getGuild()).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);
            }
            embedBuilder.addField(trackInfo.title, "`" + trackInfo.author + " - " + (trackInfo.isStream ? "STREAM" : length) + "`", false);
        } else {
            embedBuilder.setDescription("Es gibt kein weiteres Lied in der Warteschlange");
        }
    } else {
        embedBuilder.setDescription("Du bist in keinem Voicechannel mit dem Bot");
    }
    msg.getTextChannel().sendMessage(embedBuilder.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 3 with AudioTrackInfo

use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project lavaplayer by sedmelluq.

the class SoundCloudAudioSourceManager method buildAudioTrack.

private AudioTrack buildAudioTrack(JsonBrowser trackInfoJson, String secretToken) {
    String trackId = trackInfoJson.get("id").text();
    AudioTrackInfo trackInfo = new AudioTrackInfo(trackInfoJson.get("title").text(), trackInfoJson.get("user").get("username").text(), trackInfoJson.get("duration").as(Integer.class), secretToken != null ? trackId + "|" + secretToken : trackId, false, trackInfoJson.get("permalink_url").text());
    return new SoundCloudAudioTrack(trackInfo, this);
}
Also used : AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 4 with AudioTrackInfo

use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project lavaplayer by sedmelluq.

the class TwitchStreamAudioSourceManager method loadItem.

@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
    String streamName = getChannelIdentifierFromUrl(reference.identifier);
    if (streamName == null) {
        return null;
    }
    JsonBrowser channelInfo = fetchStreamChannelInfo(streamName);
    if (channelInfo == null) {
        return AudioReference.NO_TRACK;
    } else {
        final String displayName = channelInfo.get("display_name").text();
        final String status = channelInfo.get("status").text();
        return new TwitchStreamAudioTrack(new AudioTrackInfo(status, displayName, Long.MAX_VALUE, reference.identifier, true, reference.identifier), this);
    }
}
Also used : AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)

Example 5 with AudioTrackInfo

use of com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo in project lavaplayer by sedmelluq.

the class MatroskaContainerProbe method probe.

@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
    if (!checkNextBytes(inputStream, EBML_TAG)) {
        return null;
    }
    log.debug("Track {} is a matroska file.", reference.identifier);
    MatroskaStreamingFile file = new MatroskaStreamingFile(inputStream);
    file.readFile();
    if (!hasSupportedAudioTrack(file)) {
        return new MediaContainerDetectionResult(this, "No supported audio tracks present in the file.");
    }
    return new MediaContainerDetectionResult(this, new AudioTrackInfo(UNKNOWN_TITLE, UNKNOWN_ARTIST, (long) file.getDuration(), reference.identifier, false, reference.identifier));
}
Also used : MediaContainerDetectionResult(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Aggregations

AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)22 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)7 MediaContainerDetectionResult (com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult)6 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)6 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)5 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)3 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)3 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)2 List (java.util.List)2 Optional (java.util.Optional)2 TimeUnit (java.util.concurrent.TimeUnit)2 Slf4j (lombok.extern.slf4j.Slf4j)2 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)2 Message (net.dv8tion.jda.core.entities.Message)2 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)2 MantaroData (net.kodehawa.mantarobot.data.MantaroData)2 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)2 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)2 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)2 Utils (net.kodehawa.mantarobot.utils.Utils)2