use of com.sedmelluq.discord.lavaplayer.track.AudioReference in project lavaplayer by sedmelluq.
the class PlsPlaylistContainerProbe method loadFromLines.
private MediaContainerDetectionResult loadFromLines(String[] lines) {
Map<String, String> trackFiles = new HashMap<>();
Map<String, String> trackTitles = new HashMap<>();
for (String line : lines) {
Matcher fileMatcher = filePattern.matcher(line);
if (fileMatcher.matches()) {
trackFiles.put(fileMatcher.group(1), fileMatcher.group(2));
continue;
}
Matcher titleMatcher = titlePattern.matcher(line);
if (titleMatcher.matches()) {
trackTitles.put(titleMatcher.group(1), titleMatcher.group(2));
}
}
for (Map.Entry<String, String> entry : trackFiles.entrySet()) {
String title = trackTitles.get(entry.getKey());
return new MediaContainerDetectionResult(this, new AudioReference(entry.getValue(), title != null ? title : UNKNOWN_TITLE));
}
return new MediaContainerDetectionResult(this, "The playlist file contains no links.");
}
use of com.sedmelluq.discord.lavaplayer.track.AudioReference 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);
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioReference in project lavaplayer by sedmelluq.
the class DefaultAudioPlayerManager method checkSourcesForItem.
private boolean checkSourcesForItem(AudioReference reference, AudioLoadResultHandler resultHandler, boolean[] reported) {
AudioReference currentReference = reference;
for (int redirects = 0; redirects < MAXIMUM_LOAD_REDIRECTS && currentReference.identifier != null; redirects++) {
AudioItem item = checkSourcesForItemOnce(currentReference, resultHandler, reported);
if (item == null) {
return false;
} else if (!(item instanceof AudioReference)) {
return true;
}
currentReference = (AudioReference) item;
}
return false;
}
use of com.sedmelluq.discord.lavaplayer.track.AudioReference 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);
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioReference in project SkyBot by duncte123.
the class ClypitAudioSourceManager method loadItem.
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
Matcher m = CLYPIT_REGEX.matcher(reference.identifier);
if (m.matches()) {
try {
String clypitId = m.group(m.groupCount());
JSONObject json = WebUtils.ins.getJSONObject("https://api.clyp.it/" + clypitId).execute();
AudioReference httpReference = getAsHttpReference(new AudioReference(json.getString("Mp3Url"), json.getString("Title")));
return handleLoadResult(detectContainer(httpReference));
} catch (Exception e) {
return null;
}
}
return null;
}
Aggregations