mirror of
https://github.com/TeamNewPipe/NewPipeExtractor
synced 2025-08-29 13:27:38 +00:00
Merge pull request #1330 from litetex/speed-up-n-parameter-extraction
[YouTube] Speed up n parameter presence check
This commit is contained in:
commit
c0ff21af93
@ -18,6 +18,8 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
final class YoutubeThrottlingParameterUtils {
|
final class YoutubeThrottlingParameterUtils {
|
||||||
|
|
||||||
|
// NOTE: When changing this you should also change the quick exit/shortcut
|
||||||
|
// in getThrottlingParameterFromStreamingUrl
|
||||||
private static final Pattern THROTTLING_PARAM_PATTERN = Pattern.compile("[&?]n=([^&]+)");
|
private static final Pattern THROTTLING_PARAM_PATTERN = Pattern.compile("[&?]n=([^&]+)");
|
||||||
|
|
||||||
private static final String SINGLE_CHAR_VARIABLE_REGEX = "[a-zA-Z0-9$_]";
|
private static final String SINGLE_CHAR_VARIABLE_REGEX = "[a-zA-Z0-9$_]";
|
||||||
@ -203,6 +205,11 @@ final class YoutubeThrottlingParameterUtils {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
static String getThrottlingParameterFromStreamingUrl(@Nonnull final String streamingUrl) {
|
static String getThrottlingParameterFromStreamingUrl(@Nonnull final String streamingUrl) {
|
||||||
|
// Do a quick check if the n parameter is even present, if not abort
|
||||||
|
// This improves performance by 60-900x
|
||||||
|
if (!streamingUrl.contains("&n=") && !streamingUrl.contains("?n=")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return Parser.matchGroup1(THROTTLING_PARAM_PATTERN, streamingUrl);
|
return Parser.matchGroup1(THROTTLING_PARAM_PATTERN, streamingUrl);
|
||||||
} catch (final Parser.RegexException e) {
|
} catch (final Parser.RegexException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user