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

[jsinterp] Overhaul JSInterp to handle new YT players 4c3f79c5, 324f67b9 #31170

Merged
merged 1 commit into from
Aug 14, 2022

Conversation

dirkf
Copy link
Contributor

@dirkf dirkf commented Aug 14, 2022

Boilerplate: mixed code, bug fix ## Please follow the guide below
  • You will be asked some questions, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your pull request (like that [x])
  • Use Preview tab to see how your pull request will actually look like

Before submitting a pull request make sure you have:

In order to be accepted and merged into youtube-dl each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense, except for code from yt-dlp for which either this or the below has been asserted
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

  • Bug fix
  • Improvement
  • New extractor
  • New feature

Description of your pull request and other information

Issue #31164 reported errors with new players served by YouTube. More complex JS constructs confused yt-dl's JSInterp mini-JS interpreter.

Thanks mostly to @pukkandan, this PR fixes the problem code by back-porting from pukkandan/yt-dlp-dev@8f53dc4 into the existing previously back-ported framework.

Additionally:

  • supports void used in player 324f67b9
  • improves <</>> precedence (TODO item in back-ported code), by preventing an operator search for </> from matching the operator with the same first character
  • improves processing of expressions in comma-list expressions, where the last item of a multi-item list wasn't fully processed
  • allows for let, const in case they should appear
  • allows for further comparison operators in case they should appear
  • adds more tests
  • allows for variable in new Date(...)
  • improves argument list parsing and processing.

* back-port from yt-dlp 8f53dc4, thanks pukkandan
* also support void, improve <</>> precedence, improve expressions in comma-list
* add more tests
@dirkf dirkf merged commit d231b56 into ytdl-org:master Aug 14, 2022
github-actions bot added a commit to hellopony/youtube-dl that referenced this pull request Aug 14, 2022
* https://github.com/ytdl-org/youtube-dl:
  [jsinterp] Overhaul JSInterp to handle new YT players 4c3f79c5, 324f67b9 (ytdl-org#31170)
Copy link

@richardcox69 richardcox69 left a comment

Choose a reason for hiding this comment

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

Ok

Comment on lines +364 to +369
if len(sub_expressions) > 1:
for sub_expr in sub_expressions:
ret, should_abort = self.interpret_statement(sub_expr, local_vars, allow_recursion)
if should_abort:
return ret, True
return ret, False
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain to me the reasoning behind this change? All your tests pass in yt-dlp without this

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, I figured it out

Copy link
Contributor Author

@dirkf dirkf Aug 16, 2022

Choose a reason for hiding this comment

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

...the last item of a multi-item list wasn't fully processed

Before: process list, pop last item, continue processing last item instead of list or processing last item from the beginning (where's the goto when you need it!).

Comment on lines +659 to +663
@classmethod
def build_arglist(cls, arg_text):
if not arg_text:
return []
return list(filter(None, (x.strip() or None for x in cls._separate(arg_text))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same. The filter doesn't make sense to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing empty items, but there shouldn't be any:

function fred(a,b,c) {
  return b;
}
fred(1, ,2);
/*
Exception: SyntaxError: expected expression, got ','
@Scratchpad/1:4
*/
function fred(a,,c) {
  return c;
}
/*
Exception: SyntaxError: missing formal parameter
@Scratchpad/1:1
*/

So probably just strip and let it crash elsewhere.

gaming-hacker added a commit to gaming-hacker/youtube-dl that referenced this pull request Aug 16, 2022
* commit 'e52e8b8111cf7ca27daef184bacd926865e951b1':
  [postprocessor] Don't replace existing value with null metadata parsed from title
  [jsinterp] Overhaul JSInterp to handle new YT players 4c3f79c5, 324f67b9 (ytdl-org#31170)
  [core] Make `--max-downloads ...` stop immediately on reaching the limit
  [test, etc] Improve download test logs; also clean up some new flake8 issues (ytdl-org#31153)
  [aenetworks] Update _THEPLATFORM_KEY and _THEPLATFORM_SECRET (ytdl-org#29749)

# Conflicts:
#	test/test_utils.py
#	youtube_dl/jsinterp.py
belamenso pushed a commit to belamenso/youtube-dl that referenced this pull request Sep 19, 2022
…7b9 (ytdl-org#31170)

* back-port from yt-dlp 8f53dc4, thanks pukkandan
* also support void, improve <</>> precedence, improve expressions in comma-list
* add more tests
gaming-hacker added a commit to gaming-hacker/youtube-dl that referenced this pull request Oct 6, 2022
* commit 'b6bfdb25f200ba63ba1b011a54431cb424be46e9': (23 commits)
  [jsinterp] Workaround operator associativity issue * temporary fix for player 5a3b6271 [1]
  [cache] Add cache validation by program version, based on yt-dlp
  [jsinterp] Handle new YT players 113ca41c, c57c113c * add NaN * allow any white-space character for `after_op` * align with yt-dlp f26af78 (charcodeAt and bitwise overflow) * allow escaping in regex, fixing player c57c113c
  [options] Document that postprocessing is not forced by --postprocessor-args
  [compat] Replace deficient ChainMap class in Py3.3 and earlier * fix version check
  [compat] Replace deficient ChainMap class in Py3.3 and earlier
  [jsinterp] Improve try/catch/finally support
  [jsinterp] Fix bug in operator precedence * from yt-dlp/yt-dlp@164b03c * added tests
  [YouTube] Improve error check for n-sig processing
  [core] Avoid processing empty format list after removing bad formats * also ensure compat encoding of error strings
  [utils] Ensure RFC3986 encoding result is unicode
  [infoq] Avoid crash if the page has no `mp3Form`
  [uktvplay] Support domain without .uktv
  [jsinterp] Clean up and pull yt-dlp style * add compat_re_Pattern * improve compat_collections_chain_map * use class JS_Undefined * remove unused code
  [jsinterp] Handle regexp literals and throw/catch execution (ytdl-org#31182)
  [jsinterp] Improve JS language support (ytdl-org#31175)
  [postprocessor] Don't replace existing value with null metadata parsed from title
  [jsinterp] Overhaul JSInterp to handle new YT players 4c3f79c5, 324f67b9 (ytdl-org#31170)
  [core] Make `--max-downloads ...` stop immediately on reaching the limit
  [test, etc] Improve download test logs; also clean up some new flake8 issues (ytdl-org#31153)
  ...
alxlive pushed a commit to alxlive/youtube-dl that referenced this pull request Feb 27, 2023
…7b9 (ytdl-org#31170)

* back-port from yt-dlp 8f53dc4, thanks pukkandan
* also support void, improve <</>> precedence, improve expressions in comma-list
* add more tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[YouTube] When running without --verbose, … (No terminating paren } in {var b=a.split(""),…
3 participants