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] Fix division #7279

Merged
merged 2 commits into from Jun 10, 2023
Merged

[jsinterp] Fix division #7279

merged 2 commits into from Jun 10, 2023

Conversation

bashonly
Copy link
Member

@bashonly bashonly commented Jun 10, 2023

Fixes failing nsig decryption for new YT JS player 8c7583ff

See ytdl-org/youtube-dl#32292

Zero divided by any non-zero number was returning NaN

[debug] JS:                     c[new Date("1970-01-01T09:15:00.000+09:15")/1E3]
[debug] JS:                       new Date("1970-01-01T09:15:00.000+09:15")/1E3
[debug] JS:                         "1970-01-01T09:15:00.000+09:15"
[debug] JS:                         -> '1970-01-01T09:15:00.000+09:15' <-| "1970-01-01T09:15:00.000+09:15"
[debug] JS:                         0
[debug] JS:                         1E3
[debug] JS:                         -> 1000.0 <-| 1E3
[debug] JS:                       -> nan <-| new Date("1970-01-01T09:15:00.000+09:15")/1E3
[debug] JS:                     => Raises: Cannot get index nan in: [F<247>, -1658198590, ..., -1183556064, -705166834, -1680476002, 208789974] <-| c[new Date("1970-01-01T09:15:00.000+09:15")/1E3]
Template

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check all of the following options that apply:

  • I am the original author of this code and I am willing to release it under Unlicense
  • 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?

Copilot Summary

πŸ€– Generated by Copilot at 50405ed

Summary

πŸ§ͺπŸ›βž—

Fix JavaScript division operator in yt_dlp/jsinterp.py and add a test case in test/test_jsinterp.py to verify its behavior.

_js_div fixed
Zero division bug no more
Autumn tests pass now

Walkthrough

  • Fix JavaScript division operator / to return inf or -inf when dividing by zero, instead of nan (link)
  • Add test case for JavaScript division operator / with different values, such as zero, undefined, and infinity (link)
  • Use JSInterpreter class from yt_dlp/jsinterp.py to evaluate and call a simple JavaScript function that performs division in the test case (link)
  • Assert that the results match the expected values according to the JavaScript specification in the test case (link)

@coletdjnz
Copy link
Member

Add a nsig test for player 8c7583ff too (in test_YouTube_signature)

@bashonly bashonly merged commit b4a252f into yt-dlp:master Jun 10, 2023
11 checks passed
@bashonly bashonly deleted the fix/jsi-div branch July 2, 2023 16:39
aalsuwaidi pushed a commit to aalsuwaidi/yt-dlp that referenced this pull request Apr 21, 2024
* Fixes nsig decryption for Youtube JS player `8c7583ff`

Authored by: bashonly
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.

None yet

2 participants