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();
}
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;
}
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);
}
}
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);
});
}
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());
}
});
}
Aggregations