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