use of com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist 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.track.BasicAudioPlaylist in project lavaplayer by sedmelluq.
the class YoutubeMixProvider method loadTracksAsynchronously.
private AudioPlaylist loadTracksAsynchronously(List<String> videoIds, String selectedVideoId) {
ExecutorCompletionService<AudioItem> completion = new ExecutorCompletionService<>(mixLoadingExecutor);
List<AudioTrack> tracks = new ArrayList<>();
for (final String videoId : videoIds) {
completion.submit(() -> sourceManager.loadTrackWithVideoId(videoId, true));
}
try {
fetchTrackResultsFromExecutor(completion, tracks, videoIds.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
AudioTrack selectedTrack = sourceManager.findSelectedTrack(tracks, selectedVideoId);
if (tracks.isEmpty()) {
throw new FriendlyException("No tracks from the mix loaded succesfully.", SUSPICIOUS, null);
} else if (selectedTrack == null) {
throw new FriendlyException("The selected track of the mix failed to load.", SUSPICIOUS, null);
}
return new BasicAudioPlaylist("YouTube mix", tracks, selectedTrack, false);
}
use of com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist in project lavaplayer by sedmelluq.
the class YoutubeSearchProvider method extractSearchResults.
private AudioItem extractSearchResults(Document document, String query, Function<AudioTrackInfo, AudioTrack> trackFactory) {
List<AudioTrack> tracks = new ArrayList<>();
Elements resultsSelection = document.select("#page > #content #results");
if (!resultsSelection.isEmpty()) {
for (Element results : resultsSelection) {
for (Element result : results.select(".yt-lockup-video")) {
if (!result.hasAttr("data-ad-impressions") && result.select(".standalone-ypc-badge-renderer-label").isEmpty()) {
extractTrackFromResultEntry(tracks, result, trackFactory);
}
}
}
} else {
log.debug("Attempting to parse results page as polymer");
try {
tracks = polymerExtractTracks(document, trackFactory);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (tracks.isEmpty()) {
return AudioReference.NO_TRACK;
} else {
return new BasicAudioPlaylist("Search results for: " + query, tracks, null, true);
}
}
use of com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist in project lavaplayer by sedmelluq.
the class BandcampAudioSourceManager method loadAlbum.
private AudioItem loadAlbum(UrlInfo urlInfo) {
return extractFromPage(urlInfo.fullUrl, (httpClient, 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, urlInfo.baseUrl, artist));
}
JsonBrowser albumInfo = readAlbumInformation(text);
return new BasicAudioPlaylist(albumInfo.get("current").get("title").text(), tracks, null, false);
});
}
use of com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist 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);
}
}
Aggregations