Skip to content

Commit

Permalink
chore: update onesie example
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Nov 2, 2024
1 parent 590f882 commit a6eb882
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
16 changes: 8 additions & 8 deletions examples/onesie-request/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Innertube, { UniversalCache } from 'youtubei.js';
import Innertube, { Constants, UniversalCache } from 'youtubei.js';
import { type Context, Endpoints, YT } from 'youtubei.js';
import GoogleVideo, { base64ToU8, PART, Protos, QUALITY } from '../../dist/src/index.js';
import { decryptResponse, encryptRequest } from './utils.js';
Expand Down Expand Up @@ -62,12 +62,11 @@ type OnesieRequest = {
async function prepareOnesieRequest(args: OnesieRequestArgs): Promise<OnesieRequest> {
const { videoId, poToken, clientConfig, innertube } = args;
const { clientKeyData, encryptedClientKey, onesieUstreamerConfig } = clientConfig;

const clonedInnerTubeContext: Context = JSON.parse(JSON.stringify(innertube.session.context));
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 = 'TVHTML5';
clonedInnerTubeContext.client.clientVersion = '7.20240717.18.00';
clonedInnerTubeContext.client.clientName = Constants.CLIENTS.TV.NAME;
clonedInnerTubeContext.client.clientVersion = Constants.CLIENTS.TV.VERSION;

const playerRequestJson = {
context: clonedInnerTubeContext,
Expand Down Expand Up @@ -126,8 +125,8 @@ async function prepareOnesieRequest(args: OnesieRequestArgs): Promise<OnesieRequ
poToken: poToken ? base64ToU8(poToken) : undefined,
playbackCookie: undefined,
clientInfo: {
clientName: 7,
clientVersion: innertube.session.context.client.clientVersion
clientName: parseInt(Constants.CLIENTS.TV.NAME_ID),
clientVersion: clonedInnerTubeContext.client.clientVersion
}
},
bufferedRanges: [],
Expand Down Expand Up @@ -169,7 +168,8 @@ async function getBasicInfo(innertube: Innertube, videoId: string): Promise<YT.V
queryParams.push(`id=${onesieRequest.encodedVideoId}`);
queryParams.push('&opr=1');
queryParams.push('&por=1');
queryParams.push('rn=1');
queryParams.push('&rn=1');
queryParams.push('&cmo:sensitive_content=yes');

url += `&${queryParams.join('&')}`;

Expand Down
24 changes: 14 additions & 10 deletions examples/onesie-request/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/onesie-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"youtubei.js": "github:LuanRT/YouTube.js"
"youtubei.js": "^11.0.1"
}
}

0 comments on commit a6eb882

Please sign in to comment.