Search in sources :

Example 6 with HttpInterface

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);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) Header(org.apache.http.Header) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 7 with HttpInterface

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);
        }
    }
}
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 8 with HttpInterface

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);
        }
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) RingBufferMath(com.sedmelluq.discord.lavaplayer.tools.RingBufferMath) IOException(java.io.IOException)

Example 9 with HttpInterface

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);
        }
    }
}
Also used : HttpInterface(com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface) Mp3AudioTrack(com.sedmelluq.discord.lavaplayer.container.mp3.Mp3AudioTrack) PersistentHttpStream(com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream) URI(java.net.URI)

Example 10 with HttpInterface

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);
    }
}
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) URISyntaxException(java.net.URISyntaxException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) IOException(java.io.IOException)

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