3333 */
3434public class YoutubeThrottlingDecrypter {
3535
36- private static final String N_PARAM_REGEX = "[&?]n=([^&]+)" ;
36+ private static final Pattern N_PARAM_PATTERN = Pattern .compile ("[&?]n=([^&]+)" );
37+ private static final Pattern FUNCTION_NAME_PATTERN = Pattern .compile (
38+ "b=a\\ .get\\ (\" n\" \\ )\\ )&&\\ (b=(\\ w+)\\ (b\\ ),a\\ .set\\ (\" n\" ,b\\ )" );
39+
3740 private static final Map <String , String > nParams = new HashMap <>();
3841
3942 private final String functionName ;
@@ -62,9 +65,7 @@ public YoutubeThrottlingDecrypter() throws ParsingException {
6265
6366 private String parseDecodeFunctionName (final String playerJsCode )
6467 throws Parser .RegexException {
65- Pattern pattern = Pattern .compile (
66- "b=a\\ .get\\ (\" n\" \\ )\\ )&&\\ (b=(\\ w+)\\ (b\\ ),a\\ .set\\ (\" n\" ,b\\ )" );
67- return Parser .matchGroup1 (pattern , playerJsCode );
68+ return Parser .matchGroup1 (FUNCTION_NAME_PATTERN , playerJsCode );
6869 }
6970
7071 @ Nonnull
@@ -86,12 +87,11 @@ public String apply(final String url) throws Parser.RegexException {
8687 }
8788
8889 private boolean containsNParam (final String url ) {
89- return Parser .isMatch (N_PARAM_REGEX , url );
90+ return Parser .isMatch (N_PARAM_PATTERN , url );
9091 }
9192
9293 private String parseNParam (final String url ) throws Parser .RegexException {
93- Pattern nValuePattern = Pattern .compile (N_PARAM_REGEX );
94- return Parser .matchGroup1 (nValuePattern , url );
94+ return Parser .matchGroup1 (N_PARAM_PATTERN , url );
9595 }
9696
9797 private String decryptNParam (final String nParam ) {
0 commit comments