use of se.michaelthelin.spotify.requests.data.tracks.GetTrackRequest in project ascent_bot by FeroniK.
the class SpotifyAudioSource method getTrack.
public void getTrack(CommandContext ctx, String url) {
final Matcher res = SPOTIFY_TRACK_REGEX.matcher(url);
if (!res.matches()) {
return;
}
try {
GetTrackRequest request = this.spi.getTrack(res.group(res.groupCount())).build();
Track track = request.execute();
LOGGER.info("Name: " + track.getName());
LOGGER.info("Artist: " + track.getArtists()[0].getName());
String query = "ytsearch:" + track.getName() + " " + track.getArtists()[0].getName();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
PlayerManager.getInstance().audioPlayerManager.loadItemOrdered(musicManager, query, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
System.out.println("track loaded");
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
boolean empty = playlist.getTracks().isEmpty();
if (empty) {
return;
}
AudioTrack audioTrack = playlist.getTracks().get(0);
audioTrack.setUserData(ctx.getAuthor().getIdLong());
ctx.getChannel().sendMessageEmbeds(Embeds.songEmbed(ctx.getMember(), audioTrack).setDescription("[" + audioTrack.getInfo().title + " - " + audioTrack.getInfo().author + "]" + "(" + track.getExternalUrls().get("spotify") + ")").build()).queue();
musicManager.scheduler.queue(audioTrack);
}
@Override
public void noMatches() {
}
@Override
public void loadFailed(FriendlyException exception) {
}
});
} catch (IOException | SpotifyWebApiException | ParseException e) {
e.printStackTrace();
}
}
Aggregations