use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.
the class NicoAudioSourceManager method checkLoggedIn.
void checkLoggedIn() {
synchronized (loggedIn) {
if (loggedIn.get()) {
return;
}
HttpPost loginRequest = new HttpPost("https://secure.nicovideo.jp/secure/login");
loginRequest.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("mail", email), new BasicNameValuePair("password", password)), StandardCharsets.UTF_8));
try (HttpInterface httpInterface = getHttpInterface()) {
try (CloseableHttpResponse response = httpInterface.execute(loginRequest)) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 302) {
throw new IOException("Unexpected response code " + statusCode);
}
Header location = response.getFirstHeader("Location");
if (location == null || location.getValue().contains("message=")) {
throw new FriendlyException("Login details for NicoNico are invalid.", COMMON, null);
}
loggedIn.set(true);
}
} catch (IOException e) {
throw new FriendlyException("Exception when trying to log into NicoNico", SUSPICIOUS, e);
}
}
}
use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.
the class VimeoAudioTrack method process.
@Override
public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
try (HttpInterface httpInterface = sourceManager.getHttpInterface()) {
String playbackUrl = loadPlaybackUrl(httpInterface);
log.debug("Starting Vimeo 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 RemoteNodeProcessor method run.
@Override
public void run() {
if (closed || !threadRunning.compareAndSet(false, true)) {
log.debug("Not running node processor for {}, thread already active.", nodeAddress);
return;
}
log.debug("Trying to connect to node {}.", nodeAddress);
connectionState.set(ConnectionState.PENDING.id());
try (HttpInterface httpInterface = httpInterfaceManager.getInterface()) {
RingBufferMath timingAverage = new RingBufferMath(10, in -> Math.pow(in, 5.0), out -> Math.pow(out, 0.2));
while (processOneTick(httpInterface, timingAverage)) {
aliveTickCounter = Math.max(1, aliveTickCounter + 1);
lastAliveTime = System.currentTimeMillis();
}
} catch (InterruptedException e) {
log.info("Node {} processing was stopped.", nodeAddress);
Thread.currentThread().interrupt();
} catch (IOException e) {
if (aliveTickCounter > 0) {
log.error("Node {} went offline with exception.", nodeAddress, e);
} else {
log.debug("Retry, node {} is still offline.", nodeAddress);
}
} catch (Throwable e) {
log.error("Node {} appears offline due to unexpected exception.", nodeAddress, e);
ExceptionTools.rethrowErrors(e);
} finally {
processHealthCheck(true);
connectionState.set(ConnectionState.OFFLINE.id());
aliveTickCounter = Math.min(-1, aliveTickCounter - 1);
threadRunning.set(false);
if (!closed) {
long delay = getScheduleDelay();
if (aliveTickCounter == -1) {
log.info("Node {} loop ended, retry scheduled in {}.", nodeAddress, delay);
}
scheduledExecutor.schedule(this, delay, TimeUnit.MILLISECONDS);
} else {
log.info("Node {} loop ended, node was removed.", nodeAddress);
}
}
}
use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.
the class BandcampAudioTrack method process.
@Override
public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
try (HttpInterface httpInterface = sourceManager.getHttpInterface()) {
log.debug("Loading Bandcamp track page from URL: {}", trackInfo.identifier);
String trackMediaUrl = getTrackMediaUrl(httpInterface);
log.debug("Starting Bandcamp track from URL: {}", trackMediaUrl);
try (PersistentHttpStream stream = new PersistentHttpStream(httpInterface, new URI(trackMediaUrl), null)) {
processDelegate(new Mp3AudioTrack(trackInfo, stream), localExecutor);
}
}
}
use of com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface in project lavaplayer by sedmelluq.
the class YoutubeAudioSourceManager method loadPlaylistWithId.
private AudioPlaylist loadPlaylistWithId(String playlistId, String selectedVideoId) {
log.debug("Starting to load playlist with ID {}", playlistId);
try (HttpInterface httpInterface = getHttpInterface()) {
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet("https://www.youtube.com/playlist?list=" + playlistId))) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
throw new IOException("Invalid status code for playlist response: " + statusCode);
}
Document document = Jsoup.parse(response.getEntity().getContent(), CHARSET, "");
return buildPlaylist(httpInterface, document, selectedVideoId);
}
} catch (Exception e) {
throw ExceptionTools.wrapUnfriendlyExceptions(e);
}
}
Aggregations