-
Notifications
You must be signed in to change notification settings - Fork 422
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] Refactor JavaScript usage and fix extraction of obfuscated signature deobfuscation function #1108
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! The code is so much better and well organized. I pointed out a few small things I notices
.../main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeJavaScriptPlayerManager.java
Outdated
Show resolved
Hide resolved
...actor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSignatureUtils.java
Outdated
Show resolved
Hide resolved
...actor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSignatureUtils.java
Show resolved
Hide resolved
...actor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSignatureUtils.java
Outdated
Show resolved
Hide resolved
...g/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingParameterDeobfuscationTest.java
Outdated
Show resolved
Hide resolved
…uscation function extraction The goal of this class is to decouple the extraction of signature timestamp and signature deobfuscation function from YoutubeStreamExtractor. The extraction of the signature deobfuscation function has been also adapted to support the latest YouTube player versions. This new class, YoutubeSignatureUtils, doens't store anything temporary such as a copy of the player code, which has to be passed where required. It is not public, as it will be used by a JavaScript player manager class in the future, in order to handle in a better way fetching, caching and resetting cache of the player code.
This commit is introducing breaking changes. For clients, everything is managed in a new class called YoutubeJavaScriptPlayerManager: - caching JavaScript base player code and its extracted code (functions and variables); - getting player signature timestamp; - getting deobfuscated signatures of streaming URLs; - getting streaming URLs with a throttling parameter deobfuscated, if applicable. The class delegates the extraction parts to external package-private classes: - YoutubeJavaScriptExtractor, to extract and download YouTube's JavaScript base player code: it always already present before and has been edited to mainly remove the previous caching system and made it package-private; - YoutubeSignatureUtils, for player signature timestamp and signature deobfuscation function of streaming URLs, added in a recent commit; - YoutubeThrottlingParameterUtils, which was originally YoutubeThrottlingDecrypter, for throttling parameter of streaming URLs deobfuscation function and checking whether this parameter is in a streaming URL. YoutubeJavaScriptPlayerManager caches and then runs the extracted code if it has been executed successfully. The cache system of throttling parameters deobfuscated values has been kept, its size can be get using the getThrottlingParametersCacheSize method and can be cleared independently using the clearThrottlingParametersCache method. If an exception occurs during the extraction or the parsing of a function property which is not related to JavaScript base player code fetching, it is stored until caches are cleared, making subsequent failing extraction calls of the requested function or property faster and consuming less resources, as the result should be the same until the base player code changes. All caches can be reset using the clearAllCaches method of YoutubeJavaScriptPlayerManager. Classes using JavaScript base player code and utilities directly (in the code and its tests) have been also updated in this commit.
The signature timestamp is used as a number by HTML5 clients, so it should be used in the same way by the extractor too instead of being a string. As the timestamp doesn't seem to exceed 5 digits, an integer is used to store its value.
…deobfuscation function extraction and execution
…on only where needed
63aec71
to
6ed2209
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I can confirm it works, I tested in NewPipe |
This PR refactors the usage of YouTube's JavaScript base player file in the extractor.
It makes a single public class handling operations and caches of this file,
YoutubeJavaScriptPlayerManager
, instead of being split in multiple files with questionable designs (such as the one of the deobfuscation function for obfuscated signatures of streaming URLs from HTML5 clients inYoutubeStreamExtractor
).Extraction and parsing parts are delegated to different package-private classes:
YoutubeJavaScriptExtractor
, handling the extraction of JavaScript's base player file;YoutubeThrottlingParameterUtils
, handling the extraction of throttling parameter of streaming URLs from HTML5's clients and the detection of this parameter for a given streaming URL;YoutubeSignatureUtils
, handling the extraction of the signature timestamp property and the deobfuscation function for obfuscated signatures of streaming URLs from HTML5 clients.Each extraction process has now a corresponding test.
It also improves the code on the fly, fixes the extraction of the deobfuscation function for obfuscated signatures, and makes use of a number when sending the signature timestamp in InnerTube's player requests instead of a string, in order to be consistent with HTML5 clients.
This PR introduces important breaking changes:
YoutubeJavaScriptExtractor
is not public anymore, the extraction of YouTube's JavaScript base player file isn't intended to be used outside of the extractor;resetDeobfuscationCode
method ofYoutubeStreamExtractor
has been removed. Use the methodclearAllCaches
ofYoutubeJavaScriptPlayerManager
instead, which also clears other cached data;YoutubeThrottlingDecrypter
has been renamed toYoutubeThrottlingParameterUtils
, which is a package-private class and the methodsgetCacheSize
andclearCache
have been removed. Use respectivelygetThrottlingParametersCacheSize
andclearThrottlingParametersCache
methods ofYoutubeJavaScriptPlayerManager
instead.DeobfuscateException
nested exception class inYoutubeStreamExtractor
has been removed. A standardParsingException
will be thrown when the deobfuscation function couldn't be parsed or executed instead.Fixes TeamNewPipe/NewPipe#10347.