diff --git a/package-lock.json b/package-lock.json index 6e4ea4f3..4917de2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "set-cookie-parser": "2.6.0", "undici": "^5.19.1", "url-pattern": "1.0.3", - "youtubei.js": "^9.3.0" + "youtubei.js": "^10.1.0" }, "engines": { "node": ">=18" @@ -73,9 +73,9 @@ } }, "node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "bin": { "acorn": "bin/acorn" }, @@ -683,9 +683,9 @@ } }, "node_modules/jintr": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/jintr/-/jintr-1.1.0.tgz", - "integrity": "sha512-Tu9wk3BpN2v+kb8yT6YBtue+/nbjeLFv4vvVC4PJ7oCidHKbifWhvORrAbQfxVIQZG+67am/mDagpiGSVtvrZg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/jintr/-/jintr-2.0.0.tgz", + "integrity": "sha512-RiVlevxttZ4eHEYB2dXKXDXluzHfRuw0DJQGsYuKCc5IvZj5/GbOakeqVX+Bar/G9kTty9xDJREcxukurkmYLA==", "funding": [ "https://github.com/sponsors/LuanRT" ], @@ -1123,14 +1123,14 @@ } }, "node_modules/youtubei.js": { - "version": "9.4.0", - "resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-9.4.0.tgz", - "integrity": "sha512-8plCOZD2WabqWSEgZU3RjzigIIeR7sF028EERJENYrC9xO/6awpLMZfeoE1gNrNEbKcA+bzbMvonqlvBdxGdKg==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-10.1.0.tgz", + "integrity": "sha512-MokZMAnpWH11VYvWuW6qjPiiPmgRl5rfDgPQOpif9qXcVHoVw1hi8ePuRSD0AZSZ+uvWGe8rvas2dzp+Jv5JKQ==", "funding": [ "https://github.com/sponsors/LuanRT" ], "dependencies": { - "jintr": "^1.1.0", + "jintr": "^2.0.0", "tslib": "^2.5.0", "undici": "^5.19.1" } diff --git a/package.json b/package.json index 75c8228c..bcba1894 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "set-cookie-parser": "2.6.0", "undici": "^5.19.1", "url-pattern": "1.0.3", - "youtubei.js": "^9.3.0" + "youtubei.js": "^10.1.0" }, "optionalDependencies": { "freebind": "^0.2.2" diff --git a/src/modules/processing/services/youtube.js b/src/modules/processing/services/youtube.js index 1c86b4ed..b3a405e7 100644 --- a/src/modules/processing/services/youtube.js +++ b/src/modules/processing/services/youtube.js @@ -28,20 +28,24 @@ const transformSessionData = (cookie) => { if (!cookie) return; - const values = cookie.values(); + const values = { ...cookie.values() }; const REQUIRED_VALUES = [ 'access_token', 'refresh_token', - 'client_id', 'client_secret', - 'expires' + 'client_id', 'client_secret' ]; if (REQUIRED_VALUES.some(x => typeof values[x] !== 'string')) { return; } - return { - ...values, - expires: new Date(values.expires), - }; + + if (values.expires) { + values.expiry_date = values.expires; + delete values.expires; + } else if (!values.expiry_date) { + return; + } + + return values; } const cloneInnertube = async (customFetch) => { @@ -70,14 +74,19 @@ const cloneInnertube = async (customFetch) => { } if (session.logged_in) { - await session.oauth.refreshIfRequired(); - const oldExpiry = new Date(cookie.values().expires); - const newExpiry = session.oauth.credentials.expires; + if (session.oauth.shouldRefreshToken()) { + await session.oauth.refreshAccessToken(); + } + + const cookieValues = cookie.values(); + const oldExpiry = new Date(cookieValues.expiry_date); + const newExpiry = new Date(session.oauth.oauth2_tokens.expiry_date); if (oldExpiry.getTime() !== newExpiry.getTime()) { updateCookieValues(cookie, { - ...session.oauth.credentials, - expires: session.oauth.credentials.expires.toISOString() + ...session.oauth.client_id, + ...session.oauth.oauth2_tokens, + expiry_date: newExpiry.toISOString() }); } }