Skip to content

Commit d73de6b

Browse files
committed
[YouTube] Don't provide streaming URLs which have an non-decoded n param
This param used to throttle bandwidth of streaming URLs which have this parameter when the correct value is not provided but it is not the case anymore, as the streaming URLs return now an HTTP response code 403 in this case.
1 parent 22f8181 commit d73de6b

1 file changed

Lines changed: 10 additions & 25 deletions

File tree

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

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -634,28 +634,6 @@ public List<VideoStream> getVideoOnlyStreams() throws ExtractionException {
634634
getVideoStreamBuilderHelper(true), "video-only");
635635
}
636636

637-
/**
638-
* Try to deobfuscate a streaming URL and fall back to the given URL, because decryption may
639-
* fail if YouTube changes break something.
640-
*
641-
* <p>
642-
* This way a breaking change from YouTube does not result in a broken extractor.
643-
* </p>
644-
*
645-
* @param streamingUrl the streaming URL to which deobfuscating its throttling parameter if
646-
* there is one
647-
* @param videoId the video ID to use when extracting JavaScript player code, if needed
648-
*/
649-
private String tryDeobfuscateThrottlingParameterOfUrl(@Nonnull final String streamingUrl,
650-
@Nonnull final String videoId) {
651-
try {
652-
return YoutubeJavaScriptPlayerManager.getUrlWithThrottlingParameterDeobfuscated(
653-
videoId, streamingUrl);
654-
} catch (final ParsingException e) {
655-
return streamingUrl;
656-
}
657-
}
658-
659637
@Override
660638
@Nonnull
661639
public List<SubtitlesStream> getSubtitlesDefault() throws ParsingException {
@@ -1286,7 +1264,8 @@ private java.util.stream.Stream<ItagInfo> getStreamsFromStreamingDataKey(
12861264
itagItem.itagType, contentPlaybackNonce);
12871265
}
12881266
} catch (final ExtractionException ignored) {
1289-
// if the itag is not supported and getItag fails, we end up here
1267+
// If the itag is not supported, the n parameter of HTML5 clients cannot be
1268+
// decoded or buildAndAddItagInfoToList fails, we end up here
12901269
}
12911270
return null;
12921271
})
@@ -1315,8 +1294,14 @@ private ItagInfo buildAndAddItagInfoToList(
13151294
// Add the content playback nonce to the stream URL
13161295
streamUrl += "&" + CPN + "=" + contentPlaybackNonce;
13171296

1318-
// Decrypt the n parameter if it is present
1319-
streamUrl = tryDeobfuscateThrottlingParameterOfUrl(streamUrl, videoId);
1297+
// Decode the n parameter if it is present
1298+
// If it cannot be decoded, the stream cannot be used as streaming URLs return HTTP 403
1299+
// responses if it has not the right value
1300+
// Exceptions thrown by
1301+
// YoutubeJavaScriptPlayerManager.getUrlWithThrottlingParameterDeobfuscated are so
1302+
// propagated to the parent which ignores streams in this case
1303+
streamUrl = YoutubeJavaScriptPlayerManager.getUrlWithThrottlingParameterDeobfuscated(
1304+
videoId, streamUrl);
13201305

13211306
final JsonObject initRange = formatData.getObject("initRange");
13221307
final JsonObject indexRange = formatData.getObject("indexRange");

0 commit comments

Comments
 (0)