Search in sources :

Example 16 with HttpInterface

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

the class SoundCloudClientIdTracker method findClientIdFromSite.

private String findClientIdFromSite() throws IOException {
    try (HttpInterface httpInterface = httpInterfaceManager.getInterface()) {
        httpInterface.getContext().setAttribute(ID_FETCH_CONTEXT_ATTRIBUTE, true);
        List<String> scriptUrls = findScriptUrls(httpInterface);
        return findClientIdFromScripts(httpInterface, scriptUrls);
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface)

Example 17 with HttpInterface

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

the class NicoAudioSourceManager method loadTrack.

private AudioTrack loadTrack(String videoId) {
    checkLoggedIn();
    try (HttpInterface httpInterface = getHttpInterface()) {
        try (CloseableHttpResponse response = httpInterface.execute(new HttpGet("http://ext.nicovideo.jp/api/getthumbinfo/" + videoId))) {
            int statusCode = response.getStatusLine().getStatusCode();
            if (!HttpClientTools.isSuccessWithContent(statusCode)) {
                throw new IOException("Unexpected response code from video info: " + statusCode);
            }
            Document document = Jsoup.parse(response.getEntity().getContent(), StandardCharsets.UTF_8.name(), "", Parser.xmlParser());
            return extractTrackFromXml(videoId, document);
        }
    } catch (IOException e) {
        throw new FriendlyException("Error occurred when extracting video info.", SUSPICIOUS, 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) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 18 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.
 */
@Override
public AudioItem loadSearchResult(String query, Function<AudioTrackInfo, AudioTrack> trackFactory) {
    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).addParameter("hl", "en").addParameter("persist_hl", "1").build();
        try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(url))) {
            HttpClientTools.assertSuccessWithContent(response, "search response");
            Document document = Jsoup.parse(response.getEntity().getContent(), StandardCharsets.UTF_8.name(), "");
            return extractSearchResults(document, query, trackFactory);
        }
    } 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) Document(org.jsoup.nodes.Document) URI(java.net.URI) IOException(java.io.IOException) URIBuilder(org.apache.http.client.utils.URIBuilder)

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