Search in sources :

Example 1 with AudioReference

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.");
}
Also used : MediaContainerDetectionResult(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) AudioReference(com.sedmelluq.discord.lavaplayer.track.AudioReference) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AudioReference

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);
    }
}
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 3 with AudioReference

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;
}
Also used : AudioReference(com.sedmelluq.discord.lavaplayer.track.AudioReference) AudioItem(com.sedmelluq.discord.lavaplayer.track.AudioItem)

Example 4 with AudioReference

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

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;
}
Also used : JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) AudioReference(com.sedmelluq.discord.lavaplayer.track.AudioReference) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

AudioReference (com.sedmelluq.discord.lavaplayer.track.AudioReference)7 MediaContainerDetectionResult (com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult)4 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)4 URISyntaxException (java.net.URISyntaxException)4 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 AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)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