use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class TwitchStreamSegmentUrlProvider method fetchSegmentPlaylistUrl.
@Override
protected String fetchSegmentPlaylistUrl(HttpInterface httpInterface) throws IOException {
if (System.currentTimeMillis() < tokenExpirationTime) {
return streamSegmentPlaylistUrl;
}
JsonBrowser token = loadAccessToken(httpInterface);
HttpUriRequest request = new HttpGet(getChannelStreamsUrl(token).toString());
ChannelStreams streams = loadChannelStreamsInfo(HttpClientTools.fetchResponseLines(httpInterface, request, "channel streams list"));
if (streams.entries.isEmpty()) {
throw new IllegalStateException("No streams available on channel.");
}
ChannelStreamInfo stream = streams.entries.get(0);
log.debug("Chose stream with quality {} from url {}", stream.quality, stream.url);
streamSegmentPlaylistUrl = stream.url;
long tokenServerExpirationTime = JsonBrowser.parse(token.get(TOKEN_PARAMETER).text()).get("expires").as(Long.class) * 1000L;
tokenExpirationTime = System.currentTimeMillis() + (tokenServerExpirationTime - streams.serverTime) - 5000;
return streamSegmentPlaylistUrl;
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class BandcampAudioSourceManager method loadTrack.
private AudioItem loadTrack(UrlInfo urlInfo) {
return extractFromPage(urlInfo.fullUrl, (httpClient, text) -> {
JsonBrowser trackListInfo = readTrackListInformation(text);
String artist = trackListInfo.get("artist").safeText();
return extractTrack(trackListInfo.get("trackinfo").index(0), urlInfo.baseUrl, artist);
});
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultSoundCloudPlaylistLoader method loadPlaylistTracks.
protected List<AudioTrack> loadPlaylistTracks(HttpInterface httpInterface, JsonBrowser playlistData, Function<AudioTrackInfo, AudioTrack> trackFactory) throws IOException {
String playlistId = dataReader.readPlaylistIdentifier(playlistData);
List<String> trackIds = dataReader.readPlaylistTracks(playlistData).stream().map(dataReader::readTrackId).collect(Collectors.toList());
int numTrackIds = trackIds.size();
List<JsonBrowser> trackDataList = new ArrayList<>();
for (int i = 0; i < numTrackIds; i += 50) {
int last = Math.min(i + 50, numTrackIds);
List<String> trackIdSegment = trackIds.subList(i, last);
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(buildTrackListUrl(trackIdSegment)))) {
HttpClientTools.assertSuccessWithContent(response, "track list response");
JsonBrowser trackList = JsonBrowser.parse(response.getEntity().getContent());
trackDataList.addAll(trackList.values());
}
}
sortPlaylistTracks(trackDataList, trackIds);
int blockedCount = 0;
List<AudioTrack> tracks = new ArrayList<>();
for (JsonBrowser trackData : trackDataList) {
if (dataReader.isTrackBlocked(trackData)) {
blockedCount++;
} else {
try {
tracks.add(trackFactory.apply(dataReader.readTrackInfo(trackData, formatHandler.buildFormatIdentifier(formatHandler.chooseBestFormat(dataReader.readTrackFormats(trackData))))));
} catch (Exception e) {
log.error("In soundcloud playlist {}, failed to load track", playlistId, e);
}
}
}
if (blockedCount > 0) {
log.debug("In soundcloud playlist {}, {} tracks were omitted because they are blocked.", playlistId, blockedCount);
}
return tracks;
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class TwitchStreamSegmentUrlProvider method obtainSegmentPlaylistUrl.
private boolean obtainSegmentPlaylistUrl(HttpInterface httpInterface) throws IOException {
if (System.currentTimeMillis() < tokenExpirationTime) {
return true;
}
JsonBrowser token = loadAccessToken(httpInterface);
HttpUriRequest request = new HttpGet(getChannelStreamsUrl(token).toString());
ChannelStreams streams = loadChannelStreamsInfo(HttpClientTools.fetchResponseLines(httpInterface, request, "channel streams list"));
if (streams.entries.isEmpty()) {
throw new IllegalStateException("No streams available on channel.");
}
ChannelStreamInfo stream = streams.entries.get(0);
log.debug("Chose stream with quality {} from url {}", stream.quality, stream.url);
streamSegmentPlaylistUrl = stream.url;
long tokenServerExpirationTime = JsonBrowser.parse(token.get(TOKEN_PARAMETER).text()).get("expires").as(Long.class) * 1000L;
tokenExpirationTime = System.currentTimeMillis() + (tokenServerExpirationTime - streams.serverTime) - 5000;
return true;
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class YoutubeAudioSourceManager method getTrackInfoFromEmbedPage.
private JsonBrowser getTrackInfoFromEmbedPage(HttpInterface httpInterface, String videoId) throws Exception {
JsonBrowser basicInfo = loadTrackBaseInfoFromEmbedPage(httpInterface, videoId);
basicInfo.put("args", loadTrackArgsFromVideoInfoPage(httpInterface, videoId, basicInfo.get("sts").text()));
return basicInfo;
}
Aggregations