From 43200af2752a6f50a49f2685bd23644b4daaae40 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 12 Aug 2023 13:08:09 +0100 Subject: [PATCH] Attempt to extract function from player only once. --- .../youtube/YoutubeThrottlingDecrypter.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java index 227751e29..f6b9cca4c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java @@ -52,9 +52,12 @@ public final class YoutubeThrottlingDecrypter { private static final String FUNCTION_NAMES_IN_DECRYPT_ARRAY_REGEX = "\\s*=\\s*\\[(.+?)][;,]"; private static final Map N_PARAMS_CACHE = new HashMap<>(); + private static String playerJsCode; private static String decryptFunction; private static String decryptFunctionName; + private static final Object PLAYER_JS_CODE_LOCK = new Object(); + private YoutubeThrottlingDecrypter() { // No implementation } @@ -89,12 +92,17 @@ public final class YoutubeThrottlingDecrypter { } try { - if (decryptFunction == null) { - final String playerJsCode - = YoutubeJavaScriptExtractor.extractJavaScriptCode(videoId); + synchronized (PLAYER_JS_CODE_LOCK) { + if (playerJsCode == null) { + playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptCode(videoId); - decryptFunctionName = parseDecodeFunctionName(playerJsCode); - decryptFunction = parseDecodeFunction(playerJsCode, decryptFunctionName); + decryptFunctionName = parseDecodeFunctionName(playerJsCode); + decryptFunction = parseDecodeFunction(playerJsCode, decryptFunctionName); + } + } + + if (decryptFunction == null || decryptFunctionName == null) { + throw new ParsingException("The decryption function was not parsed correctly"); } final String oldNParam = parseNParam(streamingUrl);