Attempt to extract function from player only once.
This commit is contained in:
parent
7294675aea
commit
43200af275
|
@ -52,9 +52,12 @@ public final class YoutubeThrottlingDecrypter {
|
||||||
private static final String FUNCTION_NAMES_IN_DECRYPT_ARRAY_REGEX = "\\s*=\\s*\\[(.+?)][;,]";
|
private static final String FUNCTION_NAMES_IN_DECRYPT_ARRAY_REGEX = "\\s*=\\s*\\[(.+?)][;,]";
|
||||||
|
|
||||||
private static final Map<String, String> N_PARAMS_CACHE = new HashMap<>();
|
private static final Map<String, String> N_PARAMS_CACHE = new HashMap<>();
|
||||||
|
private static String playerJsCode;
|
||||||
private static String decryptFunction;
|
private static String decryptFunction;
|
||||||
private static String decryptFunctionName;
|
private static String decryptFunctionName;
|
||||||
|
|
||||||
|
private static final Object PLAYER_JS_CODE_LOCK = new Object();
|
||||||
|
|
||||||
private YoutubeThrottlingDecrypter() {
|
private YoutubeThrottlingDecrypter() {
|
||||||
// No implementation
|
// No implementation
|
||||||
}
|
}
|
||||||
|
@ -89,13 +92,18 @@ public final class YoutubeThrottlingDecrypter {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (decryptFunction == null) {
|
synchronized (PLAYER_JS_CODE_LOCK) {
|
||||||
final String playerJsCode
|
if (playerJsCode == null) {
|
||||||
= YoutubeJavaScriptExtractor.extractJavaScriptCode(videoId);
|
playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptCode(videoId);
|
||||||
|
|
||||||
decryptFunctionName = parseDecodeFunctionName(playerJsCode);
|
decryptFunctionName = parseDecodeFunctionName(playerJsCode);
|
||||||
decryptFunction = parseDecodeFunction(playerJsCode, decryptFunctionName);
|
decryptFunction = parseDecodeFunction(playerJsCode, decryptFunctionName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (decryptFunction == null || decryptFunctionName == null) {
|
||||||
|
throw new ParsingException("The decryption function was not parsed correctly");
|
||||||
|
}
|
||||||
|
|
||||||
final String oldNParam = parseNParam(streamingUrl);
|
final String oldNParam = parseNParam(streamingUrl);
|
||||||
final String newNParam = decryptNParam(decryptFunction, decryptFunctionName, oldNParam);
|
final String newNParam = decryptNParam(decryptFunction, decryptFunctionName, oldNParam);
|
||||||
|
|
Loading…
Reference in New Issue