Search in sources :

Example 51 with FriendlyException

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);
    }
}
Also used : BasicAudioPlaylist(com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist) HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) IOException(java.io.IOException) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 52 with FriendlyException

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);
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) IOException(java.io.IOException) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 53 with FriendlyException

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."));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 54 with FriendlyException

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);
}
Also used : URI(java.net.URI) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 55 with FriendlyException

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);
    }
}
Also used : JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)62 IOException (java.io.IOException)23 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)18 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)13 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)12 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)12 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)12 ArrayList (java.util.ArrayList)10 HttpGet (org.apache.http.client.methods.HttpGet)10 List (java.util.List)7 HttpInterface (com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface)6 BasicAudioPlaylist (com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 MediaContainerHints (com.sedmelluq.discord.lavaplayer.container.MediaContainerHints)3 PersistentHttpStream (com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream)3 AudioReference (com.sedmelluq.discord.lavaplayer.track.AudioReference)3 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)3 Document (org.jsoup.nodes.Document)3 Track (com.arsenarsen.lavaplayerbridge.player.Track)2