Skip to content

Commit

Permalink
Loop in all formats to check if the stream has URLs protected by sign…
Browse files Browse the repository at this point in the history
…atureCiphers
  • Loading branch information
AudricV committed Jun 15, 2021
1 parent d463636 commit 651674a
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ public long getLength() throws ParsingException {
return Long.parseLong(duration);
} catch (final Exception e) {
try {
final JsonArray formats = streamingData.getArray("formats");
final String durationMs = formats.getObject(formats.size() - 1)
final JsonArray adaptiveFormats = streamingData.getArray("adaptiveFormats");
final String durationMs = adaptiveFormats.getObject(0)
.getString("approxDurationMs");
return Math.round(Long.parseLong(durationMs) / 1000f);
} catch (final Exception ignored) {
Expand Down Expand Up @@ -500,7 +500,7 @@ public String getDashMpdUrl() throws ParsingException {

return dashManifestUrl;
} catch (final Exception e) {
throw new ParsingException("Could not get dash manifest url", e);
throw new ParsingException("Could not get DASH manifest url", e);
}
}

Expand All @@ -512,7 +512,7 @@ public String getHlsUrl() throws ParsingException {
try {
return streamingData.getString("hlsManifestUrl");
} catch (final Exception e) {
throw new ParsingException("Could not get hls manifest url", e);
throw new ParsingException("Could not get HLS manifest url", e);
}
}

Expand Down Expand Up @@ -945,14 +945,24 @@ private boolean isCipherProtectedContent() {
if (streamingData.has("adaptiveFormats")) {
final JsonArray adaptiveFormats = streamingData.getArray("adaptiveFormats");
if (!isNullOrEmpty(adaptiveFormats)) {
final JsonObject firstAdaptiveFormat = adaptiveFormats.getObject(0);
return firstAdaptiveFormat.has("cipher") || firstAdaptiveFormat.has("signatureCipher");
for (final Object adaptiveFormat : adaptiveFormats) {
final JsonObject adaptiveFormatJsonObject = ((JsonObject) adaptiveFormat);
if (adaptiveFormatJsonObject.has("signatureCipher")
|| adaptiveFormatJsonObject.has("cipher")) {
return true;
}
}
}
} else if (streamingData.has("formats")) {
final JsonArray formats = streamingData.getArray("formats");
if (!isNullOrEmpty(formats)) {
final JsonObject firstFormat = formats.getObject(0);
return firstFormat.has("cipher") || firstFormat.has("signatureCipher");
for (final Object format : formats) {
final JsonObject formatJsonObject = ((JsonObject) format);
if (formatJsonObject.has("signatureCipher")
|| formatJsonObject.has("cipher")) {
return true;
}
}
}
}
}
Expand Down Expand Up @@ -1118,7 +1128,7 @@ private Map<String, ItagItem> getItags(final String streamingDataKey,

if (ItagItem.isSupported(itag)) {
try {
ItagItem itagItem = ItagItem.getItag(itag);
final ItagItem itagItem = ItagItem.getItag(itag);
if (itagItem.itagType == itagTypeWanted) {
// Ignore streams that are delivered using YouTube's OTF format,
// as those only work with DASH and not with progressive HTTP.
Expand Down

0 comments on commit 651674a

Please sign in to comment.