Merge pull request #1076 from AudricV/yt-fix-throttling-parameter-regex

[YouTube] Support multiple declarations for throttling parameter function name array
This commit is contained in:
Tobi 2023-07-07 12:51:26 +02:00 committed by GitHub
commit d6132a9ed9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -48,6 +48,9 @@ public final class YoutubeThrottlingDecrypter {
private static final String DECRYPT_FUNCTION_BODY_REGEX =
"=\\s*function([\\S\\s]*?\\}\\s*return [\\w$]+?\\.join\\(\"\"\\)\\s*\\};)";
private static final String DECRYPT_FUNCTION_ARRAY_OBJECT_TYPE_DECLARATION_REGEX = "var ";
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 String decryptFunction;
private static String decryptFunctionName;
@ -117,7 +120,8 @@ public final class YoutubeThrottlingDecrypter {
final int arrayNum = Integer.parseInt(matcher.group(2));
final Pattern arrayPattern = Pattern.compile(
"var " + Pattern.quote(functionName) + "\\s*=\\s*\\[(.+?)];");
DECRYPT_FUNCTION_ARRAY_OBJECT_TYPE_DECLARATION_REGEX + Pattern.quote(functionName)
+ FUNCTION_NAMES_IN_DECRYPT_ARRAY_REGEX);
final String arrayStr = Parser.matchGroup1(arrayPattern, playerJsCode);
final String[] names = arrayStr.split(",");
return names[arrayNum];