Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first try #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const youtube = await Innertube.create(/* options */);
| `cache` | `ICache` | Used to cache algorithms, session data, and OAuth2 tokens. | `undefined` |
| `cookie` | `string` | YouTube cookies. | `undefined` |
| `fetch` | `FetchFunction` | Fetch function to use. | `fetch` |
| `po_token` | `string` | Send Google session information for solving the error "LOGIN_REQUIRED: This helps protect our community." | `undefined` |

</details>

Expand Down
6 changes: 4 additions & 2 deletions src/Innertube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export default class Innertube {
video_id: next_payload.videoId,
playlist_id: next_payload?.playlistId,
client: client,
sts: this.#session.player?.sts
sts: this.#session.player?.sts,
po_token: this.#session.po_token,
});

const player_response = this.actions.execute(PlayerEndpoint.PATH, player_payload);
Expand All @@ -127,7 +128,8 @@ export default class Innertube {
PlayerEndpoint.PATH, PlayerEndpoint.build({
video_id: video_id,
client: client,
sts: this.#session.player?.sts
sts: this.#session.player?.sts,
po_token: this.#session.po_token,
})
);

Expand Down
16 changes: 12 additions & 4 deletions src/core/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export type SessionOptions = {
* Fetch function to use.
*/
fetch?: FetchFunction;
/**
* Token for serviceIntegrityDimensions
*/
po_token?: string;
}

export type SessionData = {
Expand Down Expand Up @@ -213,8 +217,9 @@ export default class Session extends EventEmitter {
key: string;
api_version: string;
account_index: number;
po_token?: string;

constructor(context: Context, api_key: string, api_version: string, account_index: number, player?: Player, cookie?: string, fetch?: FetchFunction, cache?: ICache) {
constructor(context: Context, api_key: string, api_version: string, account_index: number, player?: Player, cookie?: string, fetch?: FetchFunction, cache?: ICache, po_token?: string) {
Copy link

@LuanRT LuanRT Jul 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok there's another problem here actually. po_token is a parameter, but it's not being used anywhere. Session#create is not passing the token from SessionOptions when instantiating the class:

return new Session(
context, api_key, api_version, account_index,
options.retrieve_player === false ? undefined : await Player.create(options.cache, options.fetch),
options.cookie, options.fetch, options.cache
);
}

super();
this.http = new HTTPClient(this, cookie, fetch);
this.actions = new Actions(this);
Expand All @@ -226,6 +231,7 @@ export default class Session extends EventEmitter {
this.api_version = api_version;
this.context = context;
this.player = player;
this.po_token = po_token;
}

on(type: 'auth', listener: OAuth2AuthEventHandler): void;
Expand Down Expand Up @@ -259,7 +265,8 @@ export default class Session extends EventEmitter {
options.fetch,
options.on_behalf_of_user,
options.cache,
options.enable_session_cache
options.enable_session_cache,
options.po_token,
);

return new Session(
Expand Down Expand Up @@ -323,9 +330,10 @@ export default class Session extends EventEmitter {
fetch: FetchFunction = Platform.shim.fetch,
on_behalf_of_user?: string,
cache?: ICache,
enable_session_cache = true
enable_session_cache = true,
po_token?: string,
) {
const session_args = { lang, location, time_zone: tz, device_category, client_name, enable_safety_mode, visitor_data, on_behalf_of_user };
const session_args = { lang, location, time_zone: tz, device_category, client_name, enable_safety_mode, visitor_data, on_behalf_of_user, po_token };

let session_data: SessionData | undefined;

Expand Down
7 changes: 5 additions & 2 deletions src/core/endpoints/PlayerEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export function build(opts: PlayerEndpointOptions): IPlayerRequest {
...{
client: opts.client,
playlistId: opts.playlist_id,
params: opts.params
}
params: opts.params,
serviceIntegrityDimensions: {
poToken: opts.po_token || ""
},
},
};
}
7 changes: 7 additions & 0 deletions src/types/Endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export interface IPlayerRequest {
playlistId?: string;
params?: string;
client?: InnerTubeClient;
serviceIntegrityDimensions?: {
poToken: string
}
}

export type PlayerEndpointOptions = {
Expand All @@ -52,6 +55,10 @@ export type PlayerEndpointOptions = {
* Additional protobuf parameters.
*/
params?: string;
/**
* Token for serviceIntegrityDimensions
*/
po_token?: string;
}

export type NextEndpointOptions = {
Expand Down