Search in sources :

Example 1 with PersistentHttpStream

use of com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream in project lavaplayer by sedmelluq.

the class SoundCloudAudioTrack method attemptLoadStream.

private boolean attemptLoadStream(LocalAudioTrackExecutor localExecutor, HttpInterface httpInterface, boolean checkUnauthorized) throws Exception {
    String trackUrl = sourceManager.getTrackUrlFromId(trackInfo.identifier);
    log.debug("Starting SoundCloud track from URL: {}", trackUrl);
    try (PersistentHttpStream stream = new PersistentHttpStream(httpInterface, new URI(trackUrl), null)) {
        if (checkUnauthorized) {
            int statusCode = stream.checkStatusCode();
            if (statusCode == 401) {
                return false;
            } else if (statusCode < 200 && statusCode >= 300) {
                throw new IOException("Invalid status code for soundcloud stream: " + statusCode);
            }
        }
        processDelegate(new Mp3AudioTrack(trackInfo, stream), localExecutor);
    }
    return true;
}
Also used : Mp3AudioTrack(com.sedmelluq.discord.lavaplayer.container.mp3.Mp3AudioTrack) IOException(java.io.IOException) PersistentHttpStream(com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream) URI(java.net.URI)

Example 2 with PersistentHttpStream

use of com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream in project lavaplayer by sedmelluq.

the class VimeoAudioTrack method process.

@Override
public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
    try (HttpInterface httpInterface = sourceManager.getHttpInterface()) {
        String playbackUrl = loadPlaybackUrl(httpInterface);
        log.debug("Starting Vimeo track from URL: {}", playbackUrl);
        try (PersistentHttpStream stream = new PersistentHttpStream(httpInterface, new URI(playbackUrl), null)) {
            processDelegate(new MpegAudioTrack(trackInfo, stream), localExecutor);
        }
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) MpegAudioTrack(com.sedmelluq.discord.lavaplayer.container.mpeg.MpegAudioTrack) PersistentHttpStream(com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream) URI(java.net.URI)

Example 3 with PersistentHttpStream

use of com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream in project lavaplayer by sedmelluq.

the class BandcampAudioTrack method process.

@Override
public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
    try (HttpInterface httpInterface = sourceManager.getHttpInterface()) {
        log.debug("Loading Bandcamp track page from URL: {}", trackInfo.identifier);
        String trackMediaUrl = getTrackMediaUrl(httpInterface);
        log.debug("Starting Bandcamp track from URL: {}", trackMediaUrl);
        try (PersistentHttpStream stream = new PersistentHttpStream(httpInterface, new URI(trackMediaUrl), null)) {
            processDelegate(new Mp3AudioTrack(trackInfo, stream), localExecutor);
        }
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) Mp3AudioTrack(com.sedmelluq.discord.lavaplayer.container.mp3.Mp3AudioTrack) PersistentHttpStream(com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream) URI(java.net.URI)

Example 4 with PersistentHttpStream

use of com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream 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 5 with PersistentHttpStream

use of com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream 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)

Aggregations

PersistentHttpStream (com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream)7 URI (java.net.URI)7 MediaContainerDetectionResult (com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult)3 MediaContainerHints (com.sedmelluq.discord.lavaplayer.container.MediaContainerHints)3 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)3 HttpInterface (com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface)3 AudioReference (com.sedmelluq.discord.lavaplayer.track.AudioReference)3 URISyntaxException (java.net.URISyntaxException)3 Mp3AudioTrack (com.sedmelluq.discord.lavaplayer.container.mp3.Mp3AudioTrack)2 MpegAudioTrack (com.sedmelluq.discord.lavaplayer.container.mpeg.MpegAudioTrack)2 IOException (java.io.IOException)1