Search in sources :

Example 76 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Rubicon by Rubicon-Bot.

the class MusicManager method handleTrackChoose.

public static void handleTrackChoose(MessageReceivedEvent event) {
    List<MusicSearchResult> storage = musicChoose.stream().filter(musicSearchResult -> musicSearchResult.getUser() == event.getAuthor()).collect(Collectors.toList());
    if (storage.size() == 0) {
        return;
    }
    String response = event.getMessage().getContentDisplay();
    if (!StringUtil.isNumeric(response)) {
        return;
    }
    int ans = Integer.parseInt(response);
    if (ans < 1 || ans > 5) {
        return;
    }
    ans--;
    AudioTrack track = storage.get(0).getTrack(ans);
    storage.get(0).getMusicManager().getScheduler().queue(track);
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setAuthor("Added a new song to queue", track.getInfo().uri, null);
    embedBuilder.addField("Title", track.getInfo().title, true);
    embedBuilder.addField("Author", track.getInfo().author, true);
    embedBuilder.addField("Duration", (track.getInfo().isStream) ? "Stream" : getTimestamp(track.getDuration()), false);
    embedBuilder.setColor(Colors.COLOR_PRIMARY);
    event.getTextChannel().sendMessage(embedBuilder.build()).queue();
    storage.get(0).getMessage().delete().queue();
    musicChoose.remove(storage.get(0));
    event.getMessage().delete().queue();
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) EmbedUtil(fun.rubicon.util.EmbedUtil) java.util(java.util) CommandManager(fun.rubicon.command.CommandManager) Lyrics(org.jmusixmatch.entity.lyrics.Lyrics) GuildMusicSQL(fun.rubicon.sql.GuildMusicSQL) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) Permission(net.dv8tion.jda.core.Permission) HttpAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.http.HttpAudioSourceManager) YoutubeAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) MusixMatch(org.jmusixmatch.MusixMatch) RubiconBot(fun.rubicon.RubiconBot) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) MusixMatchException(org.jmusixmatch.MusixMatchException) Track(org.jmusixmatch.entity.track.Track) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) fun.rubicon.util(fun.rubicon.util) Collectors(java.util.stream.Collectors) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) UserMusicSQL(fun.rubicon.sql.UserMusicSQL) MessageReceivedEvent(net.dv8tion.jda.core.events.message.MessageReceivedEvent) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 77 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Rubicon by Rubicon-Bot.

the class MusicManager method executeNowPlaying.

public Message executeNowPlaying() {
    if (!isBotInVoiceChannel())
        return message(error("Error!", "Bot is not in a voice channel."));
    VoiceChannel channel = getBotsVoiceChannel();
    if (parsedCommandInvocation.getMember().getVoiceState().getChannel() != channel)
        return message(error("Error!", "You have to be in the same voice channel as the bot."));
    if (getCurrentMusicManager().getPlayer().getPlayingTrack() == null) {
        return message(error("Error!", "Bot is playing nothing."));
    }
    AudioTrack track = getCurrentMusicManager().getPlayer().getPlayingTrack();
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setAuthor("Currently playing", track.getInfo().uri, null);
    embedBuilder.addField("Title", track.getInfo().title, true);
    embedBuilder.addField("Author", track.getInfo().author, true);
    embedBuilder.addField("Duration", (track.getInfo().isStream) ? "Stream" : getTimestamp(track.getDuration()), false);
    embedBuilder.setColor(Colors.COLOR_PRIMARY);
    parsedCommandInvocation.getMessage().getTextChannel().sendMessage(embedBuilder.build()).queue();
    return null;
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 78 with AudioTrack

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

the class YoutubeSearchProvider method extractSearchResults.

private AudioItem extractSearchResults(Document document, String query, Function<AudioTrackInfo, AudioTrack> trackFactory) {
    List<AudioTrack> tracks = new ArrayList<>();
    Elements resultsSelection = document.select("#page > #content #results");
    if (!resultsSelection.isEmpty()) {
        for (Element results : resultsSelection) {
            for (Element result : results.select(".yt-lockup-video")) {
                if (!result.hasAttr("data-ad-impressions") && result.select(".standalone-ypc-badge-renderer-label").isEmpty()) {
                    extractTrackFromResultEntry(tracks, result, trackFactory);
                }
            }
        }
    } else {
        log.debug("Attempting to parse results page as polymer");
        try {
            tracks = polymerExtractTracks(document, trackFactory);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    if (tracks.isEmpty()) {
        return AudioReference.NO_TRACK;
    } else {
        return new BasicAudioPlaylist("Search results for: " + query, tracks, null, true);
    }
}
Also used : BasicAudioPlaylist(com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) IOException(java.io.IOException) Elements(org.jsoup.select.Elements)

Example 79 with AudioTrack

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

the class BandcampAudioSourceManager method loadAlbum.

private AudioItem loadAlbum(UrlInfo urlInfo) {
    return extractFromPage(urlInfo.fullUrl, (httpClient, text) -> {
        JsonBrowser trackListInfo = readTrackListInformation(text);
        String artist = trackListInfo.get("artist").text();
        List<AudioTrack> tracks = new ArrayList<>();
        for (JsonBrowser trackInfo : trackListInfo.get("trackinfo").values()) {
            tracks.add(extractTrack(trackInfo, urlInfo.baseUrl, artist));
        }
        JsonBrowser albumInfo = readAlbumInformation(text);
        return new BasicAudioPlaylist(albumInfo.get("current").get("title").text(), tracks, null, false);
    });
}
Also used : BasicAudioPlaylist(com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)

Example 80 with AudioTrack

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

the class Main method loadAndPlay.

private void loadAndPlay(TextChannel channel, final String trackUrl) {
    GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild().block());
    playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {

        @Override
        public void trackLoaded(AudioTrack track) {
            sendMessageToChannel(channel, "Adding to queue " + track.getInfo().title);
            play(channel.getGuild().block(), musicManager, track);
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist) {
            AudioTrack firstTrack = playlist.getSelectedTrack();
            if (firstTrack == null) {
                firstTrack = playlist.getTracks().get(0);
            }
            sendMessageToChannel(channel, "Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")");
            play(channel.getGuild().block(), musicManager, firstTrack);
        }

        @Override
        public void noMatches() {
            sendMessageToChannel(channel, "Nothing found by " + trackUrl);
        }

        @Override
        public void loadFailed(FriendlyException exception) {
            sendMessageToChannel(channel, "Could not play: " + exception.getMessage());
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

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