Skip to content

Commit c0ff21a

Browse files
authored
Merge pull request TeamNewPipe#1330 from litetex/speed-up-n-parameter-extraction
[YouTube] Speed up n parameter presence check
2 parents ebb53fb + 0dfaeb2 commit c0ff21a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingParameterUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
final class YoutubeThrottlingParameterUtils {
2020

21+
// NOTE: When changing this you should also change the quick exit/shortcut
22+
// in getThrottlingParameterFromStreamingUrl
2123
private static final Pattern THROTTLING_PARAM_PATTERN = Pattern.compile("[&?]n=([^&]+)");
2224

2325
private static final String SINGLE_CHAR_VARIABLE_REGEX = "[a-zA-Z0-9$_]";
@@ -203,6 +205,11 @@ static String getDeobfuscationFunction(@Nonnull final String javaScriptPlayerCod
203205
*/
204206
@Nullable
205207
static String getThrottlingParameterFromStreamingUrl(@Nonnull final String streamingUrl) {
208+
// Do a quick check if the n parameter is even present, if not abort
209+
// This improves performance by 60-900x
210+
if (!streamingUrl.contains("&n=") && !streamingUrl.contains("?n=")) {
211+
return null;
212+
}
206213
try {
207214
return Parser.matchGroup1(THROTTLING_PARAM_PATTERN, streamingUrl);
208215
} catch (final Parser.RegexException e) {

0 commit comments

Comments
 (0)