Search in sources :

Example 1 with MediaContainerDetection

use of com.sedmelluq.discord.lavaplayer.container.MediaContainerDetection 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), Units.CONTENT_LENGTH_UNKNOWN)) {
        int statusCode = inputStream.checkStatusCode();
        String redirectUrl = HttpClientTools.getRedirectLocation(reference.identifier, inputStream.getCurrentResponse());
        if (redirectUrl != null) {
            return refer(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 new MediaContainerDetection(containerRegistry, reference, inputStream, hints).detectContainer();
    } catch (URISyntaxException e) {
        throw new FriendlyException("Not a valid URL.", COMMON, e);
    }
}
Also used : MediaContainerHints(com.sedmelluq.discord.lavaplayer.container.MediaContainerHints) MediaContainerDetection(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetection) 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 MediaContainerDetection

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

the class LocalAudioSourceManager method detectContainerForFile.

private MediaContainerDetectionResult detectContainerForFile(AudioReference reference, File file) {
    try (LocalSeekableInputStream inputStream = new LocalSeekableInputStream(file)) {
        int lastDotIndex = file.getName().lastIndexOf('.');
        String fileExtension = lastDotIndex >= 0 ? file.getName().substring(lastDotIndex + 1) : null;
        return new MediaContainerDetection(containerRegistry, reference, inputStream, MediaContainerHints.from(null, fileExtension)).detectContainer();
    } catch (IOException e) {
        throw new FriendlyException("Failed to open file for reading.", SUSPICIOUS, e);
    }
}
Also used : MediaContainerDetection(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetection) IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

MediaContainerDetection (com.sedmelluq.discord.lavaplayer.container.MediaContainerDetection)2 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)2 MediaContainerHints (com.sedmelluq.discord.lavaplayer.container.MediaContainerHints)1 PersistentHttpStream (com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream)1 AudioReference (com.sedmelluq.discord.lavaplayer.track.AudioReference)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1