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