use of org.jmusixmatch.entity.track.Track in project Rubicon by Rubicon-Bot.
the class MusicManager method loadSong.
public void loadSong(boolean force) {
TextChannel textChannel = parsedCommandInvocation.getMessage().getTextChannel();
boolean isURL = false;
StringBuilder searchParam = new StringBuilder();
for (int i = 0; i < args.length; i++) searchParam.append(args[i]);
if (searchParam.toString().startsWith("http://") || searchParam.toString().startsWith("https://"))
isURL = true;
if (!isURL)
searchParam.insert(0, "ytsearch: ");
final EmbedBuilder embedBuilder = new EmbedBuilder();
final boolean isURLFinal = isURL;
playerManager.loadItemOrdered(getCurrentMusicManager(), searchParam.toString(), new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack audioTrack) {
String trackName = audioTrack.getInfo().title;
String trackAuthor = audioTrack.getInfo().author;
String trackURL = audioTrack.getInfo().uri;
boolean isStream = audioTrack.getInfo().isStream;
long trackDuration = audioTrack.getDuration();
if (!force) {
getCurrentMusicManager().getScheduler().queue(audioTrack);
embedBuilder.setAuthor("Added a new song to queue", trackURL, null);
embedBuilder.addField("Title", trackName, true);
embedBuilder.addField("Author", trackAuthor, true);
embedBuilder.addField("Duration", (isStream) ? "Stream" : getTimestamp(trackDuration), false);
embedBuilder.setColor(Colors.COLOR_PRIMARY);
textChannel.sendMessage(embedBuilder.build()).queue();
}
}
@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
AudioTrack firstTrack = audioPlaylist.getSelectedTrack();
List<AudioTrack> playlistTracks = audioPlaylist.getTracks();
playlistTracks = playlistTracks.stream().limit(QUEUE_MAXIMUM - getCurrentMusicManager().getScheduler().getQueue().size()).collect(Collectors.toList());
if (firstTrack == null)
firstTrack = playlistTracks.get(0);
if (force) {
getCurrentMusicManager().getPlayer().playTrack(firstTrack);
return;
}
if (isURLFinal) {
playlistTracks.forEach(getCurrentMusicManager().getScheduler()::queue);
embedBuilder.setTitle("Added playlist to queue");
embedBuilder.setDescription("Added `" + playlistTracks.size() + "` songs from `" + audioPlaylist.getName() + "` to queue.\n" + "\n" + "**Now playing** `" + firstTrack.getInfo().title + "`");
embedBuilder.addField("Author", firstTrack.getInfo().author, true);
embedBuilder.addField("Duration", (firstTrack.getInfo().isStream) ? "Stream" : getTimestamp(firstTrack.getDuration()), false);
textChannel.sendMessage(embedBuilder.build()).queue();
embedBuilder.setColor(Colors.COLOR_PRIMARY);
textChannel.sendMessage(embedBuilder.build()).queue();
} else {
MusicSearchResult musicSearchResult = new MusicSearchResult(parsedCommandInvocation.getAuthor(), guild, getCurrentMusicManager());
audioPlaylist.getTracks().stream().limit(5).collect(Collectors.toList()).forEach(track -> {
try {
musicSearchResult.addTrack(track);
} catch (Exception e) {
e.printStackTrace();
}
});
musicSearchResult.setMessage(textChannel.sendMessage(musicSearchResult.generateEmbed().build()).complete());
musicChoose.add(musicSearchResult);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
if (musicChoose.contains(musicSearchResult)) {
musicSearchResult.getMessage().delete().queue();
musicChoose.remove(musicSearchResult);
}
}
}, 15000);
}
}
@Override
public void noMatches() {
embedBuilder.setTitle("No matches!");
embedBuilder.setDescription("There are no matches.");
embedBuilder.setColor(Colors.COLOR_NOT_IMPLEMENTED);
textChannel.sendMessage(embedBuilder.build()).queue();
}
@Override
public void loadFailed(FriendlyException e) {
embedBuilder.setTitle(":warning: Error!");
embedBuilder.setDescription("Could not play this song: " + e.getMessage());
embedBuilder.setColor(Colors.COLOR_ERROR);
textChannel.sendMessage(embedBuilder.build()).queue();
}
});
}
use of org.jmusixmatch.entity.track.Track in project Rubicon by Rubicon-Bot.
the class MusicManager method executeLyrics.
public Message executeLyrics() {
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."));
}
MusixMatch musixMatch = new MusixMatch(Info.MUSIXMATCH_KEY);
AudioTrackInfo info = this.getCurrentTrack().getInfo();
Track track;
Lyrics lyrics;
try {
track = musixMatch.getMatchingTrack(info.title, info.author);
lyrics = musixMatch.getLyrics(track.getTrack().getTrackId());
} catch (MusixMatchException e) {
return new MessageBuilder().setEmbed(EmbedUtil.error("No lyrics found", "There are no lyrics of the current song on Musixmatch").build()).build();
}
EmbedBuilder lyricsEmbed = new EmbedBuilder();
lyricsEmbed.setColor(Colors.COLOR_PREMIUM);
lyricsEmbed.setTitle("Lyrics of `" + track.getTrack().getTrackName() + "`", track.getTrack().getTrackShareUrl());
lyricsEmbed.setFooter(lyrics.getLyricsCopyright(), null);
lyricsEmbed.setDescription(lyrics.getLyricsBody());
return new MessageBuilder().setEmbed(lyricsEmbed.build()).build();
}
use of org.jmusixmatch.entity.track.Track 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();
}
Aggregations