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);
}
}
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);
}
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.");
}
Aggregations