From 6312e97f955b3b116a52fc9d41358661dd13ac2e Mon Sep 17 00:00:00 2001 From: LuanRT Date: Sun, 15 May 2022 21:49:28 -0300 Subject: [PATCH] chore: use timestamp in seconds for `visitorData` YouTube also accepts timestamps in milliseconds, but since all clients generate visitorData with timestamps in seconds then the library should do the same. --- lib/core/SessionBuilder.js | 2 +- lib/proto/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/SessionBuilder.js b/lib/core/SessionBuilder.js index 0f2103a2..e6ec0890 100644 --- a/lib/core/SessionBuilder.js +++ b/lib/core/SessionBuilder.js @@ -44,7 +44,7 @@ class SessionBuilder { const user_agent = new UserAgent({ deviceCategory: 'desktop' }); const id = Utils.generateRandomString(11); - const timestamp = new Date().getTime(); + const timestamp = Math.floor(Date.now() / 1000); const visitor_data = Proto.encodeVisitorData(id, timestamp); diff --git a/lib/proto/index.js b/lib/proto/index.js index 9fe87e82..cf96d8b8 100644 --- a/lib/proto/index.js +++ b/lib/proto/index.js @@ -13,7 +13,7 @@ class Proto { */ static encodeVisitorData(id, timestamp) { const buf = messages.VisitorData.encode({ id, timestamp }); - return encodeURIComponent(Buffer.from(buf).toString('base64')); + return encodeURIComponent(Buffer.from(buf).toString('base64').replace(/\//g, '_')); } /**