Search in sources :

Example 6 with AudioReference

use of com.sedmelluq.discord.lavaplayer.track.AudioReference 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)

Example 7 with AudioReference

use of com.sedmelluq.discord.lavaplayer.track.AudioReference in project lavaplayer by sedmelluq.

the class BandcampAudioSourceManager method extractFromPageWithInterface.

private AudioItem extractFromPageWithInterface(HttpInterface httpInterface, String url, AudioItemExtractor extractor) throws Exception {
    String responseText;
    try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(url))) {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return new AudioReference(null, null);
        } else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
            throw new IOException("Invalid status code for track page: " + statusCode);
        }
        responseText = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
    }
    return extractor.extract(httpInterface, responseText);
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) AudioReference(com.sedmelluq.discord.lavaplayer.track.AudioReference)

Example 8 with AudioReference

use of com.sedmelluq.discord.lavaplayer.track.AudioReference in project lavaplayer by sedmelluq.

the class M3uPlaylistContainerProbe method probe.

@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
    if (!checkNextBytes(inputStream, M3U_HEADER_TAG) && !checkNextBytes(inputStream, M3U_ENTRY_TAG)) {
        return null;
    }
    log.debug("Track {} is an M3U playlist file.", reference.identifier);
    String[] lines = DataFormatTools.streamToLines(inputStream, StandardCharsets.UTF_8);
    String hlsStreamUrl = HlsStreamSegmentUrlProvider.findHlsEntryUrl(lines);
    if (hlsStreamUrl != null) {
        AudioTrackInfoBuilder infoBuilder = AudioTrackInfoBuilder.create(reference, inputStream);
        AudioReference httpReference = HttpAudioSourceManager.getAsHttpReference(reference);
        if (httpReference != null) {
            return supportedFormat(this, TYPE_HLS_OUTER, infoBuilder.setIdentifier(httpReference.identifier).build());
        } else {
            return refer(this, new AudioReference(hlsStreamUrl, infoBuilder.getTitle(), new MediaContainerDescriptor(this, TYPE_HLS_INNER)));
        }
    }
    MediaContainerDetectionResult result = loadSingleItemPlaylist(lines);
    if (result != null) {
        return result;
    }
    return unsupportedFormat(this, "The playlist file contains no links.");
}
Also used : AudioTrackInfoBuilder(com.sedmelluq.discord.lavaplayer.track.info.AudioTrackInfoBuilder) MediaContainerDetectionResult(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult) AudioReference(com.sedmelluq.discord.lavaplayer.track.AudioReference) MediaContainerDescriptor(com.sedmelluq.discord.lavaplayer.container.MediaContainerDescriptor)

Aggregations

AudioReference (com.sedmelluq.discord.lavaplayer.track.AudioReference)8 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)4 URISyntaxException (java.net.URISyntaxException)4 MediaContainerDetectionResult (com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult)3 MediaContainerHints (com.sedmelluq.discord.lavaplayer.container.MediaContainerHints)3 PersistentHttpStream (com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream)3 URI (java.net.URI)3 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 MediaContainerDescriptor (com.sedmelluq.discord.lavaplayer.container.MediaContainerDescriptor)1 MediaContainerDetection (com.sedmelluq.discord.lavaplayer.container.MediaContainerDetection)1 AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)1 AudioTrackInfoBuilder (com.sedmelluq.discord.lavaplayer.track.info.AudioTrackInfoBuilder)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 JSONObject (org.json.JSONObject)1