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

View File

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