use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class Main method loadAndPlay.
private void loadAndPlay(final TextChannel channel, final String trackUrl) {
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
channel.sendMessage("Adding to queue " + track.getInfo().title).queue();
play(channel.getGuild(), musicManager, track);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
channel.sendMessage("Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")").queue();
play(channel.getGuild(), musicManager, firstTrack);
}
@Override
public void noMatches() {
channel.sendMessage("Nothing found by " + trackUrl).queue();
}
@Override
public void loadFailed(FriendlyException exception) {
channel.sendMessage("Could not play: " + exception.getMessage()).queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetailsLoader method loadTrackBaseInfoFromEmbedPage.
protected JsonBrowser loadTrackBaseInfoFromEmbedPage(HttpInterface httpInterface, String videoId) throws IOException {
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet("https://www.youtube.com/embed/" + videoId))) {
HttpClientTools.assertSuccessWithContent(response, "embed video page response");
String html = EntityUtils.toString(response.getEntity(), UTF_8);
String configJson = DataFormatTools.extractAfter(html, EMBED_CONFIG_PREFIXES);
if (configJson != null) {
// configJson is not pure JSON - it contains data after the object ends, but this does not break parsing.
return JsonBrowser.parse(configJson);
}
log.debug("Did not find player config in track {} embed page HTML: {}", videoId, html);
}
throw new FriendlyException("Track information is unavailable.", SUSPICIOUS, new IllegalStateException("Expected player config is not present in embed page."));
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class YoutubeMixProvider method load.
/**
* Loads tracks from mix in parallel into a playlist entry.
*
* @param mixId ID of the mix
* @param selectedVideoId Selected track, {@link AudioPlaylist#getSelectedTrack()} will return this.
* @return Playlist of the tracks in the mix.
*/
public AudioPlaylist load(HttpInterface httpInterface, String mixId, String selectedVideoId, Function<AudioTrackInfo, AudioTrack> trackFactory) {
String playlistTitle = "YouTube mix";
List<AudioTrack> tracks = new ArrayList<>();
String mixUrl = "https://www.youtube.com/watch?v=" + selectedVideoId + "&list=" + mixId + PBJ_PARAMETER;
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(mixUrl))) {
HttpClientTools.assertSuccessWithContent(response, "mix response");
JsonBrowser body = JsonBrowser.parse(response.getEntity().getContent());
JsonBrowser playlist = body.index(3).get("response").get("contents").get("twoColumnWatchNextResults").get("playlist").get("playlist");
JsonBrowser title = playlist.get("title");
if (!title.isNull()) {
playlistTitle = title.text();
}
extractPlaylistTracks(playlist.get("contents"), tracks, trackFactory);
} catch (IOException e) {
throw new FriendlyException("Could not read mix page.", SUSPICIOUS, e);
}
if (tracks.isEmpty()) {
throw new FriendlyException("Could not find tracks from mix.", SUSPICIOUS, null);
}
AudioTrack selectedTrack = findSelectedTrack(tracks, selectedVideoId);
return new BasicAudioPlaylist(playlistTitle, tracks, selectedTrack, false);
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetails method loadLegacyTrackInfo.
private AudioTrackInfo loadLegacyTrackInfo() {
JsonBrowser args = data.polymerArguments;
if ("fail".equals(args.get("status").text())) {
throw new FriendlyException(args.get("reason").text(), COMMON, null);
}
TemporalInfo temporalInfo = TemporalInfo.fromRawData("1".equals(args.get("live_playback").text()), args.get("length_seconds"));
return buildTrackInfo(videoId, args.get("title").text(), args.get("author").text(), temporalInfo);
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetails method loadTrackInfo.
private AudioTrackInfo loadTrackInfo() {
JsonBrowser playabilityStatus = data.playerResponse.get("playabilityStatus");
if ("ERROR".equals(playabilityStatus.get("status").text())) {
throw new FriendlyException(playabilityStatus.get("reason").text(), COMMON, null);
}
JsonBrowser videoDetails = data.playerResponse.get("videoDetails");
if (videoDetails.isNull()) {
return loadLegacyTrackInfo();
}
TemporalInfo temporalInfo = TemporalInfo.fromRawData(videoDetails.get("isLiveContent").asBoolean(false), videoDetails.get("lengthSeconds"));
return buildTrackInfo(videoId, videoDetails.get("title").text(), videoDetails.get("author").text(), temporalInfo);
}
Aggregations