use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class DefaultSoundCloudPlaylistLoader method loadFromSet.
protected AudioPlaylist loadFromSet(HttpInterfaceManager httpInterfaceManager, String playlistWebUrl, Function<AudioTrackInfo, AudioTrack> trackFactory) {
try (HttpInterface httpInterface = httpInterfaceManager.getInterface()) {
JsonBrowser rootData = htmlDataLoader.load(httpInterface, playlistWebUrl);
JsonBrowser playlistData = dataReader.findPlaylistData(rootData);
return new BasicAudioPlaylist(dataReader.readPlaylistName(playlistData), loadPlaylistTracks(httpInterface, playlistData, trackFactory), null, false);
} catch (IOException e) {
throw new FriendlyException("Loading playlist from SoundCloud failed.", SUSPICIOUS, e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class SoundCloudAudioSourceManager method loadFromTrackPage.
public AudioTrack loadFromTrackPage(String trackWebUrl) {
try (HttpInterface httpInterface = getHttpInterface()) {
JsonBrowser rootData = htmlDataLoader.load(httpInterface, trackWebUrl);
JsonBrowser trackData = dataReader.findTrackData(rootData);
if (trackData == null) {
throw new FriendlyException("This track is not available", COMMON, null);
}
return loadFromTrackData(trackData);
} catch (IOException e) {
throw new FriendlyException("Loading track from SoundCloud failed.", SUSPICIOUS, e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetailsLoader method loadTrackInfoWithContentVerifyRequest.
protected JsonBrowser loadTrackInfoWithContentVerifyRequest(HttpInterface httpInterface, String videoId) throws IOException {
HttpPost post = new HttpPost(AGE_VERIFY_REQUEST_URL);
StringEntity payload = new StringEntity(String.format(AGE_VERIFY_REQUEST_PAYLOAD, "/watch?v=" + videoId), "UTF-8");
post.setEntity(payload);
try (CloseableHttpResponse response = httpInterface.execute(post)) {
HttpClientTools.assertSuccessWithContent(response, "content verify response");
String json = EntityUtils.toString(response.getEntity(), UTF_8);
String fetchedContentVerifiedLink = JsonBrowser.parse(json).get("actions").index(0).get("navigateAction").get("endpoint").get("urlEndpoint").get("url").text();
if (fetchedContentVerifiedLink != null) {
return loadTrackInfoFromMainPage(httpInterface, fetchedContentVerifiedLink.substring(9));
}
log.error("Did not receive requested content verified link on track {} response: {}", videoId, json);
}
throw new FriendlyException("Track requires content verification.", SUSPICIOUS, new IllegalStateException("Expected response is not present."));
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class YoutubeAudioTrack method loadBestFormatWithUrl.
private FormatWithUrl loadBestFormatWithUrl(HttpInterface httpInterface) throws Exception {
YoutubeTrackDetails details = sourceManager.getTrackDetailsLoader().loadDetails(httpInterface, getIdentifier(), true);
// If the error reason is "Video unavailable" details will return null
if (details == null) {
throw new FriendlyException("This video is not available", FriendlyException.Severity.COMMON, null);
}
List<YoutubeTrackFormat> formats = details.getFormats(httpInterface, sourceManager.getSignatureResolver());
;
YoutubeTrackFormat format = findBestSupportedFormat(formats);
URI signedUrl = sourceManager.getSignatureResolver().resolveFormatUrl(httpInterface, details.getPlayerScript(), format);
return new FormatWithUrl(format, signedUrl);
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException 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