From efffa5347544db7b47c45a352adfea758dd7f854 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Fri, 13 Dec 2024 22:19:40 +0000 Subject: [PATCH 1/3] Update youtubei.js --- package.json | 2 +- src/youtube_onesie_provider.ts | 49 ++++++++++++++++++++-------------- yarn.lock | 18 ++++++------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index cc5cd94ab..2eda95a68 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "uuid": "^10.0.0", "winston": "^3.14.2", "winston-daily-rotate-file": "^5.0.0", - "youtubei.js": "^10.3.0" + "youtubei.js": "^12.2.0" }, "devDependencies": { "@types/jsdom": "^21.1.7", diff --git a/src/youtube_onesie_provider.ts b/src/youtube_onesie_provider.ts index 25080c1ec..f88f4c18a 100644 --- a/src/youtube_onesie_provider.ts +++ b/src/youtube_onesie_provider.ts @@ -1,4 +1,4 @@ -import { type Context, Endpoints, YT } from "youtubei.js"; +import { Constants, type Context, YT } from "youtubei.js"; import { IPCLogger } from "./logger"; import GoogleVideo, { PART, Protos, QUALITY, base64ToU8 } from "googlevideo"; import Innertube, { UniversalCache } from "youtubei.js"; @@ -108,25 +108,34 @@ export default class YoutubeOnesieProvider { args: OnesieRequestArgs, ): Promise { const { videoId, poToken, clientConfig, innertube } = args; - const { clientKeyData, encryptedClientKey, onesieUstreamerConfig } = - clientConfig; - - const clonedInnerTubeContext: Context = JSON.parse( - JSON.stringify(innertube.session.context), - ); - - // Change or remove these if you want to use a different client. I chose TVHTML5 purely for testing. - clonedInnerTubeContext.client.clientName = "TVHTML5"; - clonedInnerTubeContext.client.clientVersion = "7.20240717.18.00"; - - const playerRequestJson = { - context: clonedInnerTubeContext, - ...Endpoints.PlayerEndpoint.build({ - video_id: videoId, - po_token: poToken, - sts: innertube.session.player?.sts, - }), - }; + const { clientKeyData, encryptedClientKey, onesieUstreamerConfig } = clientConfig; + const clonedInnerTubeContext: Context = structuredClone(innertube.session.context); + + // Change or remove these if you want to use a different client. I chose TVHTML5 purely for testing. + clonedInnerTubeContext.client.clientName = Constants.CLIENTS.TV.NAME; + clonedInnerTubeContext.client.clientVersion = Constants.CLIENTS.TV.VERSION; + + const params: Record = { + playbackContext: { + contentPlaybackContext: { + vis: 0, + splay: false, + lactMilliseconds: '-1', + signatureTimestamp: innertube.session.player?.sts + } + }, + videoId + }; + + if (poToken) { + params.serviceIntegrityDimensions = {}; + params.serviceIntegrityDimensions.poToken = poToken; + } + + const playerRequestJson = { + context: clonedInnerTubeContext, + ...params + }; const headers = [ { diff --git a/yarn.lock b/yarn.lock index 8303fbf39..94aa00fff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2972,10 +2972,10 @@ jest-get-type@^22.4.3: resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4" integrity sha512-/jsz0Y+V29w1chdXVygEKSz2nBoHoYqNShPe+QgxSNjAuP1i8+k4LbQNrfoliKej0P45sivkSCh7yiD6ubHS3w== -jintr@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/jintr/-/jintr-2.1.1.tgz#84d555df06d26128c2a1d0e1eebd6fecdf8eb280" - integrity sha512-89cwX4ouogeDGOBsEVsVYsnWWvWjchmwXBB4kiBhmjOKw19FiOKhNhMhpxhTlK2ctl7DS+d/ethfmuBpzoNNgA== +jintr@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/jintr/-/jintr-3.2.0.tgz#38bfc2311c7ed4412ebe0bfc5c2e700f8f433921" + integrity sha512-psD1yf05kMKDNsUdW1l5YhO59pHScQ6OIHHb8W5SKSM2dCOFPsqolmIuSHgVA8+3Dc47NJR181CXZ4alCAPTkA== dependencies: acorn "^8.8.0" @@ -4945,12 +4945,12 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -youtubei.js@^10.3.0: - version "10.5.0" - resolved "https://registry.yarnpkg.com/youtubei.js/-/youtubei.js-10.5.0.tgz#3cf0c79cf73fb26e13d167f37dec7d65419e91b8" - integrity sha512-iyA+VF28c15tCCKH9ExM2RKC3zYiHzA/eixGlJ3vERANkuI+xYKzAZ4vtOhmyqwrAddu88R/DkzEsmpph5NWjg== +youtubei.js@^12.2.0: + version "12.2.0" + resolved "https://registry.yarnpkg.com/youtubei.js/-/youtubei.js-12.2.0.tgz#54f058b5d0892b5c7e35019e2be6a2a7f7ba4447" + integrity sha512-G+50qrbJCToMYhu8jbaHiS3Vf+RRul+CcDbz3hEGwHkGPh+zLiWwD6SS+YhYF+2/op4ZU5zDYQJrGqJ+wKh7Gw== dependencies: "@bufbuild/protobuf" "^2.0.0" - jintr "^2.1.1" + jintr "^3.2.0" tslib "^2.5.0" undici "^5.19.1" From 121ae05c707031348f64b65c5ad15c88e2e323e7 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Fri, 13 Dec 2024 22:21:35 +0000 Subject: [PATCH 2/3] Prettier --- src/youtube_onesie_provider.ts | 60 ++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/youtube_onesie_provider.ts b/src/youtube_onesie_provider.ts index f88f4c18a..4839e5155 100644 --- a/src/youtube_onesie_provider.ts +++ b/src/youtube_onesie_provider.ts @@ -108,34 +108,38 @@ export default class YoutubeOnesieProvider { args: OnesieRequestArgs, ): Promise { const { videoId, poToken, clientConfig, innertube } = args; - const { clientKeyData, encryptedClientKey, onesieUstreamerConfig } = clientConfig; - const clonedInnerTubeContext: Context = structuredClone(innertube.session.context); - - // Change or remove these if you want to use a different client. I chose TVHTML5 purely for testing. - clonedInnerTubeContext.client.clientName = Constants.CLIENTS.TV.NAME; - clonedInnerTubeContext.client.clientVersion = Constants.CLIENTS.TV.VERSION; - - const params: Record = { - playbackContext: { - contentPlaybackContext: { - vis: 0, - splay: false, - lactMilliseconds: '-1', - signatureTimestamp: innertube.session.player?.sts - } - }, - videoId - }; - - if (poToken) { - params.serviceIntegrityDimensions = {}; - params.serviceIntegrityDimensions.poToken = poToken; - } - - const playerRequestJson = { - context: clonedInnerTubeContext, - ...params - }; + const { clientKeyData, encryptedClientKey, onesieUstreamerConfig } = + clientConfig; + const clonedInnerTubeContext: Context = structuredClone( + innertube.session.context, + ); + + // Change or remove these if you want to use a different client. I chose TVHTML5 purely for testing. + clonedInnerTubeContext.client.clientName = Constants.CLIENTS.TV.NAME; + clonedInnerTubeContext.client.clientVersion = + Constants.CLIENTS.TV.VERSION; + + const params: Record = { + playbackContext: { + contentPlaybackContext: { + vis: 0, + splay: false, + lactMilliseconds: "-1", + signatureTimestamp: innertube.session.player?.sts, + }, + }, + videoId, + }; + + if (poToken) { + params.serviceIntegrityDimensions = {}; + params.serviceIntegrityDimensions.poToken = poToken; + } + + const playerRequestJson = { + context: clonedInnerTubeContext, + ...params, + }; const headers = [ { From cdf84769f18513fa19b24d2afaeaf9c2e8b67b94 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Fri, 13 Dec 2024 22:27:21 +0000 Subject: [PATCH 3/3] Linting --- src/youtube_onesie_provider.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/youtube_onesie_provider.ts b/src/youtube_onesie_provider.ts index 4839e5155..075a689c4 100644 --- a/src/youtube_onesie_provider.ts +++ b/src/youtube_onesie_provider.ts @@ -110,6 +110,7 @@ export default class YoutubeOnesieProvider { const { videoId, poToken, clientConfig, innertube } = args; const { clientKeyData, encryptedClientKey, onesieUstreamerConfig } = clientConfig; + const clonedInnerTubeContext: Context = structuredClone( innertube.session.context, );