Search in sources :

Example 1 with MediaContainerHints

use of com.sedmelluq.discord.lavaplayer.container.MediaContainerHints in project lavaplayer by sedmelluq.

the class HttpAudioSourceManager method detectContainerWithClient.

private MediaContainerDetectionResult detectContainerWithClient(HttpInterface httpInterface, AudioReference reference) throws IOException {
    try (PersistentHttpStream inputStream = new PersistentHttpStream(httpInterface, new URI(reference.identifier), Long.MAX_VALUE)) {
        int statusCode = inputStream.checkStatusCode();
        String redirectUrl = HttpClientTools.getRedirectLocation(reference.identifier, inputStream.getCurrentResponse());
        if (redirectUrl != null) {
            return new MediaContainerDetectionResult(null, new AudioReference(redirectUrl, null));
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        } else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
            throw new FriendlyException("That URL is not playable.", COMMON, new IllegalStateException("Status code " + statusCode));
        }
        MediaContainerHints hints = MediaContainerHints.from(getHeaderValue(inputStream.getCurrentResponse(), "Content-Type"), null);
        return MediaContainerDetection.detectContainer(reference, inputStream, hints);
    } catch (URISyntaxException e) {
        throw new FriendlyException("Not a valid URL.", COMMON, e);
    }
}
Also used : MediaContainerHints(com.sedmelluq.discord.lavaplayer.container.MediaContainerHints) MediaContainerDetectionResult(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult) URISyntaxException(java.net.URISyntaxException) PersistentHttpStream(com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream) AudioReference(com.sedmelluq.discord.lavaplayer.track.AudioReference) URI(java.net.URI) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 2 with MediaContainerHints

use of com.sedmelluq.discord.lavaplayer.container.MediaContainerHints in project SkyBot by duncte123.

the class ClypitAudioSourceManager method detectContainerWithClient.

private MediaContainerDetectionResult detectContainerWithClient(HttpInterface httpInterface, AudioReference reference) throws IOException {
    try (PersistentHttpStream inputStream = new PersistentHttpStream(httpInterface, new URI(reference.identifier), Long.MAX_VALUE)) {
        int statusCode = inputStream.checkStatusCode();
        String redirectUrl = HttpClientTools.getRedirectLocation(reference.identifier, inputStream.getCurrentResponse());
        if (redirectUrl != null) {
            return new MediaContainerDetectionResult(null, new AudioReference(redirectUrl, null));
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        } else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
            throw new FriendlyException("That URL is not playable.", COMMON, new IllegalStateException("Status code " + statusCode));
        }
        MediaContainerHints hints = MediaContainerHints.from(getHeaderValue(inputStream.getCurrentResponse(), "Content-Type"), null);
        return MediaContainerDetection.detectContainer(reference, inputStream, hints);
    } catch (URISyntaxException e) {
        throw new FriendlyException("Not a valid URL.", COMMON, e);
    }
}
Also used : MediaContainerHints(com.sedmelluq.discord.lavaplayer.container.MediaContainerHints) MediaContainerDetectionResult(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult) URISyntaxException(java.net.URISyntaxException) PersistentHttpStream(com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream) AudioReference(com.sedmelluq.discord.lavaplayer.track.AudioReference) URI(java.net.URI) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 3 with MediaContainerHints

use of com.sedmelluq.discord.lavaplayer.container.MediaContainerHints in project FredBoat by Frederikam.

the class HttpSourceManager method detectContainerWithClient.

private MediaContainerDetectionResult detectContainerWithClient(HttpInterface httpInterface, AudioReference reference, boolean ignoreHtml) throws IOException {
    try (PersistentHttpStream inputStream = new PersistentHttpStream(httpInterface, new URI(reference.identifier), Long.MAX_VALUE)) {
        int statusCode = inputStream.checkStatusCode();
        String redirectUrl = HttpClientTools.getRedirectLocation(reference.identifier, inputStream.getCurrentResponse());
        if (redirectUrl != null) {
            return new MediaContainerDetectionResult(null, new AudioReference(redirectUrl, null));
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        } else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
            throw new FriendlyException("That URL is not playable.", COMMON, new IllegalStateException("Status code " + statusCode));
        }
        MediaContainerHints hints = MediaContainerHints.from(getHeaderValue(inputStream.getCurrentResponse(), "Content-Type"), null);
        /* START CUSTOM CHANGES */
        MediaContainerDetectionResult detection = MediaContainerDetection.detectContainer(reference, inputStream, hints);
        if (!ignoreHtml && !detection.isReference() && !detection.isContainerDetected() && hints.mimeType.startsWith("text/html")) {
            return checkHtmlResponse(reference, inputStream, hints);
        }
        return detection;
    /* END CUSTOM CHANGES */
    } catch (URISyntaxException e) {
        throw new FriendlyException("Not a valid URL.", COMMON, e);
    }
}
Also used : MediaContainerHints(com.sedmelluq.discord.lavaplayer.container.MediaContainerHints) MediaContainerDetectionResult(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult) URISyntaxException(java.net.URISyntaxException) PersistentHttpStream(com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream) AudioReference(com.sedmelluq.discord.lavaplayer.track.AudioReference) URI(java.net.URI) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

MediaContainerDetectionResult (com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult)3 MediaContainerHints (com.sedmelluq.discord.lavaplayer.container.MediaContainerHints)3 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)3 PersistentHttpStream (com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream)3 AudioReference (com.sedmelluq.discord.lavaplayer.track.AudioReference)3 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3