Skip to content
Merged
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
15 changes: 13 additions & 2 deletions src/core/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export interface Context {
utcOffsetMinutes: number;
};
user: {
lockedSafetyMode: false;
enableSafetyMode: boolean;
lockedSafetyMode: boolean;
};
thirdParty?: {
embedUrl: string;
Expand All @@ -60,6 +61,8 @@ export interface SessionOptions {
lang?: string;
location?: string;
account_index?: number;
retrieve_player?: boolean;
enable_safety_mode?: boolean;
device_category?: DeviceCategory;
client_type?: ClientType;
timezone?: string;
Expand Down Expand Up @@ -117,18 +120,25 @@ export default class Session extends EventEmitterLike {
options.lang,
options.location,
options.account_index,
options.enable_safety_mode,
options.device_category,
options.client_type,
options.timezone,
options.fetch
);
return new Session(context, api_key, api_version, account_index, await Player.create(options.cache, options.fetch), options.cookie, options.fetch, options.cache);

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
);
}

static async getSessionData(
lang = 'en-US',
location = '',
account_index = 0,
enable_safety_mode = false,
device_category: DeviceCategory = 'desktop',
client_name: ClientType = ClientType.WEB,
tz: string = Intl.DateTimeFormat().resolvedOptions().timeZone,
Expand Down Expand Up @@ -186,6 +196,7 @@ export default class Session extends EventEmitterLike {
utcOffsetMinutes: new Date().getTimezoneOffset()
},
user: {
enableSafetyMode: enable_safety_mode,
lockedSafetyMode: false
},
request: {
Expand Down
7 changes: 6 additions & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('YouTube.js Tests', () => {
beforeAll(async () => {
yt = await Innertube.create();
});

describe('Info', () => {
let info: any;

Expand Down Expand Up @@ -116,6 +116,11 @@ describe('YouTube.js Tests', () => {
});

describe('General', () => {
it('should create sessions without a player instance', async () => {
const nop_yt = await Innertube.create({ retrieve_player: false });
expect(nop_yt.session.player).toBeUndefined();
});

it('should resolve a URL', async () => {
const url = await yt.resolveURL('https://www.youtube.com/@linustechtips');
expect(url.payload.browseId).toBe(CHANNELS[0].ID);
Expand Down