use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class SoundCloudAudioSourceManager method handlePlaylistTracksResponse.
private List<AudioTrack> handlePlaylistTracksResponse(HttpResponse response, String playlistWebUrl, List<String> trackIds) throws IOException {
List<AudioTrack> tracks = new ArrayList<>();
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
throw new IOException("Invalid status code for track list response: " + statusCode);
}
JsonBrowser trackList = JsonBrowser.parse(response.getEntity().getContent());
int blockedCount = 0;
for (JsonBrowser trackInfoJson : trackList.values()) {
if ("BLOCK".equals(trackInfoJson.get("policy").text())) {
blockedCount++;
} else {
tracks.add(buildAudioTrack(trackInfoJson, null));
}
}
if (blockedCount > 0) {
log.debug("In soundcloud playlist {}, {} tracks were omitted because they are blocked.", playlistWebUrl, blockedCount);
}
sortPlaylistTracks(tracks, trackIds);
return tracks;
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class TwitchStreamAudioSourceManager method loadItem.
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
String streamName = getChannelIdentifierFromUrl(reference.identifier);
if (streamName == null) {
return null;
}
JsonBrowser channelInfo = fetchStreamChannelInfo(streamName);
if (channelInfo == null) {
return AudioReference.NO_TRACK;
} else {
final String displayName = channelInfo.get("display_name").text();
final String status = channelInfo.get("status").text();
return new TwitchStreamAudioTrack(new AudioTrackInfo(status, displayName, Long.MAX_VALUE, reference.identifier, true, reference.identifier), this);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class YoutubeAudioSourceManager method loadTrackWithVideoId.
/**
* Loads a single track from video ID.
*
* @param videoId ID of the YouTube video.
* @param mustExist True if it should throw an exception on missing track, otherwise returns AudioReference.NO_TRACK.
* @return Loaded YouTube track.
*/
public AudioItem loadTrackWithVideoId(String videoId, boolean mustExist) {
try (HttpInterface httpInterface = getHttpInterface()) {
JsonBrowser info = getTrackInfoFromMainPage(httpInterface, videoId, mustExist);
if (info == null) {
return AudioReference.NO_TRACK;
}
JsonBrowser args = info.get("args");
if ("fail".equals(args.get("status").text())) {
throw new FriendlyException(args.get("reason").text(), COMMON, null);
}
boolean isStream = "1".equals(args.get("live_playback").text());
long duration = isStream ? Long.MAX_VALUE : args.get("length_seconds").as(Long.class) * 1000;
return buildTrackObject(videoId, args.get("title").text(), args.get("author").text(), isStream, duration);
} catch (Exception e) {
throw ExceptionTools.wrapUnfriendlyExceptions("Loading information for a YouTube track failed.", FAULT, e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class BandcampAudioSourceManager method loadAlbum.
private AudioItem loadAlbum(String albumUrl) {
return extractFromPage(albumUrl, (httpClient, text) -> {
String bandUrl = readBandUrl(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, bandUrl, artist));
}
JsonBrowser albumInfo = readAlbumInformation(text);
return new BasicAudioPlaylist(albumInfo.get("album_title").text(), tracks, null, false);
});
}
use of com.sedmelluq.discord.lavaplayer.tools.JsonBrowser in project lavaplayer by sedmelluq.
the class BeamAudioSourceManager method loadItem.
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
String streamName = getChannelNameFromUrl(reference.identifier);
if (streamName == null) {
return null;
}
JsonBrowser channelInfo = fetchStreamChannelInfo(streamName);
if (channelInfo == null) {
return AudioReference.NO_TRACK;
} else {
String displayName = channelInfo.get("name").text();
String id = channelInfo.get("id").text();
if (displayName == null || id == null) {
throw new IllegalStateException("Expected id and name fields from Beam channel info.");
}
return new BeamAudioTrack(new AudioTrackInfo(displayName, streamName, Long.MAX_VALUE, id + "|" + streamName + "|" + reference.identifier, true, "https://beam.pro/" + streamName), this);
}
}
Aggregations