Java Code Examples for com.sedmelluq.discord.lavaplayer.track.AudioPlaylist#getTracks()
The following examples show how to use
com.sedmelluq.discord.lavaplayer.track.AudioPlaylist#getTracks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AudioLoader.java From Lavalink with MIT License | 6 votes |
@Override public void playlistLoaded(AudioPlaylist audioPlaylist) { log.info("Loaded playlist " + audioPlaylist.getName()); String playlistName = null; Integer selectedTrack = null; if (!audioPlaylist.isSearchResult()) { playlistName = audioPlaylist.getName(); selectedTrack = audioPlaylist.getTracks().indexOf(audioPlaylist.getSelectedTrack()); } ResultStatus status = audioPlaylist.isSearchResult() ? ResultStatus.SEARCH_RESULT : ResultStatus.PLAYLIST_LOADED; List<AudioTrack> loadedItems = audioPlaylist.getTracks(); this.loadResult.complete(new LoadResult(status, loadedItems, playlistName, selectedTrack)); }
Example 2
Source File: AudioLoader.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
private void onSearch(AudioPlaylist playlist) { List<AudioTrack> list = playlist.getTracks(); DiscordUtils.selectList(event, list.subList(0, Math.min(5, list.size())), track -> String.format("**[%s](%s)** (%s)", track.getInfo().title, track.getInfo().uri, Utils.getDurationMinutes(track.getInfo().length)), s -> new EmbedBuilder().setColor(Color.CYAN).setAuthor(language.get("commands.music_general.loader.selection_text"), "https://i.imgur.com/sFDpUZy.png") .setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png") .setDescription(s) .setFooter(language.get("commands.music_general.loader.timeout_text"), null).build(), selected -> loadSingle(selected, false) ); Metrics.TRACK_EVENTS.labels("tracks_search").inc(); }
Example 3
Source File: ValidationService.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
public List<AudioTrack> filterPlaylist(AudioPlaylist playlist, Member requestedBy) throws ValidationException { MusicConfig config = musicConfigService.get(requestedBy.getGuild()); Long queueLimit = config != null ? config.getQueueLimit() : null; Long durationLimit = config != null ? config.getDurationLimit() : null; Long duplicateLimit = config != null ? config.getDuplicateLimit() : null; PlaybackInstance instance = playerService.get(requestedBy.getGuild()); if (config == null || !Boolean.TRUE.equals(config.getPlaylistEnabled())) { throw new ValidationException("discord.command.audio.queue.limits.playlists"); } List<AudioTrack> tracks = playlist.getTracks(); if (!tracks.isEmpty() && !config.isStreamsEnabled()) { tracks = tracks.stream().filter(e -> !e.getInfo().isStream).collect(Collectors.toList()); if (tracks.isEmpty()) { throw new ValidationException("discord.command.audio.queue.limits.streams"); } } if (!tracks.isEmpty() && durationLimit != null) { tracks = tracks.stream().filter(e -> e.getInfo().isStream || e.getDuration() < (durationLimit * 60000)).collect(Collectors.toList()); if (tracks.isEmpty()) { throw new ValidationException("discord.command.audio.queue.limits.duration.playlist", durationLimit); } } if (instance != null && !tracks.isEmpty() && duplicateLimit != null) { List<TrackRequest> queue = instance.getQueue(); tracks = tracks.stream().filter(e -> queue.stream().filter(e2 -> compareTracks(e2.getTrack(), e)).count() < duplicateLimit).collect(Collectors.toList()); if (tracks.isEmpty()) { throw new ValidationException("discord.command.audio.queue.limits.duplicates.playlist", duplicateLimit); } } if (tracks.isEmpty()) { throw new ValidationException("discord.command.audio.queue.limits.playlistEmpty"); } if (instance != null && queueLimit != null) { List<TrackRequest> userQueue = instance.getQueue(requestedBy); int availableSlots = queueLimit.intValue() - userQueue.size(); if (availableSlots <= 0) { throw new ValidationException("discord.command.audio.queue.limits.items", queueLimit); } if (tracks.size() > availableSlots) { tracks = tracks.subList(0, availableSlots); } } return tracks; }
Example 4
Source File: AudioLoader.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
@Override public void playlistLoaded(AudioPlaylist playlist) { if (playlist.isSearchResult()) { if (!skipSelection) { onSearch(playlist); } else { loadSingle(playlist.getTracks().get(0), false); } return; } try { int i = 0; for (AudioTrack track : playlist.getTracks()) { DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild()); DBUser user = MantaroData.db().getUser(event.getMember()); GuildData guildData = dbGuild.getData(); if (guildData.getMusicQueueSizeLimit() != null) { if (i < guildData.getMusicQueueSizeLimit()) { loadSingle(track, true); } else { event.getChannel().sendMessageFormat(language.get("commands.music_general.loader.over_limit"), EmoteReference.WARNING, guildData.getMusicQueueSizeLimit()).queue(); break; } } else { if (i > MAX_QUEUE_LENGTH && (!dbGuild.isPremium() && !user.isPremium())) { event.getChannel().sendMessageFormat(language.get("commands.music_general.loader.over_limit"), EmoteReference.WARNING, MAX_QUEUE_LENGTH).queue(); break; //stop adding songs } else { loadSingle(track, true); } } i++; } event.getChannel().sendMessageFormat(language.get("commands.music_general.loader.loaded_playlist"), EmoteReference.CORRECT, i, playlist.getName(), Utils.getDurationMinutes(playlist.getTracks().stream().mapToLong(temp -> temp.getInfo().length).sum()) ).queue(); } catch (Exception e) { SentryHelper.captureExceptionContext("Cannot load playlist. I guess something broke pretty hard. Please check", e, this.getClass(), "Music Loader"); } }