use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class YoutubeTrackJsonData method fromMainResult.
public static YoutubeTrackJsonData fromMainResult(JsonBrowser result) {
try {
JsonBrowser playerInfo = NULL_BROWSER;
JsonBrowser playerResponse = NULL_BROWSER;
for (JsonBrowser child : result.values()) {
if (child.isMap()) {
if (playerInfo.isNull()) {
playerInfo = child.get("player");
}
if (playerResponse.isNull()) {
playerResponse = child.get("playerResponse");
}
}
}
if (!playerInfo.isNull()) {
return fromPolymerPlayerInfo(playerInfo, playerResponse);
} else if (!playerResponse.isNull()) {
return new YoutubeTrackJsonData(playerResponse, NULL_BROWSER, null);
}
} catch (Exception e) {
throw throwWithDebugInfo(log, e, "Error parsing result", "json", result.format());
}
throw throwWithDebugInfo(log, null, "Neither player nor playerResponse in result", "json", result.format());
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser 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.JsonBrowser 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);
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubePlaylistLoader method findErrorAlert.
private String findErrorAlert(JsonBrowser jsonResponse) {
JsonBrowser alerts = jsonResponse.get("alerts");
if (!alerts.isNull()) {
for (JsonBrowser alert : alerts.values()) {
JsonBrowser alertInner = alert.values().get(0);
String type = alertInner.get("type").text();
if ("ERROR".equals(type)) {
JsonBrowser textObject = alertInner.get("text");
String text;
if (!textObject.get("simpleText").isNull()) {
text = textObject.get("simpleText").text();
} else {
text = textObject.get("runs").values().stream().map(run -> run.get("text").text()).collect(Collectors.joining());
}
return text;
}
}
}
return null;
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubePlaylistLoader method load.
@Override
public AudioPlaylist load(HttpInterface httpInterface, String playlistId, String selectedVideoId, Function<AudioTrackInfo, AudioTrack> trackFactory) {
HttpGet request = new HttpGet(getPlaylistUrl(playlistId) + PBJ_PARAMETER + "&hl=en");
try (CloseableHttpResponse response = httpInterface.execute(request)) {
HttpClientTools.assertSuccessWithContent(response, "playlist response");
HttpClientTools.assertJsonContentType(response);
JsonBrowser json = JsonBrowser.parse(response.getEntity().getContent());
return buildPlaylist(httpInterface, json, selectedVideoId, trackFactory);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations