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