use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetailsLoader method checkPlayabilityStatus.
protected InfoStatus checkPlayabilityStatus(JsonBrowser playerResponse) {
JsonBrowser statusBlock = playerResponse.get("playabilityStatus");
if (statusBlock.isNull()) {
throw new RuntimeException("No playability status block.");
}
String status = statusBlock.get("status").text();
if (status == null) {
throw new RuntimeException("No playability status field.");
} else if ("OK".equals(status)) {
return InfoStatus.INFO_PRESENT;
} else if ("ERROR".equals(status)) {
String reason = statusBlock.get("reason").text();
if ("Video unavailable".equals(reason)) {
return InfoStatus.DOES_NOT_EXIST;
} else {
throw new FriendlyException(reason, COMMON, null);
}
} else if ("UNPLAYABLE".equals(status)) {
String unplayableReason = getUnplayableReason(statusBlock);
throw new FriendlyException(unplayableReason, COMMON, null);
} else if ("LOGIN_REQUIRED".equals(status)) {
String errorReason = statusBlock.get("errorScreen").get("playerErrorMessageRenderer").get("reason").get("simpleText").text();
if ("Private video".equals(errorReason)) {
throw new FriendlyException("This is a private video.", COMMON, null);
}
return InfoStatus.REQUIRES_LOGIN;
} else if ("CONTENT_CHECK_REQUIRED".equals(status)) {
return InfoStatus.CONTENT_CHECK_REQUIRED;
} else {
throw new FriendlyException("This video cannot be viewed anonymously.", COMMON, null);
}
}
Aggregations