mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-07-02 21:52:48 +00:00
feat: allow enabling safety mode (#269)
Unrelated: this also simplifies the creation of sessions without a player instance.
This commit is contained in:
@@ -46,7 +46,8 @@ export interface Context {
|
||||
utcOffsetMinutes: number;
|
||||
};
|
||||
user: {
|
||||
lockedSafetyMode: false;
|
||||
enableSafetyMode: boolean;
|
||||
lockedSafetyMode: boolean;
|
||||
};
|
||||
thirdParty?: {
|
||||
embedUrl: string;
|
||||
@@ -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;
|
||||
@@ -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,
|
||||
@@ -186,6 +196,7 @@ export default class Session extends EventEmitterLike {
|
||||
utcOffsetMinutes: new Date().getTimezoneOffset()
|
||||
},
|
||||
user: {
|
||||
enableSafetyMode: enable_safety_mode,
|
||||
lockedSafetyMode: false
|
||||
},
|
||||
request: {
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('YouTube.js Tests', () => {
|
||||
beforeAll(async () => {
|
||||
yt = await Innertube.create();
|
||||
});
|
||||
|
||||
|
||||
describe('Info', () => {
|
||||
let info: any;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user