[YouTube] Convert signature timestamp to integer

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.
This commit is contained in:
AudricV 2023-09-16 22:22:09 +02:00
parent 7de3753a81
commit a04bc320de
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
2 changed files with 8 additions and 5 deletions

View File

@ -33,7 +33,7 @@ public final class YoutubeJavaScriptPlayerManager {
private static String cachedJavaScriptPlayerCode;
@Nullable
private static String cachedSignatureTimestamp;
private static Integer cachedSignatureTimestamp;
@Nullable
private static String cachedSignatureDeobfuscationFunction;
@Nullable
@ -76,7 +76,7 @@ public final class YoutubeJavaScriptPlayerManager {
* signature timestamp failed
*/
@Nonnull
public static String getSignatureTimestamp(@Nonnull final String videoId)
public static Integer getSignatureTimestamp(@Nonnull final String videoId)
throws ParsingException {
// Return the cached result if it is present
if (cachedSignatureTimestamp != null) {
@ -93,12 +93,15 @@ public final class YoutubeJavaScriptPlayerManager {
extractJavaScriptCodeIfNeeded(videoId);
try {
cachedSignatureTimestamp = YoutubeSignatureUtils.getSignatureTimestamp(
cachedJavaScriptPlayerCode);
cachedSignatureTimestamp = Integer.valueOf(
YoutubeSignatureUtils.getSignatureTimestamp(cachedJavaScriptPlayerCode));
} catch (final ParsingException e) {
// Store the exception for future calls of this method, in order to improve performance
sigTimestampExtractionEx = e;
throw e;
} catch (final NumberFormatException e) {
sigTimestampExtractionEx =
new ParsingException("Could not convert signature timestamp to a number", e);
}
return cachedSignatureTimestamp;

View File

@ -1419,7 +1419,7 @@ public final class YoutubeParsingHelper {
@Nonnull final Localization localization,
@Nonnull final ContentCountry contentCountry,
@Nonnull final String videoId,
@Nonnull final String sts,
@Nonnull final Integer sts,
final boolean isTvHtml5DesktopJsonBuilder,
@Nonnull final String contentPlaybackNonce) throws IOException, ExtractionException {
// @formatter:off