|
5 | 5 | import org.schabi.newpipe.extractor.utils.Parser; |
6 | 6 | import org.schabi.newpipe.extractor.utils.StringUtils; |
7 | 7 |
|
8 | | -import javax.annotation.Nonnull; |
9 | 8 | import java.util.HashMap; |
10 | 9 | import java.util.Map; |
11 | 10 | import java.util.regex.Matcher; |
12 | 11 | import java.util.regex.Pattern; |
13 | 12 |
|
| 13 | +import javax.annotation.Nonnull; |
| 14 | + |
14 | 15 | /** |
15 | 16 | * YouTube's streaming URLs of HTML5 clients are protected with a cipher, which modifies their |
16 | 17 | * {@code n} query parameter. |
@@ -154,16 +155,25 @@ private static String parseDecodeFunction(final String playerJsCode, final Strin |
154 | 155 | private static String parseWithParenthesisMatching(final String playerJsCode, |
155 | 156 | final String functionName) { |
156 | 157 | final String functionBase = functionName + "=function"; |
157 | | - return functionBase + StringUtils.matchToClosingParenthesis(playerJsCode, functionBase) |
158 | | - + ";"; |
| 158 | + return validateFunction(functionBase |
| 159 | + + StringUtils.matchToClosingParenthesis(playerJsCode, functionBase) |
| 160 | + + ";"); |
159 | 161 | } |
160 | 162 |
|
161 | 163 | @Nonnull |
162 | 164 | private static String parseWithRegex(final String playerJsCode, final String functionName) |
163 | 165 | throws Parser.RegexException { |
164 | 166 | final Pattern functionPattern = Pattern.compile(functionName + "=function(.*?};)\n", |
165 | 167 | Pattern.DOTALL); |
166 | | - return "function " + functionName + Parser.matchGroup1(functionPattern, playerJsCode); |
| 168 | + return validateFunction("function " |
| 169 | + + functionName |
| 170 | + + Parser.matchGroup1(functionPattern, playerJsCode)); |
| 171 | + } |
| 172 | + |
| 173 | + @Nonnull |
| 174 | + private static String validateFunction(@Nonnull final String function) { |
| 175 | + JavaScript.compileOrThrow(function); |
| 176 | + return function; |
167 | 177 | } |
168 | 178 |
|
169 | 179 | @Deprecated |
|
0 commit comments