Skip to content

Commit d8177b5

Browse files
committed
Loop in all formats to check if the stream has URLs protected by signatureCiphers
1 parent a6a2c6e commit d8177b5

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ public long getLength() throws ParsingException {
290290
return Long.parseLong(duration);
291291
} catch (final Exception e) {
292292
try {
293-
final JsonArray formats = streamingData.getArray("formats");
294-
final String durationMs = formats.getObject(formats.size() - 1)
293+
final JsonArray adaptiveFormats = streamingData.getArray("adaptiveFormats");
294+
final String durationMs = adaptiveFormats.getObject(0)
295295
.getString("approxDurationMs");
296296
return Math.round(Long.parseLong(durationMs) / 1000f);
297297
} catch (final Exception ignored) {
@@ -504,7 +504,7 @@ public String getDashMpdUrl() throws ParsingException {
504504

505505
return dashManifestUrl;
506506
} catch (final Exception e) {
507-
throw new ParsingException("Could not get dash manifest url", e);
507+
throw new ParsingException("Could not get DASH manifest url", e);
508508
}
509509
}
510510

@@ -516,7 +516,7 @@ public String getHlsUrl() throws ParsingException {
516516
try {
517517
return streamingData.getString("hlsManifestUrl");
518518
} catch (final Exception e) {
519-
throw new ParsingException("Could not get hls manifest url", e);
519+
throw new ParsingException("Could not get HLS manifest url", e);
520520
}
521521
}
522522

@@ -961,14 +961,24 @@ private boolean isCipherProtectedContent() {
961961
if (streamingData.has("adaptiveFormats")) {
962962
final JsonArray adaptiveFormats = streamingData.getArray("adaptiveFormats");
963963
if (!isNullOrEmpty(adaptiveFormats)) {
964-
final JsonObject firstAdaptiveFormat = adaptiveFormats.getObject(0);
965-
return firstAdaptiveFormat.has("cipher") || firstAdaptiveFormat.has("signatureCipher");
964+
for (final Object adaptiveFormat : adaptiveFormats) {
965+
final JsonObject adaptiveFormatJsonObject = ((JsonObject) adaptiveFormat);
966+
if (adaptiveFormatJsonObject.has("signatureCipher")
967+
|| adaptiveFormatJsonObject.has("cipher")) {
968+
return true;
969+
}
970+
}
966971
}
967972
} else if (streamingData.has("formats")) {
968973
final JsonArray formats = streamingData.getArray("formats");
969974
if (!isNullOrEmpty(formats)) {
970-
final JsonObject firstFormat = formats.getObject(0);
971-
return firstFormat.has("cipher") || firstFormat.has("signatureCipher");
975+
for (final Object format : formats) {
976+
final JsonObject formatJsonObject = ((JsonObject) format);
977+
if (formatJsonObject.has("signatureCipher")
978+
|| formatJsonObject.has("cipher")) {
979+
return true;
980+
}
981+
}
972982
}
973983
}
974984
}
@@ -1134,7 +1144,7 @@ private Map<String, ItagItem> getItags(final String streamingDataKey,
11341144

11351145
if (ItagItem.isSupported(itag)) {
11361146
try {
1137-
ItagItem itagItem = ItagItem.getItag(itag);
1147+
final ItagItem itagItem = ItagItem.getItag(itag);
11381148
if (itagItem.itagType == itagTypeWanted) {
11391149
// Ignore streams that are delivered using YouTube's OTF format,
11401150
// as those only work with DASH and not with progressive HTTP.

0 commit comments

Comments
 (0)