Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YouTube] Fixes for n param deobfuscation function #1253

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

gechoto
Copy link

@gechoto gechoto commented Dec 29, 2024

Fixes #1252

Changes:

  • new regex for extracting the name of the n param deobfuscation function

  • added fixup for the n param deobfuscation functions code to prevent an early return

  • I carefully read the contribution guidelines and agree to them.

  • I have tested the API against NewPipe.

  • I agree to create a pull request for NewPipe as soon as possible to make it compatible with the changed API.

@ShareASmile ShareASmile added bug Issue is related to a bug youtube service, https://www.youtube.com/ labels Dec 29, 2024
Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines +52 to +57
// Pattern.compile(SINGLE_CHAR_VARIABLE_REGEX + "=\"nn\"\\[\\+" + MULTIPLE_CHARS_REGEX
// + "\\." + MULTIPLE_CHARS_REGEX + "]," + MULTIPLE_CHARS_REGEX + "\\("
// + MULTIPLE_CHARS_REGEX + "\\)," + MULTIPLE_CHARS_REGEX + "="
// + MULTIPLE_CHARS_REGEX + "\\." + MULTIPLE_CHARS_REGEX + "\\["
// + MULTIPLE_CHARS_REGEX + "]\\|\\|null\\).+\\|\\|(" + MULTIPLE_CHARS_REGEX
// + ")\\(\"\"\\)"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the previous regex? It's better if you keep it, so in case YouTube reverts something it's already there and it works.

Copy link
Author

@gechoto gechoto Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.

This pattern is prone to find wrong functions.
Imagine this:

  • NewPipeExtractor searches for the n deobfuscation function
  • the first regex doesn't work so it uses the second one (the one I commented out)
  • the (commented out) regex finds the wrong function
  • NewPipeExtractor runs the wrong function and gets the wrong n parameter
  • User gets 403
  • No exception is thrown in NewPipeExtractor so it is harder to find the correct place which needs fixing

2.

The regex which comes after the one commented out already finds a very similar pattern, only different groups and more specific.
In this example:

a.D&&(b="nn"[+a.D],WL(a),c=a.j[b]||null)&&(c=SDa[0](c),a.set(b,c),SDa.length||Wma("")

Looking at different versions of the player code it seems more often correct to use the function which is in SDa[0] but using Wma in this case would find the wrong function in newer versions.

Going for SDa[0] (and searching for what is in the array afterwards) seems more robust across multiple versions. The next regex already catches that.

From what I have seen I think if the regex which I commented out is added back in it should be swapped with the next one to hopefully prevent false positives more often.

(Also it might be a good idea to add some additional checks to validate it found the correct function but I consider this out of scope for this PR.)

But I have to say I'm very new to this YT/NewPipeExtractor stuff and only looked at some but not all player version so I might lack some experience with YTs past which means I might be wrong. I can only talk about what I have seen so far so if you know better feel free to correct me.

My suggestion for now:
I will add it back in but swap it with the next one.
What do you think?

@@ -214,4 +237,17 @@ private static String validateFunction(@Nonnull final String function) {
JavaScript.compileOrThrow(function);
return function;
}

@Nonnull
private static String fixupFunction(@Nonnull final String function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmh, this function is specific to the new player code, right? Maybe it would be best to return the original function if the regexes don't find anything.

Also, could you add a comment explaining what fixupFunction does with an example?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current code is fine because:

  • The first regex just finds the functions parameters. A function in JS always follows the same pattern so this regex should never fail.
  • The second regex is used with replaceFirst of the Matcher. replaceFirst already checks if the pattern was found and just returns the input if it wasn't found so this already does what you described.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment is added now

@gechoto gechoto requested a review from Stypox December 31, 2024 15:56
@Figim
Copy link

Figim commented Dec 31, 2024

Does this PR fix the http 403 error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is related to a bug youtube service, https://www.youtube.com/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not find throttling deobfuscation function
4 participants