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);
}
}
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);
}
}
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);
}
}
Aggregations