Java Code Examples for com.sedmelluq.discord.lavaplayer.track.AudioTrack#getInfo()
The following examples show how to use
com.sedmelluq.discord.lavaplayer.track.AudioTrack#getInfo() .
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: RequestUtils.java From andesite-node with MIT License | 6 votes |
/** * Encodes a track into a json object, useful for sending to clients. * * @param playerManager Player manager used to encode the track. * @param track Track to encode. * * @return A json object containing information about the track. */ @Nonnull @CheckReturnValue public static JsonObject encodeTrack(@Nonnull AudioPlayerManager playerManager, @Nonnull AudioTrack track) { var info = track.getInfo(); return new JsonObject() .put("track", trackString(playerManager, track)) .put("info", new JsonObject() .put("class", track.getClass().getName()) .put("title", info.title) .put("author", info.author) .put("length", info.length) .put("identifier", info.identifier) .put("uri", info.uri) .put("isStream", info.isStream) .put("isSeekable", track.isSeekable()) .put("position", track.getPosition()) ); }
Example 2
Source File: AudioLoader.java From SkyBot with GNU Affero General Public License v3.0 | 6 votes |
@Override public void trackLoaded(AudioTrack track) { addToIndex(track); final AudioTrackInfo info = track.getInfo(); final String title = getSteamTitle(track, info.title, this.ctx.getCommandManager()); track.setUserData(new TrackUserData(this.requester)); try { this.mng.getScheduler().queue(track, this.isPatron); if (this.announce) { final String msg = "Adding to queue: [" + StringKt.abbreviate(title, 500) + "](" + info.uri + ')'; sendEmbed(this.channel, embedField(AudioUtils.EMBED_TITLE, msg) .setThumbnail(AudioTrackKt.getImageUrl(track, true)) ); } } catch (LimitReachedException e) { sendMsgFormat(ctx, "You exceeded the maximum queue size of %s tracks", e.getSize()); } }
Example 3
Source File: AudioMessageManager.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
private void addQueue(EmbedBuilder builder, PlaybackInstance instance, List<TrackRequest> requests, int offset, boolean nextHint) { if (requests.isEmpty()) { return; } for (int i = 0; i < requests.size(); i++) { TrackRequest request = requests.get(i); AudioTrack track = request.getTrack(); AudioTrackInfo info = track.getInfo(); int rowNum = i + offset; String name = EmbedBuilder.ZERO_WIDTH_SPACE; if (nextHint && i == 0) { name = messageService.getMessage("discord.command.audio.queue.next"); } String duration = info.isStream ? "" : String.format("`[%s]`", CommonUtils.formatDuration(track.getDuration())); String icon = info.isStream ? ":red_circle: " : ":musical_note: "; String title = messageService.getMessage("discord.command.audio.queue.list.entry", rowNum, duration, !nextHint && rowNum - instance.getCursor() == 1 ? icon : "", getTitle(info), getUrl(info), getMemberName(request, false)); builder.addField(name, title, false); } }
Example 4
Source File: ValidationService.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
private boolean compareTracks(AudioTrack track1, AudioTrack track2) { if (Objects.equals(track1, track2)) { return true; } AudioTrackInfo info1 = track1.getInfo(); AudioTrackInfo info2 = track2.getInfo(); if (info1 != null && info2 != null) { return Objects.equals(info1.uri, info2.uri) && Objects.equals(info1.title, info2.title) && Objects.equals(info1.author, info2.author) && Objects.equals(info1.identifier, info2.identifier) && Objects.equals(info1.length, info2.length) && Objects.equals(info1.isStream, info2.isStream); } return Objects.equals(info1, info2); }
Example 5
Source File: DefaultAudioPlayerManager.java From lavaplayer with Apache License 2.0 | 6 votes |
@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); }
Example 6
Source File: MusicUtil.java From kyoko with MIT License | 5 votes |
@Nullable public static String getThumbnail(AudioTrack track) { if (track instanceof YoutubeAudioTrack) { return "https://img.youtube.com/vi/" + track.getInfo().identifier + "/0.jpg"; } return null; }
Example 7
Source File: AudioLoaderRestHandler.java From Lavalink with MIT License | 5 votes |
private JSONObject trackToJSON(AudioTrack audioTrack) { AudioTrackInfo trackInfo = audioTrack.getInfo(); return new JSONObject() .put("title", trackInfo.title) .put("author", trackInfo.author) .put("length", trackInfo.length) .put("identifier", trackInfo.identifier) .put("uri", trackInfo.uri) .put("isStream", trackInfo.isStream) .put("isSeekable", audioTrack.isSeekable()) .put("position", audioTrack.getPosition()); }
Example 8
Source File: AudioLoader.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
private static String getSteamTitle(AudioTrack track, String rawTitle, CommandManager commandManager) { String title = rawTitle; if (track.getInfo().isStream) { final Optional<RadioStream> stream = ((RadioCommand) commandManager.getCommand("radio")) .getRadioStreams().stream().filter(s -> s.getUrl().equals(track.getInfo().uri)).findFirst(); if (stream.isPresent()) { title = stream.get().getName(); } } return title; }
Example 9
Source File: TrackData.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
public static String getArtwork(AudioTrack track) { AudioTrackInfo info = track.getInfo(); if (StringUtils.isNotBlank(info.getArtworkUrl())) { return info.getArtworkUrl(); } TrackData trackData = get(track); if (trackData.getPlaylistItem() != null && StringUtils.isNotBlank(trackData.getPlaylistItem().getArtworkUri())) { return trackData.getPlaylistItem().getArtworkUri(); } return null; }
Example 10
Source File: AudioMessageManager.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private String getTextProgress(PlaybackInstance instance, AudioTrack track, boolean bonusActive) { StringBuilder builder = new StringBuilder(); boolean closeDuration = false; if (bonusActive && instance.getPlayer().getPlayingTrack() != null) { if (!track.getInfo().isStream) { double progress = (double) instance.getPosition() / (double) track.getDuration(); builder.append(AudioUtils.getProgressString((int) (progress * 100))).append(" "); } builder.append("`").append(CommonUtils.formatDuration(instance.getPosition())); closeDuration = true; } if (!track.getInfo().isStream) { if (track.getDuration() >= 0) { if (bonusActive && builder.length() > 0) { builder.append(" / "); } builder.append(CommonUtils.formatDuration(track.getDuration())); } } if (closeDuration) { builder.append("`"); } if (track.getInfo().isStream) { builder.append(String.format(bonusActive ? " (%s)" : "%s", messageService.getMessage("discord.command.audio.panel.stream"))); } return builder.toString(); }
Example 11
Source File: TrackBoxBuilder.java From lavaplayer with Apache License 2.0 | 5 votes |
private static String buildFirstLine(int width, AudioTrack track) { StringBuilder builder = new StringBuilder(); String title = track.getInfo().title; int titleWidth = width - 7; if (title.length() > titleWidth) { builder.append(title.substring(0, titleWidth - 3)); builder.append("..."); } else { builder.append(title); } return builder.toString(); }
Example 12
Source File: YoutubeAudioSourceManagerOverride.java From SkyBot with GNU Affero General Public License v3.0 | 4 votes |
DoNotCache(AudioTrack track) { super(track.getInfo(), (YoutubeAudioSourceManager) track.getSourceManager()); }
Example 13
Source File: AudioLoader.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
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()).isEmpty() ? MAX_QUEUE_LENGTH : dbGuild.getData().getMusicQueueSizeLimit(); int fqSize = guildData.getMaxFairQueue(); if (musicManager.getTrackScheduler().getQueue().size() > queueLimit && !dbUser.isPremium() && !dbGuild.isPremium()) { if (!silent) event.getChannel().sendMessageFormat(language.get("commands.music_general.loader.over_queue_limit"), EmoteReference.WARNING, title, queueLimit ).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS)); return; } if (audioTrack.getInfo().length > MAX_SONG_LENGTH && (!dbUser.isPremium() && !dbGuild.isPremium())) { event.getChannel().sendMessageFormat(language.get("commands.music_general.loader.over_32_minutes"), EmoteReference.WARNING, 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().sendMessageFormat(language.get("commands.music_general.loader.fair_queue_limit_reached"), EmoteReference.ERROR, fqSize + 1).queue(); return; } musicManager.getTrackScheduler().queue(audioTrack, insertFirst); musicManager.getTrackScheduler().setRequestedChannel(event.getChannel().getIdLong()); if (!silent) { //Hush from here babe, hehe. Player player = MantaroData.db().getPlayer(event.getAuthor()); Badge badge = APIUtils.getHushBadge(audioTrack.getIdentifier(), Utils.HushType.MUSIC); if (badge != null) { player.getData().addBadgeIfAbsent(badge); player.save(); } event.getChannel().sendMessageFormat( language.get("commands.music_general.loader.loaded_song"), EmoteReference.CORRECT, title, AudioUtils.getLength(length) ).queue(); } Metrics.TRACK_EVENTS.labels("tracks_load").inc(); }