Search in sources :

Example 11 with HttpInterface

use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.

the class SoundCloudAudioTrack method process.

@Override
public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
    try (HttpInterface httpInterface = sourceManager.getHttpInterface()) {
        if (!attemptLoadStream(localExecutor, httpInterface, true)) {
            sourceManager.updateClientId();
            attemptLoadStream(localExecutor, httpInterface, false);
        }
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface)

Example 12 with HttpInterface

use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.

the class YoutubeSearchProvider method loadSearchResult.

/**
 * @param query Search query.
 * @return Playlist of the first page of results.
 */
public AudioItem loadSearchResult(String query) {
    log.debug("Performing a search with query {}", query);
    try (HttpInterface httpInterface = httpInterfaceManager.getInterface()) {
        URI url = new URIBuilder("https://www.youtube.com/results").addParameter("search_query", query).build();
        try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(url))) {
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode != 200) {
                throw new IOException("Invalid status code for search response: " + statusCode);
            }
            Document document = Jsoup.parse(response.getEntity().getContent(), StandardCharsets.UTF_8.name(), "");
            return extractSearchResults(document, query);
        }
    } catch (Exception e) {
        throw ExceptionTools.wrapUnfriendlyExceptions(e);
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) URI(java.net.URI) IOException(java.io.IOException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 13 with HttpInterface

use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.

the class NicoAudioTrack method process.

@Override
public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
    sourceManager.checkLoggedIn();
    try (HttpInterface httpInterface = sourceManager.getHttpInterface()) {
        loadVideoMainPage(httpInterface);
        String playbackUrl = loadPlaybackUrl(httpInterface);
        log.debug("Starting NicoNico track from URL: {}", playbackUrl);
        try (PersistentHttpStream stream = new PersistentHttpStream(httpInterface, new URI(playbackUrl), null)) {
            processDelegate(new MpegAudioTrack(trackInfo, stream), localExecutor);
        }
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) MpegAudioTrack(com.sedmelluq.discord.lavaplayer.container.mpeg.MpegAudioTrack) PersistentHttpStream(com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream) URI(java.net.URI)

Example 14 with HttpInterface

use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.

the class DefaultSoundCloudPlaylistLoader method loadFromSet.

protected AudioPlaylist loadFromSet(HttpInterfaceManager httpInterfaceManager, String playlistWebUrl, Function<AudioTrackInfo, AudioTrack> trackFactory) {
    try (HttpInterface httpInterface = httpInterfaceManager.getInterface()) {
        JsonBrowser rootData = htmlDataLoader.load(httpInterface, playlistWebUrl);
        JsonBrowser playlistData = dataReader.findPlaylistData(rootData);
        return new BasicAudioPlaylist(dataReader.readPlaylistName(playlistData), loadPlaylistTracks(httpInterface, playlistData, trackFactory), null, false);
    } catch (IOException e) {
        throw new FriendlyException("Loading playlist from SoundCloud failed.", SUSPICIOUS, e);
    }
}
Also used : BasicAudioPlaylist(com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist) HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) IOException(java.io.IOException) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 15 with HttpInterface

use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.

the class SoundCloudAudioSourceManager method loadFromTrackPage.

public AudioTrack loadFromTrackPage(String trackWebUrl) {
    try (HttpInterface httpInterface = getHttpInterface()) {
        JsonBrowser rootData = htmlDataLoader.load(httpInterface, trackWebUrl);
        JsonBrowser trackData = dataReader.findTrackData(rootData);
        if (trackData == null) {
            throw new FriendlyException("This track is not available", COMMON, null);
        }
        return loadFromTrackData(trackData);
    } catch (IOException e) {
        throw new FriendlyException("Loading track from SoundCloud failed.", SUSPICIOUS, e);
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) IOException(java.io.IOException) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

HttpInterface (com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface)18 IOException (java.io.IOException)11 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)7 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 URI (java.net.URI)6 Document (org.jsoup.nodes.Document)6 HttpGet (org.apache.http.client.methods.HttpGet)5 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)3 PersistentHttpStream (com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream)3 URIBuilder (org.apache.http.client.utils.URIBuilder)3 MpegAudioTrack (com.sedmelluq.discord.lavaplayer.container.mpeg.MpegAudioTrack)2 URISyntaxException (java.net.URISyntaxException)2 HttpPost (org.apache.http.client.methods.HttpPost)2 AdtsAudioTrack (com.sedmelluq.discord.lavaplayer.container.adts.AdtsAudioTrack)1 Mp3AudioTrack (com.sedmelluq.discord.lavaplayer.container.mp3.Mp3AudioTrack)1 MpegTsElementaryInputStream (com.sedmelluq.discord.lavaplayer.container.mpegts.MpegTsElementaryInputStream)1 PesPacketInputStream (com.sedmelluq.discord.lavaplayer.container.mpegts.PesPacketInputStream)1 RingBufferMath (com.sedmelluq.discord.lavaplayer.tools.RingBufferMath)1 ChainedInputStream (com.sedmelluq.discord.lavaplayer.tools.io.ChainedInputStream)1 BasicAudioPlaylist (com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist)1