Class YoutubeJavaScriptPlayerManager
- java.lang.Object
-
- org.schabi.newpipe.extractor.services.youtube.YoutubeJavaScriptPlayerManager
-
public final class YoutubeJavaScriptPlayerManager extends java.lang.Object
Manage the extraction and the usage of YouTube's player JavaScript needed data in the YouTube service.YouTube restrict streaming their media in multiple ways by requiring their HTML5 clients to use a signature timestamp, and on streaming URLs a signature deobfuscation function for some contents and a throttling parameter deobfuscation one for all contents.
This class provides access to methods which allows to get base JavaScript player's signature timestamp and to deobfuscate streaming URLs' signature and/or throttling parameter of HTML5 clients.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
clearAllCaches()
Clear all caches.static void
clearThrottlingParametersCache()
Clear all cached throttling parameters.static java.lang.String
deobfuscateSignature(java.lang.String videoId, java.lang.String obfuscatedSignature)
Deobfuscate a signature of a streaming URL using its corresponding JavaScript base player's function.static java.lang.Integer
getSignatureTimestamp(java.lang.String videoId)
Get the signature timestamp of the base JavaScript player file.static int
getThrottlingParametersCacheSize()
Get the current cache size of throttling parameters.static java.lang.String
getUrlWithThrottlingParameterDeobfuscated(java.lang.String videoId, java.lang.String streamingUrl)
Return a streaming URL with the throttling parameter of a given one deobfuscated, if it is present, using its corresponding JavaScript base player's function.
-
-
-
Method Detail
-
getSignatureTimestamp
@Nonnull public static java.lang.Integer getSignatureTimestamp(@Nonnull java.lang.String videoId) throws ParsingException
Get the signature timestamp of the base JavaScript player file.A valid signature timestamp sent in the payload of player InnerTube requests is required to get valid stream URLs on HTML5 clients for videos which have obfuscated signatures.
The base JavaScript player file will fetched if it is not already done.
The result of the extraction is cached until
clearAllCaches()
is called, making subsequent calls faster.- Parameters:
videoId
- the video ID used to get the JavaScript base player file (an empty one can be passed, even it is not recommend in order to spoof better official YouTube clients)- Returns:
- the signature timestamp of the base JavaScript player file
- Throws:
ParsingException
- if the extraction of the base JavaScript player file or the signature timestamp failed
-
deobfuscateSignature
@Nonnull public static java.lang.String deobfuscateSignature(@Nonnull java.lang.String videoId, @Nonnull java.lang.String obfuscatedSignature) throws ParsingException
Deobfuscate a signature of a streaming URL using its corresponding JavaScript base player's function.Obfuscated signatures are only present on streaming URLs of some videos with HTML5 clients.
- Parameters:
videoId
- the video ID used to get the JavaScript base player file (an empty one can be passed, even it is not recommend in order to spoof better official YouTube clients)obfuscatedSignature
- the obfuscated signature of a streaming URL- Returns:
- the deobfuscated signature
- Throws:
ParsingException
- if the extraction of the base JavaScript player file or the signature deobfuscation function failed
-
getUrlWithThrottlingParameterDeobfuscated
@Nonnull public static java.lang.String getUrlWithThrottlingParameterDeobfuscated(@Nonnull java.lang.String videoId, @Nonnull java.lang.String streamingUrl) throws ParsingException
Return a streaming URL with the throttling parameter of a given one deobfuscated, if it is present, using its corresponding JavaScript base player's function.The throttling parameter is present on all streaming URLs of HTML5 clients.
If it is not given or deobfuscated, speeds will be throttled to a very slow speed (around 50 KB/s) and some streaming URLs could even lead to invalid HTTP responses such a 403 one.
As throttling parameters can be common between multiple streaming URLs of the same player response, deobfuscated parameters are cached with their obfuscated variant, in order to improve performance with multiple calls of this method having the same obfuscated throttling parameter.
The cache's size can be get using
getThrottlingParametersCacheSize()
and the cache can be cleared usingclearThrottlingParametersCache()
orclearAllCaches()
.- Parameters:
videoId
- the video ID used to get the JavaScript base player file (an empty one can be passed, even it is not recommend in order to spoof better official YouTube clients)streamingUrl
- a streaming URL- Returns:
- the original streaming URL if it has no throttling parameter or a URL with a deobfuscated throttling parameter
- Throws:
ParsingException
- if the extraction of the base JavaScript player file or the throttling parameter deobfuscation function failed
-
getThrottlingParametersCacheSize
public static int getThrottlingParametersCacheSize()
Get the current cache size of throttling parameters.- Returns:
- the current cache size of throttling parameters
-
clearAllCaches
public static void clearAllCaches()
Clear all caches.This method will clear all cached JavaScript code and throttling parameters.
The next time
getSignatureTimestamp(String)
,deobfuscateSignature(String, String)
orgetUrlWithThrottlingParameterDeobfuscated(String, String)
is called, the JavaScript code will be fetched again and the corresponding extraction methods will be ran.
-
clearThrottlingParametersCache
public static void clearThrottlingParametersCache()
Clear all cached throttling parameters.The throttling parameter deobfuscation function will be ran again on these parameters if streaming URLs containing them are passed in the future.
This method doesn't clear the cached throttling parameter deobfuscation function, this can be done using
clearAllCaches()
.
-
-