use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultSoundCloudPlaylistLoader method loadFromSet.
protected AudioPlaylist loadFromSet(HttpInterfaceManager httpInterfaceManager, String playlistWebUrl, Function<AudioTrackInfo, AudioTrack> trackFactory) {
try (HttpInterface httpInterface = httpInterfaceManager.getInterface()) {
JsonBrowser rootData = htmlDataLoader.load(httpInterface, playlistWebUrl);
JsonBrowser playlistData = dataReader.findPlaylistData(rootData);
return new BasicAudioPlaylist(dataReader.readPlaylistName(playlistData), loadPlaylistTracks(httpInterface, playlistData, trackFactory), null, false);
} catch (IOException e) {
throw new FriendlyException("Loading playlist from SoundCloud failed.", SUSPICIOUS, e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class SoundCloudAudioSourceManager method loadFromTrackPage.
public AudioTrack loadFromTrackPage(String trackWebUrl) {
try (HttpInterface httpInterface = getHttpInterface()) {
JsonBrowser rootData = htmlDataLoader.load(httpInterface, trackWebUrl);
JsonBrowser trackData = dataReader.findTrackData(rootData);
if (trackData == null) {
throw new FriendlyException("This track is not available", COMMON, null);
}
return loadFromTrackData(trackData);
} catch (IOException e) {
throw new FriendlyException("Loading track from SoundCloud failed.", SUSPICIOUS, e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetailsLoader method loadTrackArgsFromVideoInfoPage.
protected JsonBrowser loadTrackArgsFromVideoInfoPage(HttpInterface httpInterface, String videoId, String sts) throws IOException {
String videoApiUrl = "https://youtube.googleapis.com/v/" + videoId;
String encodedApiUrl = URLEncoder.encode(videoApiUrl, UTF_8.name());
String url = "https://www.youtube.com/get_video_info?video_id=" + videoId + "&eurl=" + encodedApiUrl + "&hl=en_GB&html5=1&c=ANDROID&cver=16.24";
if (sts != null) {
url += "&sts=" + sts;
}
JsonBrowser values = JsonBrowser.newMap();
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(url))) {
HttpClientTools.assertSuccessWithContent(response, "video info response");
for (NameValuePair pair : URLEncodedUtils.parse(response.getEntity())) {
values.put(pair.getName(), pair.getValue());
}
}
return values;
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubeTrackDetailsLoader method getUnplayableReason.
protected String getUnplayableReason(JsonBrowser statusBlock) {
JsonBrowser playerErrorMessage = statusBlock.get("errorScreen").get("playerErrorMessageRenderer");
String unplayableReason = statusBlock.get("reason").text();
if (!playerErrorMessage.get("subreason").isNull()) {
JsonBrowser subreason = playerErrorMessage.get("subreason");
if (!subreason.get("simpleText").isNull()) {
unplayableReason = subreason.get("simpleText").text();
} else if (!subreason.get("runs").isNull() && subreason.get("runs").isList()) {
StringBuilder reasonBuilder = new StringBuilder();
subreason.get("runs").values().forEach(item -> reasonBuilder.append(item.get("text").text()).append('\n'));
unplayableReason = reasonBuilder.toString();
}
}
return unplayableReason;
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class DefaultYoutubePlaylistLoader method extractPlaylistTracks.
private String extractPlaylistTracks(JsonBrowser playlistVideoList, List<AudioTrack> tracks, Function<AudioTrackInfo, AudioTrack> trackFactory) {
if (playlistVideoList.isNull())
return null;
final List<JsonBrowser> playlistTrackEntries = playlistVideoList.values();
for (JsonBrowser track : playlistTrackEntries) {
JsonBrowser item = track.get("playlistVideoRenderer");
JsonBrowser shortBylineText = item.get("shortBylineText");
// If the shortBylineText property does not exist, it means the Track is Region blocked
if (!item.get("isPlayable").isNull() && !shortBylineText.isNull()) {
String videoId = item.get("videoId").text();
JsonBrowser titleField = item.get("title");
String title = Optional.ofNullable(titleField.get("simpleText").text()).orElse(titleField.get("runs").index(0).get("text").text());
String author = shortBylineText.get("runs").index(0).get("text").text();
JsonBrowser lengthSeconds = item.get("lengthSeconds");
long duration = Units.secondsToMillis(lengthSeconds.asLong(Units.DURATION_SEC_UNKNOWN));
AudioTrackInfo info = new AudioTrackInfo(title, author, duration, videoId, false, "https://www.youtube.com/watch?v=" + videoId);
tracks.add(trackFactory.apply(info));
}
}
JsonBrowser continuations = playlistTrackEntries.get(playlistTrackEntries.size() - 1).get("continuationItemRenderer").get("continuationEndpoint").get("continuationCommand");
String continuationsToken;
if (!continuations.isNull()) {
continuationsToken = continuations.get("token").text();
return continuationsToken;
}
return null;
}
Aggregations