mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-18 03:59:38 +00:00
* feat(Player.ts): append `cver` to deciphered URLs * refactor(Actions.ts): remove redundant `getVideoInfo` function This is leftover code from previous versions. It had many problems and it is no longer required. * fix(Kids.ts): remove unneeded `await` keywords * dev: add more endpoints * chore: update deps * refactor: separate endpoints into files * dev: improve types * dev: add more endpoints * refactor: put clients in a separate directory inside `core` * chore: lint * refactor: move mixins and managers to separate folders * chore: fix tests * dev: add `CreateVideoEndpoint` * chore: clean up * chore: lint * chore: add some comments * chore: remove unnecessary test * dev: add `playlist/CreateEndpoint` * dev: add `playlist/DeleteEndpoint` * dev: add `browse/EditPlaylistEndpoint` * fix(parser): add a few checks to avoid parsing errors
120 lines
3.3 KiB
TypeScript
120 lines
3.3 KiB
TypeScript
import AccountInfo from '../../parser/youtube/AccountInfo.js';
|
|
import Analytics from '../../parser/youtube/Analytics.js';
|
|
import Settings from '../../parser/youtube/Settings.js';
|
|
import TimeWatched from '../../parser/youtube/TimeWatched.js';
|
|
|
|
import Proto from '../../proto/index.js';
|
|
import { InnertubeError } from '../../utils/Utils.js';
|
|
import { Account, BrowseEndpoint, Channel } from '../endpoints/index.js';
|
|
|
|
import type Actions from '../Actions.js';
|
|
import type { ApiResponse } from '../Actions.js';
|
|
|
|
export default class AccountManager {
|
|
#actions: Actions;
|
|
|
|
channel: {
|
|
editName: (new_name: string) => Promise<ApiResponse>;
|
|
editDescription: (new_description: string) => Promise<ApiResponse>;
|
|
getBasicAnalytics: () => Promise<Analytics>;
|
|
};
|
|
|
|
constructor(actions: Actions) {
|
|
this.#actions = actions;
|
|
|
|
this.channel = {
|
|
/**
|
|
* Edits channel name.
|
|
* @param new_name - The new channel name.
|
|
*/
|
|
editName: (new_name: string) => {
|
|
if (!this.#actions.session.logged_in)
|
|
throw new InnertubeError('You must be signed in to perform this operation.');
|
|
|
|
return this.#actions.execute(
|
|
Channel.EditNameEndpoint.PATH,
|
|
Channel.EditNameEndpoint.build({
|
|
given_name: new_name
|
|
})
|
|
);
|
|
},
|
|
/**
|
|
* Edits channel description.
|
|
* @param new_description - The new description.
|
|
*/
|
|
editDescription: (new_description: string) => {
|
|
if (!this.#actions.session.logged_in)
|
|
throw new InnertubeError('You must be signed in to perform this operation.');
|
|
|
|
return this.#actions.execute(
|
|
Channel.EditDescriptionEndpoint.PATH,
|
|
Channel.EditDescriptionEndpoint.build({
|
|
given_description: new_description
|
|
})
|
|
);
|
|
},
|
|
/**
|
|
* Retrieves basic channel analytics.
|
|
*/
|
|
getBasicAnalytics: () => this.getAnalytics()
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Retrieves channel info.
|
|
*/
|
|
async getInfo(): Promise<AccountInfo> {
|
|
if (!this.#actions.session.logged_in)
|
|
throw new InnertubeError('You must be signed in to perform this operation.');
|
|
|
|
const response = await this.#actions.execute(
|
|
Account.AccountListEndpoint.PATH,
|
|
Account.AccountListEndpoint.build()
|
|
);
|
|
|
|
return new AccountInfo(response);
|
|
}
|
|
|
|
/**
|
|
* Retrieves time watched statistics.
|
|
*/
|
|
async getTimeWatched(): Promise<TimeWatched> {
|
|
const response = await this.#actions.execute(
|
|
BrowseEndpoint.PATH, BrowseEndpoint.build({
|
|
browse_id: 'SPtime_watched',
|
|
client: 'ANDROID'
|
|
})
|
|
);
|
|
|
|
return new TimeWatched(response);
|
|
}
|
|
|
|
/**
|
|
* Opens YouTube settings.
|
|
*/
|
|
async getSettings(): Promise<Settings> {
|
|
const response = await this.#actions.execute(
|
|
BrowseEndpoint.PATH, BrowseEndpoint.build({
|
|
browse_id: 'SPaccount_overview'
|
|
})
|
|
);
|
|
return new Settings(this.#actions, response);
|
|
}
|
|
|
|
/**
|
|
* Retrieves basic channel analytics.
|
|
*/
|
|
async getAnalytics(): Promise<Analytics> {
|
|
const info = await this.getInfo();
|
|
|
|
const response = await this.#actions.execute(
|
|
BrowseEndpoint.PATH, BrowseEndpoint.build({
|
|
browse_id: 'FEanalytics_screen',
|
|
params: Proto.encodeChannelAnalyticsParams(info.footers?.endpoint.payload.browseId),
|
|
client: 'ANDROID'
|
|
})
|
|
);
|
|
|
|
return new Analytics(response);
|
|
}
|
|
} |