use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class YoutubeAudioSourceManager method buildPlaylist.
private AudioPlaylist buildPlaylist(HttpInterface httpInterface, Document document, String selectedVideoId) throws IOException {
boolean isAccessible = !document.select("#pl-header").isEmpty();
if (!isAccessible) {
if (selectedVideoId != null) {
return null;
} else {
throw new FriendlyException("The playlist is private.", COMMON, null);
}
}
Element container = document.select("#pl-header").first().parent();
String playlistName = container.select(".pl-header-title").first().text();
List<AudioTrack> tracks = new ArrayList<>();
String loadMoreUrl = extractPlaylistTracks(container, container, tracks);
int loadCount = 0;
int pageCount = playlistPageCount;
// Also load the next pages, each result gives us a JSON with separate values for list html and next page loader html
while (loadMoreUrl != null && ++loadCount < pageCount) {
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet("https://www.youtube.com" + loadMoreUrl))) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
throw new IOException("Invalid status code for playlist response: " + statusCode);
}
JsonBrowser json = JsonBrowser.parse(response.getEntity().getContent());
String html = json.get("content_html").text();
Element videoContainer = Jsoup.parse("<table>" + html + "</table>", "");
String moreHtml = json.get("load_more_widget_html").text();
Element moreContainer = moreHtml != null ? Jsoup.parse(moreHtml) : null;
loadMoreUrl = extractPlaylistTracks(videoContainer, moreContainer, tracks);
}
}
return new BasicAudioPlaylist(playlistName, tracks, findSelectedTrack(tracks, selectedVideoId), false);
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class YoutubeAudioTrack method loadTrackFormats.
private List<YoutubeTrackFormat> loadTrackFormats(JsonBrowser info, HttpInterface httpInterface, String playerScript) throws Exception {
JsonBrowser args = info.safeGet("args");
String adaptiveFormats = args.safeGet("adaptive_fmts").text();
if (adaptiveFormats != null) {
return loadTrackFormatsFromAdaptive(adaptiveFormats);
}
String dashUrl = args.safeGet("dashmpd").text();
if (dashUrl != null) {
return loadTrackFormatsFromDash(dashUrl, httpInterface, playerScript);
}
String formatStreamMap = args.safeGet("url_encoded_fmt_stream_map").text();
if (formatStreamMap != null) {
return loadTrackFormatsFromFormatStreamMap(formatStreamMap);
}
throw new FriendlyException("Unable to play this YouTube track.", SUSPICIOUS, new IllegalStateException("No adaptive formats, no dash, no stream map."));
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class BandcampAudioSourceManager method loadTrack.
private AudioItem loadTrack(String trackUrl) {
return extractFromPage(trackUrl, (httpClient, text) -> {
String bandUrl = readBandUrl(text);
JsonBrowser trackListInfo = readTrackListInformation(text);
String artist = trackListInfo.get("artist").text();
return extractTrack(trackListInfo.get("trackinfo").index(0), bandUrl, artist);
});
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class YoutubeSearchMusicProvider method extractMusicData.
private AudioTrack extractMusicData(JsonBrowser json, Function<AudioTrackInfo, AudioTrack> trackFactory) {
JsonBrowser columns = json.get("musicResponsiveListItemRenderer").get("flexColumns");
if (columns.isNull()) {
// Somehow don't get track info, ignore
return null;
}
JsonBrowser firstColumn = columns.index(0).get("musicResponsiveListItemFlexColumnRenderer").get("text").get("runs").index(0);
String title = firstColumn.get("text").text();
String videoId = firstColumn.get("navigationEndpoint").get("watchEndpoint").get("videoId").text();
List<JsonBrowser> secondColumn = columns.index(1).get("musicResponsiveListItemFlexColumnRenderer").get("text").get("runs").values();
String author = secondColumn.get(0).get("text").text();
JsonBrowser lastElement = secondColumn.get(secondColumn.size() - 1);
if (!lastElement.get("navigationEndpoint").isNull()) {
// The duration element should not have this key, if it does, then duration is probably missing, so return
return null;
}
long duration = DataFormatTools.durationTextToMillis(lastElement.get("text").text());
AudioTrackInfo info = new AudioTrackInfo(title, author, duration, videoId, false, WATCH_URL_PREFIX + videoId);
return trackFactory.apply(info);
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class YoutubeSearchProvider method extractPolymerData.
private AudioTrack extractPolymerData(JsonBrowser json, Function<AudioTrackInfo, AudioTrack> trackFactory) {
JsonBrowser renderer = json.get("videoRenderer");
if (renderer.isNull()) {
// Not a track, ignore
return null;
}
String title = renderer.get("title").get("runs").index(0).get("text").text();
String author = renderer.get("ownerText").get("runs").index(0).get("text").text();
String lengthText = renderer.get("lengthText").get("simpleText").text();
if (lengthText == null) {
// Unknown length means this is a livestream, ignore
return null;
}
long duration = DataFormatTools.durationTextToMillis(lengthText);
String videoId = renderer.get("videoId").text();
AudioTrackInfo info = new AudioTrackInfo(title, author, duration, videoId, false, WATCH_URL_PREFIX + videoId);
return trackFactory.apply(info);
}
Aggregations