Search in sources :

Example 46 with FriendlyException

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

the class MusicManager method loadAndPlay.

/**
 * Load a song
 * @param channel The channel to send the alert in.
 * @param trackUrl The song URL
 * @param voiceChannel the voice channel to play the music in.
 */
public void loadAndPlay(final TextChannel channel, final String trackUrl, VoiceChannel voiceChannel) {
    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, voiceChannel);
        }

        @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, voiceChannel);
        }

        @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 47 with FriendlyException

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

the class YoutubeMpegStreamAudioTrack method processSegmentStream.

private void processSegmentStream(SeekableInputStream stream, AudioProcessingContext context, TrackState state) throws InterruptedException {
    MpegFileLoader file = new MpegFileLoader(stream);
    file.parseHeaders();
    state.absoluteSequence = extractAbsoluteSequenceFromEvent(file.getLastEventMessage());
    if (state.trackConsumer == null) {
        state.trackConsumer = loadAudioTrack(file, context);
    }
    MpegFileTrackProvider fileReader = file.loadReader(state.trackConsumer);
    if (fileReader == null) {
        throw new FriendlyException("Unknown MP4 format.", SUSPICIOUS, null);
    }
    fileReader.provideFrames();
}
Also used : MpegFileLoader(com.sedmelluq.discord.lavaplayer.container.mpeg.MpegFileLoader) MpegFileTrackProvider(com.sedmelluq.discord.lavaplayer.container.mpeg.reader.MpegFileTrackProvider) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 48 with FriendlyException

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

the class GetyarnAudioSourceManager method extractVideoUrlFromPage.

private AudioTrack extractVideoUrlFromPage(AudioReference reference) {
    try (final CloseableHttpResponse response = getHttpInterface().execute(new HttpGet(reference.identifier))) {
        final String html = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
        final Document document = Jsoup.parse(html);
        final AudioTrackInfo trackInfo = AudioTrackInfoBuilder.empty().setUri(reference.identifier).setAuthor("Unknown").setIsStream(false).setIdentifier(document.selectFirst("meta[property=og:video:secure_url]").attr("content")).setTitle(document.selectFirst("meta[property=og:title]").attr("content")).build();
        return createTrack(trackInfo);
    } catch (IOException e) {
        throw new FriendlyException("Failed to load info for yarn clip", SUSPICIOUS, null);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 49 with FriendlyException

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

the class M3uStreamSegmentUrlProvider method getNextSegmentUrl.

/**
 * Logic for getting the URL for the next segment.
 *
 * @param httpInterface HTTP interface to use for any requests required to perform to find the segment URL.
 * @return The direct stream URL of the next segment.
 */
protected String getNextSegmentUrl(HttpInterface httpInterface) {
    try {
        String streamSegmentPlaylistUrl = fetchSegmentPlaylistUrl(httpInterface);
        if (streamSegmentPlaylistUrl == null) {
            return null;
        }
        long startTime = System.currentTimeMillis();
        SegmentInfo nextSegment;
        while (true) {
            List<SegmentInfo> segments = loadStreamSegmentsList(httpInterface, streamSegmentPlaylistUrl);
            nextSegment = chooseNextSegment(segments, lastSegment);
            if (nextSegment != null || !shouldWaitForSegment(startTime, segments)) {
                break;
            }
            Thread.sleep(SEGMENT_WAIT_STEP_MS);
        }
        if (nextSegment == null) {
            return null;
        }
        lastSegment = nextSegment;
        return createSegmentUrl(streamSegmentPlaylistUrl, lastSegment.url);
    } catch (IOException e) {
        throw new FriendlyException("Failed to get next part of the stream.", SUSPICIOUS, e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 50 with FriendlyException

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

the class VimeoAudioTrack method loadPlaybackUrl.

private String loadPlaybackUrl(HttpInterface httpInterface) throws IOException {
    JsonBrowser config = loadPlayerConfig(httpInterface);
    if (config == null) {
        throw new FriendlyException("Track information not present on the page.", SUSPICIOUS, null);
    }
    String trackConfigUrl = config.get("player").get("config_url").text();
    JsonBrowser trackConfig = loadTrackConfig(httpInterface, trackConfigUrl);
    return trackConfig.get("request").get("files").get("progressive").index(0).get("url").text();
}
Also used : JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser) 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