use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubePlaylistLoader method buildPlaylist.
private AudioPlaylist buildPlaylist(HttpInterface httpInterface, JsonBrowser json, String selectedVideoId, Function<AudioTrackInfo, AudioTrack> trackFactory) throws IOException {
JsonBrowser jsonResponse = json.index(1).get("response");
String errorAlertMessage = findErrorAlert(jsonResponse);
if (errorAlertMessage != null) {
throw new FriendlyException(errorAlertMessage, COMMON, null);
}
JsonBrowser info = jsonResponse.get("sidebar").get("playlistSidebarRenderer").get("items").index(0).get("playlistSidebarPrimaryInfoRenderer");
String playlistName = info.get("title").get("runs").index(0).get("text").text();
JsonBrowser playlistVideoList = jsonResponse.get("contents").get("twoColumnBrowseResultsRenderer").get("tabs").index(0).get("tabRenderer").get("content").get("sectionListRenderer").get("contents").index(0).get("itemSectionRenderer").get("contents").index(0).get("playlistVideoListRenderer").get("contents");
List<AudioTrack> tracks = new ArrayList<>();
String continuationsToken = extractPlaylistTracks(playlistVideoList, tracks, trackFactory);
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 (continuationsToken != null && ++loadCount < pageCount) {
HttpPost post = new HttpPost(REQUEST_URL);
StringEntity payload = new StringEntity(String.format(REQUEST_PAYLOAD, continuationsToken), "UTF-8");
post.setEntity(payload);
try (CloseableHttpResponse response = httpInterface.execute(post)) {
HttpClientTools.assertSuccessWithContent(response, "playlist response");
JsonBrowser continuationJson = JsonBrowser.parse(response.getEntity().getContent());
JsonBrowser playlistVideoListPage = continuationJson.index(1).get("response").get("continuationContents").get("playlistVideoListContinuation");
if (playlistVideoListPage.isNull()) {
playlistVideoListPage = continuationJson.get("onResponseReceivedActions").index(0).get("appendContinuationItemsAction").get("continuationItems");
}
continuationsToken = extractPlaylistTracks(playlistVideoListPage, tracks, trackFactory);
}
}
return new BasicAudioPlaylist(playlistName, tracks, findSelectedTrack(tracks, selectedVideoId), false);
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetailsLoader method load.
private YoutubeTrackDetails load(HttpInterface httpInterface, String videoId, boolean requireFormats) throws IOException {
JsonBrowser mainInfo = loadTrackInfoFromMainPage(httpInterface, videoId);
try {
YoutubeTrackJsonData initialData = loadBaseResponse(mainInfo, httpInterface, videoId, requireFormats);
if (initialData == null) {
return null;
}
YoutubeTrackJsonData finalData = augmentWithPlayerScript(initialData, httpInterface, requireFormats);
return new DefaultYoutubeTrackDetails(videoId, finalData);
} catch (FriendlyException e) {
throw e;
} catch (Exception e) {
throw throwWithDebugInfo(log, e, "Error when extracting data", "mainJson", mainInfo.format());
}
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetailsLoader method loadBaseResponse.
protected YoutubeTrackJsonData loadBaseResponse(JsonBrowser mainInfo, HttpInterface httpInterface, String videoId, boolean requireFormats) throws IOException {
YoutubeTrackJsonData data = YoutubeTrackJsonData.fromMainResult(mainInfo);
InfoStatus status = checkPlayabilityStatus(data.playerResponse);
if (status == InfoStatus.DOES_NOT_EXIST) {
return null;
}
if (status == InfoStatus.CONTENT_CHECK_REQUIRED) {
JsonBrowser trackInfo = loadTrackInfoWithContentVerifyRequest(httpInterface, videoId);
return YoutubeTrackJsonData.fromMainResult(trackInfo);
}
if (requireFormats && status == InfoStatus.REQUIRES_LOGIN) {
JsonBrowser basicInfo = loadTrackBaseInfoFromEmbedPage(httpInterface, videoId);
return fromEmbedParts(basicInfo, loadTrackArgsFromVideoInfoPage(httpInterface, videoId, basicInfo.get("sts").text()));
} else {
return data;
}
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultSoundCloudDataReader method readTrackFormats.
@Override
public List<SoundCloudTrackFormat> readTrackFormats(JsonBrowser trackData) {
List<SoundCloudTrackFormat> formats = new ArrayList<>();
String trackId = readTrackId(trackData);
if (trackId.isEmpty()) {
log.warn("Track data {} missing track ID: {}.", trackId, trackData.format());
}
for (JsonBrowser transcoding : trackData.get("media").get("transcodings").values()) {
JsonBrowser format = transcoding.get("format");
String protocol = format.get("protocol").safeText();
String mimeType = format.get("mime_type").safeText();
if (!protocol.isEmpty() && !mimeType.isEmpty()) {
String lookupUrl = transcoding.get("url").safeText();
if (!lookupUrl.isEmpty()) {
formats.add(new DefaultSoundCloudTrackFormat(trackId, protocol, mimeType, lookupUrl));
} else {
log.warn("Transcoding of {} missing url: {}.", trackId, transcoding.format());
}
} else {
log.warn("Transcoding of {} missing protocol/mimetype: {}.", trackId, transcoding.format());
}
}
return formats;
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class TwitchStreamAudioSourceManager method loadItem.
@Override
public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) {
String streamName = getChannelIdentifierFromUrl(reference.identifier);
if (streamName == null) {
return null;
}
JsonBrowser accessToken = fetchAccessToken(streamName);
if (accessToken == null || accessToken.get("token").isNull()) {
return AudioReference.NO_TRACK;
}
String channelId;
try {
JsonBrowser token = JsonBrowser.parse(accessToken.get("token").text());
channelId = token.get("channel_id").text();
} catch (IOException e) {
return null;
}
JsonBrowser channelInfo = fetchStreamChannelInfo(channelId);
if (channelInfo == null || channelInfo.get("stream").isNull()) {
return AudioReference.NO_TRACK;
} else {
/*
--- HELIX STUFF
//Retrieve the data value list; this will have only one element since we're getting only one stream's information
List<JsonBrowser> dataList = channelInfo.get("data").values();
//The value list is empty if the stream is offline, even when hosting another channel
if (dataList.size() == 0){
return null;
}
//The first one has the title of the broadcast
JsonBrowser channelData = dataList.get(0);
String status = channelData.get("title").text();
*/
JsonBrowser channelData = channelInfo.get("stream").get("channel");
String status = channelData.get("status").text();
return new TwitchStreamAudioTrack(new AudioTrackInfo(status, streamName, Units.DURATION_MS_UNKNOWN, reference.identifier, true, reference.identifier), this);
}
}
Aggregations