From a9174f6b9f2b15ff7f7b5037a47b077313c61f3e Mon Sep 17 00:00:00 2001 From: Abdu Ameen Date: Mon, 31 Jan 2022 22:29:00 -0800 Subject: [PATCH 1/3] Changed the regex to account for nonword characters --- .../extractor/services/youtube/YoutubeThrottlingDecrypter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3ba8e2dad..9b154f008 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 @@ -36,7 +36,7 @@ public class YoutubeThrottlingDecrypter { private static final Pattern N_PARAM_PATTERN = Pattern.compile("[&?]n=([^&]+)"); private static final Pattern FUNCTION_NAME_PATTERN = Pattern.compile( - "b=a\\.get\\(\"n\"\\)\\)&&\\(b=(\\w+)\\(b\\),a\\.set\\(\"n\",b\\)"); + "b=a\\.get\\(\"n\"\\)\\)&&\\(b=(\\S+)\\(b\\),a\\.set\\(\"n\",b\\)"); private static final Map nParams = new HashMap<>(); From 50a4b026f8e9755b0e51eed07516babbf988e8a0 Mon Sep 17 00:00:00 2001 From: Abdu Ameen Date: Mon, 31 Jan 2022 23:52:31 -0800 Subject: [PATCH 2/3] Adding removal of the braces --- .../youtube/YoutubeThrottlingDecrypter.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 9b154f008..48a8f64d2 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 @@ -66,7 +66,19 @@ public class YoutubeThrottlingDecrypter { private String parseDecodeFunctionName(final String playerJsCode) throws Parser.RegexException { - return Parser.matchGroup1(FUNCTION_NAME_PATTERN, playerJsCode); + String functionName = Parser.matchGroup1(FUNCTION_NAME_PATTERN, playerJsCode); + int arrayStartBrace = functionName.indexOf("["); + + if (arrayStartBrace > 0) { + String arrayVarName = functionName.substring(0, arrayStartBrace); + String order = functionName.substring(arrayStartBrace+1, functionName.indexOf("]")); + int arrayNum = Integer.parseInt(order); + Pattern ARRAY_PATTERN = Pattern.compile(String.format("var %s=\\[(.+?)\\];", arrayVarName)); + String arrayStr = Parser.matchGroup1(ARRAY_PATTERN, playerJsCode); + String names[] = arrayStr.split(","); + functionName = names[arrayNum]; + } + return functionName; } @Nonnull From 047d75a4c97dbdfd275320efd00424f4b6cbe687 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 1 Feb 2022 12:56:47 +0100 Subject: [PATCH 3/3] Improve code style --- .../youtube/YoutubeThrottlingDecrypter.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 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 48a8f64d2..21925392a 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 @@ -67,15 +67,17 @@ public class YoutubeThrottlingDecrypter { private String parseDecodeFunctionName(final String playerJsCode) throws Parser.RegexException { String functionName = Parser.matchGroup1(FUNCTION_NAME_PATTERN, playerJsCode); - int arrayStartBrace = functionName.indexOf("["); + final int arrayStartBrace = functionName.indexOf("["); if (arrayStartBrace > 0) { - String arrayVarName = functionName.substring(0, arrayStartBrace); - String order = functionName.substring(arrayStartBrace+1, functionName.indexOf("]")); - int arrayNum = Integer.parseInt(order); - Pattern ARRAY_PATTERN = Pattern.compile(String.format("var %s=\\[(.+?)\\];", arrayVarName)); - String arrayStr = Parser.matchGroup1(ARRAY_PATTERN, playerJsCode); - String names[] = arrayStr.split(","); + final String arrayVarName = functionName.substring(0, arrayStartBrace); + final String order = functionName.substring( + arrayStartBrace + 1, functionName.indexOf("]")); + final int arrayNum = Integer.parseInt(order); + final Pattern arrayPattern = Pattern.compile( + String.format("var %s=\\[(.+?)\\];", arrayVarName)); + final String arrayStr = Parser.matchGroup1(arrayPattern, playerJsCode); + final String[] names = arrayStr.split(","); functionName = names[arrayNum]; } return functionName; @@ -99,15 +101,15 @@ public class YoutubeThrottlingDecrypter { @Nonnull private String parseWithRegex(final String playerJsCode, final String functionName) throws Parser.RegexException { - Pattern functionPattern = Pattern.compile(functionName + "=function(.*?}};)\n", + final Pattern functionPattern = Pattern.compile(functionName + "=function(.*?}};)\n", Pattern.DOTALL); return "function " + functionName + Parser.matchGroup1(functionPattern, playerJsCode); } public String apply(final String url) throws Parser.RegexException { if (containsNParam(url)) { - String oldNParam = parseNParam(url); - String newNParam = decryptNParam(oldNParam); + final String oldNParam = parseNParam(url); + final String newNParam = decryptNParam(oldNParam); return replaceNParam(url, oldNParam, newNParam); } else { return url;