From 651674a54ee25757ae378e069b1a124dfab034eb Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Fri, 11 Jun 2021 13:32:59 +0200 Subject: [PATCH] Loop in all formats to check if the stream has URLs protected by signatureCiphers --- .../extractors/YoutubeStreamExtractor.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 0f0d46e95a..e7abe532a2 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -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) { @@ -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); } } @@ -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); } } @@ -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; + } + } } } } @@ -1118,7 +1128,7 @@ private Map 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.