Skip to content

Commit a04bc32

Browse files
committed
[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.
1 parent 7de3753 commit a04bc32

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeJavaScriptPlayerManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public final class YoutubeJavaScriptPlayerManager {
3333
private static String cachedJavaScriptPlayerCode;
3434

3535
@Nullable
36-
private static String cachedSignatureTimestamp;
36+
private static Integer cachedSignatureTimestamp;
3737
@Nullable
3838
private static String cachedSignatureDeobfuscationFunction;
3939
@Nullable
@@ -76,7 +76,7 @@ private YoutubeJavaScriptPlayerManager() {
7676
* signature timestamp failed
7777
*/
7878
@Nonnull
79-
public static String getSignatureTimestamp(@Nonnull final String videoId)
79+
public static Integer getSignatureTimestamp(@Nonnull final String videoId)
8080
throws ParsingException {
8181
// Return the cached result if it is present
8282
if (cachedSignatureTimestamp != null) {
@@ -93,12 +93,15 @@ public static String getSignatureTimestamp(@Nonnull final String videoId)
9393
extractJavaScriptCodeIfNeeded(videoId);
9494

9595
try {
96-
cachedSignatureTimestamp = YoutubeSignatureUtils.getSignatureTimestamp(
97-
cachedJavaScriptPlayerCode);
96+
cachedSignatureTimestamp = Integer.valueOf(
97+
YoutubeSignatureUtils.getSignatureTimestamp(cachedJavaScriptPlayerCode));
9898
} catch (final ParsingException e) {
9999
// Store the exception for future calls of this method, in order to improve performance
100100
sigTimestampExtractionEx = e;
101101
throw e;
102+
} catch (final NumberFormatException e) {
103+
sigTimestampExtractionEx =
104+
new ParsingException("Could not convert signature timestamp to a number", e);
102105
}
103106

104107
return cachedSignatureTimestamp;

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ public static byte[] createDesktopPlayerBody(
14191419
@Nonnull final Localization localization,
14201420
@Nonnull final ContentCountry contentCountry,
14211421
@Nonnull final String videoId,
1422-
@Nonnull final String sts,
1422+
@Nonnull final Integer sts,
14231423
final boolean isTvHtml5DesktopJsonBuilder,
14241424
@Nonnull final String contentPlaybackNonce) throws IOException, ExtractionException {
14251425
// @formatter:off

0 commit comments

Comments
 (0)