Search in sources :

Example 1 with Playlist

use of com.arsenarsen.lavaplayerbridge.player.Playlist in project FlareBot by FlareBot.

the class YouTubeExtractor method process.

@Override
public void process(String input, Player player, Message message, User user) throws Exception {
    AudioItem item;
    try {
        item = GeneralUtils.resolveItem(player, input);
    } catch (IllegalArgumentException e) {
        MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("Could not get that video/playlist! Make sure the URL is correct!").setColor(Color.RED), message);
        return;
    } catch (IllegalStateException e) {
        if (e.getMessage().contains("Vevo")) {
            MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("We are blocked from playing this video as it is from Vevo! " + "Sorry for any inconvenience.").setColor(Color.RED), message);
            return;
        }
        MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("There was a problem with that video!\n" + "If the error continues, join our support discord: " + Constants.INVITE_URL + "\n" + "Input: " + input + "\n" + "Error Message: " + e.getMessage() + "\n" + "Stacktrace: " + MessageUtils.paste(GeneralUtils.getStackTrace(e))).setColor(Color.RED), message);
        return;
    }
    List<AudioTrack> audioTracks = new ArrayList<>();
    String name;
    if (item instanceof AudioPlaylist) {
        AudioPlaylist audioPlaylist = (AudioPlaylist) item;
        audioTracks.addAll(audioPlaylist.getTracks());
        name = audioPlaylist.getName();
    } else {
        AudioTrack track = (AudioTrack) item;
        /*if (track.getInfo().length == 0 || track.getInfo().isStream) {
                EmbedBuilder builder = MessageUtils.getEmbed(user).setDescription("Cannot queue a livestream!");
                MessageUtils.editMessage(null, builder, message);
                return;
            }*/
        audioTracks.add(track);
        name = track.getInfo().title;
        if (track.getInfo().identifier.equals("dQw4w9WgXcQ") && (random.nextInt(1000) + 1) == 1000) {
            GeneralUtils.sendImage("https://flarebot.stream/img/rick_roll.jpg", "rick_roll.jpg", user);
            Constants.logEG("You can't rick roll me!", null, message.getGuild(), user);
        }
    }
    if (name != null) {
        List<Track> tracks = audioTracks.stream().map(Track::new).peek(track -> {
            track.getMeta().put("requester", user.getId());
            track.getMeta().put("guildId", player.getGuildId());
        }).collect(Collectors.toList());
        if (tracks.size() > 1) {
            // Double `if` https://giphy.com/gifs/ng1xAzwIkDgfm
            Playlist p = new Playlist(tracks);
            player.queue(p);
        } else {
            player.queue(tracks.get(0));
        }
        EmbedBuilder builder = MessageUtils.getEmbed(user);
        builder.setDescription(String.format("%s added the %s [`%s`](%s)", user.getAsMention(), audioTracks.size() == 1 ? "song" : "playlist", name.replace("`", "'"), input));
        if (audioTracks.size() > 1)
            builder.addField("Song count:", String.valueOf(audioTracks.size()), true);
        MessageUtils.editMessage(null, builder, message);
    }
}
Also used : Color(java.awt.Color) Track(com.arsenarsen.lavaplayerbridge.player.Track) Player(com.arsenarsen.lavaplayerbridge.player.Player) Random(java.util.Random) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Collectors(java.util.stream.Collectors) Message(net.dv8tion.jda.core.entities.Message) AudioItem(com.sedmelluq.discord.lavaplayer.track.AudioItem) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) Playlist(com.arsenarsen.lavaplayerbridge.player.Playlist) List(java.util.List) User(net.dv8tion.jda.core.entities.User) YoutubeAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager) AudioSourceManager(com.sedmelluq.discord.lavaplayer.source.AudioSourceManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Constants(stream.flarebot.flarebot.util.Constants) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) ArrayList(java.util.ArrayList) AudioItem(com.sedmelluq.discord.lavaplayer.track.AudioItem) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) Playlist(com.arsenarsen.lavaplayerbridge.player.Playlist) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Track(com.arsenarsen.lavaplayerbridge.player.Track) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

Example 2 with Playlist

use of com.arsenarsen.lavaplayerbridge.player.Playlist in project FlareBot by FlareBot.

the class SavedPlaylistExtractor method process.

@Override
public void process(String input, Player player, Message message, User user) throws Exception {
    input = input.substring(input.indexOf('\u200B') + 1).replaceAll("\\[? ?]?", "");
    int i = 0;
    ArrayList<Track> playlist = new ArrayList<>();
    for (String s : input.split(",")) {
        String url = YouTubeExtractor.WATCH_URL + s;
        Document doc;
        try {
            doc = Jsoup.connect(url).get();
        } catch (Exception e) {
            continue;
        }
        if (!doc.title().endsWith("YouTube") || doc.title().equals("YouTube")) {
            continue;
        }
        try {
            Track track = new Track((AudioTrack) player.resolve(url));
            track.getMeta().put("requester", user.getId());
            track.getMeta().put("guildId", player.getGuildId());
            playlist.add(track);
            if (playlist.size() == 10) {
                player.queue(new Playlist(playlist));
                playlist.clear();
            }
            i++;
        } catch (FriendlyException ignored) {
        }
    }
    if (!playlist.isEmpty()) {
        player.queue(new Playlist(playlist));
    }
    MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription(String.format("*Loaded %s songs!*", i)), message);
}
Also used : Playlist(com.arsenarsen.lavaplayerbridge.player.Playlist) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Track(com.arsenarsen.lavaplayerbridge.player.Track) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

Playlist (com.arsenarsen.lavaplayerbridge.player.Playlist)2 Track (com.arsenarsen.lavaplayerbridge.player.Track)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 ArrayList (java.util.ArrayList)2 Player (com.arsenarsen.lavaplayerbridge.player.Player)1 AudioSourceManager (com.sedmelluq.discord.lavaplayer.source.AudioSourceManager)1 YoutubeAudioSourceManager (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager)1 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)1 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)1 Color (java.awt.Color)1 List (java.util.List)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 Message (net.dv8tion.jda.core.entities.Message)1 User (net.dv8tion.jda.core.entities.User)1 Document (org.jsoup.nodes.Document)1 Constants (stream.flarebot.flarebot.util.Constants)1 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)1