Loop in all formats to check if the stream has URLs protected by signatureCiphers

This commit is contained in:
TiA4f8R 2021-06-11 13:32:59 +02:00
parent a6a2c6eb80
commit d8177b57f6
No known key found for this signature in database
GPG Key ID: E6D3E7F5949450DD
1 changed files with 19 additions and 9 deletions

View File

@ -290,8 +290,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
return Long.parseLong(duration); return Long.parseLong(duration);
} catch (final Exception e) { } catch (final Exception e) {
try { try {
final JsonArray formats = streamingData.getArray("formats"); final JsonArray adaptiveFormats = streamingData.getArray("adaptiveFormats");
final String durationMs = formats.getObject(formats.size() - 1) final String durationMs = adaptiveFormats.getObject(0)
.getString("approxDurationMs"); .getString("approxDurationMs");
return Math.round(Long.parseLong(durationMs) / 1000f); return Math.round(Long.parseLong(durationMs) / 1000f);
} catch (final Exception ignored) { } catch (final Exception ignored) {
@ -504,7 +504,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
return dashManifestUrl; return dashManifestUrl;
} catch (final Exception e) { } catch (final Exception e) {
throw new ParsingException("Could not get dash manifest url", e); throw new ParsingException("Could not get DASH manifest url", e);
} }
} }
@ -516,7 +516,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
try { try {
return streamingData.getString("hlsManifestUrl"); return streamingData.getString("hlsManifestUrl");
} catch (final Exception e) { } catch (final Exception e) {
throw new ParsingException("Could not get hls manifest url", e); throw new ParsingException("Could not get HLS manifest url", e);
} }
} }
@ -961,14 +961,24 @@ public class YoutubeStreamExtractor extends StreamExtractor {
if (streamingData.has("adaptiveFormats")) { if (streamingData.has("adaptiveFormats")) {
final JsonArray adaptiveFormats = streamingData.getArray("adaptiveFormats"); final JsonArray adaptiveFormats = streamingData.getArray("adaptiveFormats");
if (!isNullOrEmpty(adaptiveFormats)) { if (!isNullOrEmpty(adaptiveFormats)) {
final JsonObject firstAdaptiveFormat = adaptiveFormats.getObject(0); for (final Object adaptiveFormat : adaptiveFormats) {
return firstAdaptiveFormat.has("cipher") || firstAdaptiveFormat.has("signatureCipher"); final JsonObject adaptiveFormatJsonObject = ((JsonObject) adaptiveFormat);
if (adaptiveFormatJsonObject.has("signatureCipher")
|| adaptiveFormatJsonObject.has("cipher")) {
return true;
}
}
} }
} else if (streamingData.has("formats")) { } else if (streamingData.has("formats")) {
final JsonArray formats = streamingData.getArray("formats"); final JsonArray formats = streamingData.getArray("formats");
if (!isNullOrEmpty(formats)) { if (!isNullOrEmpty(formats)) {
final JsonObject firstFormat = formats.getObject(0); for (final Object format : formats) {
return firstFormat.has("cipher") || firstFormat.has("signatureCipher"); final JsonObject formatJsonObject = ((JsonObject) format);
if (formatJsonObject.has("signatureCipher")
|| formatJsonObject.has("cipher")) {
return true;
}
}
} }
} }
} }
@ -1134,7 +1144,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
if (ItagItem.isSupported(itag)) { if (ItagItem.isSupported(itag)) {
try { try {
ItagItem itagItem = ItagItem.getItag(itag); final ItagItem itagItem = ItagItem.getItag(itag);
if (itagItem.itagType == itagTypeWanted) { if (itagItem.itagType == itagTypeWanted) {
// Ignore streams that are delivered using YouTube's OTF format, // Ignore streams that are delivered using YouTube's OTF format,
// as those only work with DASH and not with progressive HTTP. // as those only work with DASH and not with progressive HTTP.