From a04bc320de603d96e4f2949b67562066a183019f Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sat, 16 Sep 2023 22:22:09 +0200 Subject: [PATCH] [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. --- .../youtube/YoutubeJavaScriptPlayerManager.java | 11 +++++++---- .../services/youtube/YoutubeParsingHelper.java | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeJavaScriptPlayerManager.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeJavaScriptPlayerManager.java index 7ddfdb193..f83cf203b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeJavaScriptPlayerManager.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeJavaScriptPlayerManager.java @@ -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; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 1bce2c2f8..9e6373528 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -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