Search in sources :

Example 26 with FriendlyException

use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.

the class RemoteNodeProcessor method handleTrackStartResponse.

private void handleTrackStartResponse(TrackStartResponseMessage message) {
    if (message.success) {
        log.debug("Successful start confirmation from node {} for executor {}.", nodeAddress, message.executorId);
    } else {
        RemoteAudioTrackExecutor executor = playingTracks.get(message.executorId);
        if (executor != null) {
            executor.dispatchException(new FriendlyException("Remote machine failed to start track: " + message.failureReason, SUSPICIOUS, null));
            executor.stop();
        } else {
            log.debug("Received failed track start for an already stopped executor {} from node {}.", message.executorId, nodeAddress);
        }
    }
}
Also used : FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 27 with FriendlyException

use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException 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);
    }
}
Also used : MediaContainerHints(com.sedmelluq.discord.lavaplayer.container.MediaContainerHints) MediaContainerDetection(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetection) 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 28 with FriendlyException

use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException 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);
    }
}
Also used : MediaContainerDetection(com.sedmelluq.discord.lavaplayer.container.MediaContainerDetection) IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 29 with FriendlyException

use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.

the class AbandonedTrackManager method add.

/**
 * Adds a track executor to abandoned tracks. The abandoned track manager will take over managing its lifecycle and
 * the caller should not use it any further.
 *
 * @param executor The executor to register as an abandoned track.
 */
public void add(RemoteAudioTrackExecutor executor) {
    if (abandonedExecutors.offer(new AbandonedExecutor(System.currentTimeMillis(), executor))) {
        log.debug("{} has been put up for adoption.", executor);
    } else {
        log.debug("{} has been discarded, adoption queue is full.", executor);
        executor.dispatchException(new FriendlyException("Cannot find a node to play the track on.", COMMON, null));
        executor.stop();
    }
}
Also used : FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 30 with FriendlyException

use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.

the class AbandonedTrackManager method shutdown.

/**
 * Shut down the abandoned track manager, stopping any tracks.
 */
public void shutdown() {
    AbandonedExecutor executor;
    while ((executor = abandonedExecutors.poll()) != null) {
        executor.executor.dispatchException(new FriendlyException("Node system was shut down.", COMMON, null));
        executor.executor.stop();
    }
}
Also used : FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)62 IOException (java.io.IOException)23 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)18 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)13 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)12 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)12 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)12 ArrayList (java.util.ArrayList)10 HttpGet (org.apache.http.client.methods.HttpGet)10 List (java.util.List)7 HttpInterface (com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface)6 BasicAudioPlaylist (com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 MediaContainerHints (com.sedmelluq.discord.lavaplayer.container.MediaContainerHints)3 PersistentHttpStream (com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream)3 AudioReference (com.sedmelluq.discord.lavaplayer.track.AudioReference)3 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)3 Document (org.jsoup.nodes.Document)3 Track (com.arsenarsen.lavaplayerbridge.player.Track)2