[YouTube] Fix throttling parameter decryption function regex
- Quote the function name, as it may contain special regex symbols, such as dollar; - Support multiple lines; - Use what looks like the end of the function for the end of the regex (this part is inspired from yt-dlp throttling parameter decryption regex); - Move the throttling function body regex into a private and static constant.
This commit is contained in:
parent
7244be7627
commit
abcee87167
|
@ -40,6 +40,12 @@ public final class YoutubeThrottlingDecrypter {
|
||||||
private static final Pattern DECRYPT_FUNCTION_NAME_PATTERN = Pattern.compile(
|
private static final Pattern DECRYPT_FUNCTION_NAME_PATTERN = Pattern.compile(
|
||||||
"\\.get\\(\"n\"\\)\\)&&\\(b=([a-zA-Z0-9$]+)(?:\\[(\\d+)])?\\([a-zA-Z0-9]\\)");
|
"\\.get\\(\"n\"\\)\\)&&\\(b=([a-zA-Z0-9$]+)(?:\\[(\\d+)])?\\([a-zA-Z0-9]\\)");
|
||||||
|
|
||||||
|
// Escape the curly end brace to allow compatibility with Android's regex engine
|
||||||
|
// See https://stackoverflow.com/q/45074813
|
||||||
|
@SuppressWarnings("RegExpRedundantEscape")
|
||||||
|
private static final String DECRYPT_FUNCTION_BODY_REGEX =
|
||||||
|
"=\\s*function([\\S\\s]*?\\}\\s*return [\\w$]+?\\.join\\(\"\"\\)\\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 decryptFunction;
|
private static String decryptFunction;
|
||||||
private static String decryptFunctionName;
|
private static String decryptFunctionName;
|
||||||
|
@ -128,11 +134,9 @@ public final class YoutubeThrottlingDecrypter {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static String parseWithRegex(final String playerJsCode, final String functionName)
|
private static String parseWithRegex(final String playerJsCode, final String functionName)
|
||||||
throws Parser.RegexException {
|
throws Parser.RegexException {
|
||||||
// Escape the curly end brace to allow compatibility with Android's regex engine
|
// Quote the function name, as it may contain special regex characters such as dollar
|
||||||
// See https://stackoverflow.com/q/45074813
|
final Pattern functionPattern = Pattern.compile(
|
||||||
//noinspection RegExpRedundantEscape
|
Pattern.quote(functionName) + DECRYPT_FUNCTION_BODY_REGEX, Pattern.DOTALL);
|
||||||
final Pattern functionPattern = Pattern.compile(functionName + "=function(.*?\\};)\n",
|
|
||||||
Pattern.DOTALL);
|
|
||||||
return validateFunction("function "
|
return validateFunction("function "
|
||||||
+ functionName
|
+ functionName
|
||||||
+ Parser.matchGroup1(functionPattern, playerJsCode));
|
+ Parser.matchGroup1(functionPattern, playerJsCode));
|
||||||
|
|
Loading…
Reference in New Issue