Search in sources :

Example 31 with JsonBrowser

use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.

the class StreamingDataFormatsExtractor method extract.

@Override
public List<YoutubeTrackFormat> extract(YoutubeTrackJsonData data) {
    JsonBrowser streamingData = data.playerResponse.get("streamingData");
    if (streamingData.isNull()) {
        return Collections.emptyList();
    }
    boolean isLive = data.playerResponse.get("videoDetails").get("isLive").asBoolean(false);
    List<YoutubeTrackFormat> formats = loadTrackFormatsFromStreamingData(streamingData.get("formats"), isLive);
    formats.addAll(loadTrackFormatsFromStreamingData(streamingData.get("adaptiveFormats"), isLive));
    return formats;
}
Also used : YoutubeTrackFormat(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackFormat) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)

Example 32 with JsonBrowser

use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.

the class StreamingDataFormatsExtractor method loadTrackFormatsFromStreamingData.

private List<YoutubeTrackFormat> loadTrackFormatsFromStreamingData(JsonBrowser formats, boolean isLive) {
    List<YoutubeTrackFormat> tracks = new ArrayList<>();
    boolean anyFailures = false;
    if (!formats.isNull() && formats.isList()) {
        for (JsonBrowser formatJson : formats.values()) {
            String cipher = formatJson.get("cipher").text();
            if (cipher == null) {
                cipher = formatJson.get("signatureCipher").text();
            }
            Map<String, String> cipherInfo = cipher != null ? decodeUrlEncodedItems(cipher, true) : Collections.emptyMap();
            try {
                long contentLength = formatJson.get("contentLength").asLong(CONTENT_LENGTH_UNKNOWN);
                if (contentLength == CONTENT_LENGTH_UNKNOWN && !isLive) {
                    log.debug("Track not a live stream, but no contentLength in format {}, skipping", formatJson.format());
                    continue;
                }
                tracks.add(new YoutubeTrackFormat(ContentType.parse(formatJson.get("mimeType").text()), formatJson.get("bitrate").asLong(Units.BITRATE_UNKNOWN), contentLength, cipherInfo.getOrDefault("url", formatJson.get("url").text()), cipherInfo.get("s"), cipherInfo.getOrDefault("sp", DEFAULT_SIGNATURE_KEY)));
            } catch (RuntimeException e) {
                anyFailures = true;
                log.debug("Failed to parse format {}, skipping", formatJson, e);
            }
        }
    }
    if (tracks.isEmpty() && anyFailures) {
        log.warn("In streamingData adaptive formats {}, all formats either failed to load or were skipped due to missing " + "fields", formats.format());
    }
    return tracks;
}
Also used : ArrayList(java.util.ArrayList) YoutubeTrackFormat(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackFormat) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)

Example 33 with JsonBrowser

use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.

the class BandcampAudioTrack method getTrackMediaUrl.

private String getTrackMediaUrl(HttpInterface httpInterface) throws IOException {
    try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(trackInfo.identifier))) {
        HttpClientTools.assertSuccessWithContent(response, "track page");
        String responseText = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
        JsonBrowser trackInfo = sourceManager.readTrackListInformation(responseText);
        return trackInfo.get("trackinfo").index(0).get("file").get("mp3-128").text();
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)

Example 34 with JsonBrowser

use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.

the class BandcampAudioSourceManager method loadAlbum.

private AudioItem loadAlbum(UrlInfo urlInfo) {
    return extractFromPage(urlInfo.fullUrl, (httpClient, text) -> {
        JsonBrowser trackListInfo = readTrackListInformation(text);
        String artist = trackListInfo.get("artist").text();
        List<AudioTrack> tracks = new ArrayList<>();
        for (JsonBrowser trackInfo : trackListInfo.get("trackinfo").values()) {
            tracks.add(extractTrack(trackInfo, urlInfo.baseUrl, artist));
        }
        JsonBrowser albumInfo = readAlbumInformation(text);
        return new BasicAudioPlaylist(albumInfo.get("current").get("title").text(), tracks, null, false);
    });
}
Also used : BasicAudioPlaylist(com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)

Example 35 with JsonBrowser

use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.

the class VimeoAudioTrack method loadPlaybackUrl.

private String loadPlaybackUrl(HttpInterface httpInterface) throws IOException {
    JsonBrowser config = loadPlayerConfig(httpInterface);
    if (config == null) {
        throw new FriendlyException("Track information not present on the page.", SUSPICIOUS, null);
    }
    String trackConfigUrl = config.get("player").get("config_url").text();
    JsonBrowser trackConfig = loadTrackConfig(httpInterface, trackConfigUrl);
    return trackConfig.get("request").get("files").get("progressive").index(0).get("url").text();
}
Also used : JsonBrowser(com.sedmelluq.discord.lavaplayer.tools.JsonBrowser) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)41 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)14 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)9 HttpGet (org.apache.http.client.methods.HttpGet)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)7 BasicAudioPlaylist (com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist)6 HttpInterface (com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface)4 YoutubeTrackFormat (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackFormat)2 URISyntaxException (java.net.URISyntaxException)2 Matcher (java.util.regex.Matcher)2 NameValuePair (org.apache.http.NameValuePair)2 HttpPost (org.apache.http.client.methods.HttpPost)2 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)2 StringEntity (org.apache.http.entity.StringEntity)2 PBJ_PARAMETER (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeHttpContextFilter.PBJ_PARAMETER)1 YoutubeTrackJsonData.fromEmbedParts (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackJsonData.fromEmbedParts)1 DataFormatTools (com.sedmelluq.discord.lavaplayer.tools.DataFormatTools)1