use of com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackFormat in project lavaplayer by sedmelluq.
the class LegacyDashMpdFormatsExtractor method loadTrackFormatsFromDashDocument.
private List<YoutubeTrackFormat> loadTrackFormatsFromDashDocument(Document document) {
List<YoutubeTrackFormat> tracks = new ArrayList<>();
for (Element adaptation : document.select("AdaptationSet")) {
String mimeType = adaptation.attr("mimeType");
for (Element representation : adaptation.select("Representation")) {
String url = representation.select("BaseURL").first().text();
String contentLength = DataFormatTools.extractBetween(url, "/clen/", "/");
String contentType = mimeType + "; codecs=" + representation.attr("codecs");
if (contentLength == null) {
log.debug("Skipping format {} because the content length is missing", contentType);
continue;
}
tracks.add(new YoutubeTrackFormat(ContentType.parse(contentType), Long.parseLong(representation.attr("bandwidth")), Long.parseLong(contentLength), url, null, DEFAULT_SIGNATURE_KEY));
}
}
return tracks;
}
use of com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackFormat in project lavaplayer by sedmelluq.
the class LegacyAdaptiveFormatsExtractor method loadTrackFormatsFromAdaptive.
private List<YoutubeTrackFormat> loadTrackFormatsFromAdaptive(String adaptiveFormats) {
List<YoutubeTrackFormat> tracks = new ArrayList<>();
for (String formatString : adaptiveFormats.split(",")) {
Map<String, String> format = decodeUrlEncodedItems(formatString, false);
tracks.add(new YoutubeTrackFormat(ContentType.parse(format.get("type")), Long.parseLong(format.get("bitrate")), Long.parseLong(format.get("clen")), format.get("url"), format.get("s"), format.getOrDefault("sp", DEFAULT_SIGNATURE_KEY)));
}
return tracks;
}
use of com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackFormat in project lavaplayer by sedmelluq.
the class LegacyStreamMapFormatsExtractor method loadTrackFormatsFromFormatStreamMap.
private List<YoutubeTrackFormat> loadTrackFormatsFromFormatStreamMap(String adaptiveFormats) {
List<YoutubeTrackFormat> tracks = new ArrayList<>();
boolean anyFailures = false;
for (String formatString : adaptiveFormats.split(",")) {
try {
Map<String, String> format = decodeUrlEncodedItems(formatString, false);
String url = format.get("url");
if (url == null) {
continue;
}
String contentLength = DataFormatTools.extractBetween(url, "clen=", "&");
if (contentLength == null) {
log.debug("Could not find content length from URL {}, skipping format", url);
continue;
}
tracks.add(new YoutubeTrackFormat(ContentType.parse(format.get("type")), qualityToBitrateValue(format.get("quality")), Long.parseLong(contentLength), url, format.get("s"), format.getOrDefault("sp", DEFAULT_SIGNATURE_KEY)));
} catch (RuntimeException e) {
anyFailures = true;
log.debug("Failed to parse format {}, skipping.", formatString, e);
}
}
if (tracks.isEmpty() && anyFailures) {
log.warn("In adaptive format map {}, all formats either failed to load or were skipped due to missing fields", adaptiveFormats);
}
return tracks;
}
use of com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackFormat in project lavaplayer by sedmelluq.
the class StreamingDataFormatsExtractor method extract.
@Override
public List<YoutubeTrackFormat> extract(YoutubeTrackJsonData data) {
JsonBrowser streamingData = data.playerResponse.get("streamingData");
if (streamingData.isNull()) {
return Collections.emptyList();
}
boolean isLive = data.playerResponse.get("videoDetails").get("isLive").asBoolean(false);
List<YoutubeTrackFormat> formats = loadTrackFormatsFromStreamingData(streamingData.get("formats"), isLive);
formats.addAll(loadTrackFormatsFromStreamingData(streamingData.get("adaptiveFormats"), isLive));
return formats;
}
use of com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeTrackFormat in project lavaplayer by sedmelluq.
the class StreamingDataFormatsExtractor method loadTrackFormatsFromStreamingData.
private List<YoutubeTrackFormat> loadTrackFormatsFromStreamingData(JsonBrowser formats, boolean isLive) {
List<YoutubeTrackFormat> tracks = new ArrayList<>();
boolean anyFailures = false;
if (!formats.isNull() && formats.isList()) {
for (JsonBrowser formatJson : formats.values()) {
String cipher = formatJson.get("cipher").text();
if (cipher == null) {
cipher = formatJson.get("signatureCipher").text();
}
Map<String, String> cipherInfo = cipher != null ? decodeUrlEncodedItems(cipher, true) : Collections.emptyMap();
try {
long contentLength = formatJson.get("contentLength").asLong(CONTENT_LENGTH_UNKNOWN);
if (contentLength == CONTENT_LENGTH_UNKNOWN && !isLive) {
log.debug("Track not a live stream, but no contentLength in format {}, skipping", formatJson.format());
continue;
}
tracks.add(new YoutubeTrackFormat(ContentType.parse(formatJson.get("mimeType").text()), formatJson.get("bitrate").asLong(Units.BITRATE_UNKNOWN), contentLength, cipherInfo.getOrDefault("url", formatJson.get("url").text()), cipherInfo.get("s"), cipherInfo.getOrDefault("sp", DEFAULT_SIGNATURE_KEY)));
} catch (RuntimeException e) {
anyFailures = true;
log.debug("Failed to parse format {}, skipping", formatJson, e);
}
}
}
if (tracks.isEmpty() && anyFailures) {
log.warn("In streamingData adaptive formats {}, all formats either failed to load or were skipped due to missing " + "fields", formats.format());
}
return tracks;
}
Aggregations