Search in sources :

Example 1 with FriendlyException

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

the class Main method loadAndPlay.

private void loadAndPlay(final IChannel channel, final String trackUrl) {
    GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
    playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {

        @Override
        public void trackLoaded(AudioTrack track) {
            sendMessageToChannel(channel, "Adding to queue " + track.getInfo().title);
            play(channel.getGuild(), musicManager, track);
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist) {
            AudioTrack firstTrack = playlist.getSelectedTrack();
            if (firstTrack == null) {
                firstTrack = playlist.getTracks().get(0);
            }
            sendMessageToChannel(channel, "Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")");
            play(channel.getGuild(), musicManager, firstTrack);
        }

        @Override
        public void noMatches() {
            sendMessageToChannel(channel, "Nothing found by " + trackUrl);
        }

        @Override
        public void loadFailed(FriendlyException exception) {
            sendMessageToChannel(channel, "Could not play: " + exception.getMessage());
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 2 with FriendlyException

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

the class Main method loadAndPlay.

private void loadAndPlay(final TextChannel channel, final String trackUrl) {
    GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
    playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {

        @Override
        public void trackLoaded(AudioTrack track) {
            channel.sendMessage("Adding to queue " + track.getInfo().title).queue();
            play(channel.getGuild(), musicManager, track);
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist) {
            AudioTrack firstTrack = playlist.getSelectedTrack();
            if (firstTrack == null) {
                firstTrack = playlist.getTracks().get(0);
            }
            channel.sendMessage("Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")").queue();
            play(channel.getGuild(), musicManager, firstTrack);
        }

        @Override
        public void noMatches() {
            channel.sendMessage("Nothing found by " + trackUrl).queue();
        }

        @Override
        public void loadFailed(FriendlyException exception) {
            channel.sendMessage("Could not play: " + exception.getMessage()).queue();
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 3 with FriendlyException

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

the class NicoAudioSourceManager method checkLoggedIn.

void checkLoggedIn() {
    synchronized (loggedIn) {
        if (loggedIn.get()) {
            return;
        }
        HttpPost loginRequest = new HttpPost("https://secure.nicovideo.jp/secure/login");
        loginRequest.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("mail", email), new BasicNameValuePair("password", password)), StandardCharsets.UTF_8));
        try (HttpInterface httpInterface = getHttpInterface()) {
            try (CloseableHttpResponse response = httpInterface.execute(loginRequest)) {
                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode != 302) {
                    throw new IOException("Unexpected response code " + statusCode);
                }
                Header location = response.getFirstHeader("Location");
                if (location == null || location.getValue().contains("message=")) {
                    throw new FriendlyException("Login details for NicoNico are invalid.", COMMON, null);
                }
                loggedIn.set(true);
            }
        } catch (IOException e) {
            throw new FriendlyException("Exception when trying to log into NicoNico", SUSPICIOUS, e);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) Header(org.apache.http.Header) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 4 with FriendlyException

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

the class SoundCloudAudioSourceManager method loadPageConfigJson.

private JsonBrowser loadPageConfigJson(HttpInterface httpInterface, String url) throws IOException {
    try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(url))) {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            throw new FriendlyException("That track does not exist.", COMMON, null);
        } else if (statusCode != HttpStatus.SC_OK) {
            throw new IOException("Invalid status code for video page response: " + statusCode);
        }
        String html = IOUtils.toString(response.getEntity().getContent(), Charset.forName(CHARSET));
        String configJson = DataFormatTools.extractBetween(html, "e}var c=", ",o=Date.now()");
        if (configJson == null) {
            throw new FriendlyException("This url does not appear to be a playable track.", SUSPICIOUS, null);
        }
        return JsonBrowser.parse(configJson);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 5 with FriendlyException

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

the class TwitchStreamSegmentUrlProvider method getNextSegmentUrl.

/**
 * @param httpInterface Http interface to use for requests.
 * @return The URL of the next TS segment.
 */
@Override
public String getNextSegmentUrl(HttpInterface httpInterface) {
    try {
        if (!obtainSegmentPlaylistUrl(httpInterface)) {
            return null;
        }
        List<String> segments = loadStreamSegmentsList(httpInterface, streamSegmentPlaylistUrl);
        lastSegment = chooseNextSegment(segments, lastSegment);
        if (lastSegment == null) {
            return null;
        }
        return createSegmentUrl(streamSegmentPlaylistUrl, lastSegment);
    } catch (IOException e) {
        throw new FriendlyException("Failed to get next part of the stream.", SUSPICIOUS, e);
    }
}
Also used : IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)44 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)15 IOException (java.io.IOException)15 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)11 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)11 ArrayList (java.util.ArrayList)8 List (java.util.List)7 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 HttpGet (org.apache.http.client.methods.HttpGet)5 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)4 HttpInterface (com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface)4 URISyntaxException (java.net.URISyntaxException)4 MediaContainerDetectionResult (com.sedmelluq.discord.lavaplayer.container.MediaContainerDetectionResult)3 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 URI (java.net.URI)3 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)3 Track (com.arsenarsen.lavaplayerbridge.player.Track)2 MpegFileTrackProvider (com.sedmelluq.discord.lavaplayer.container.mpeg.reader.MpegFileTrackProvider)2