mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-28 00:56:23 +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
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import Channel from '../../parser/ytkids/Channel.js';
|
|
import HomeFeed from '../../parser/ytkids/HomeFeed.js';
|
|
import Search from '../../parser/ytkids/Search.js';
|
|
import VideoInfo from '../../parser/ytkids/VideoInfo.js';
|
|
import type Session from '../Session.js';
|
|
|
|
import { generateRandomString } from '../../utils/Utils.js';
|
|
|
|
import {
|
|
BrowseEndpoint, NextEndpoint,
|
|
PlayerEndpoint, SearchEndpoint
|
|
} from '../endpoints/index.js';
|
|
|
|
export default class Kids {
|
|
#session: Session;
|
|
|
|
constructor(session: Session) {
|
|
this.#session = session;
|
|
}
|
|
|
|
/**
|
|
* Searches the given query.
|
|
* @param query - The query.
|
|
*/
|
|
async search(query: string): Promise<Search> {
|
|
const response = await this.#session.actions.execute(
|
|
SearchEndpoint.PATH, SearchEndpoint.build({ client: 'YTKIDS', query })
|
|
);
|
|
return new Search(this.#session.actions, response);
|
|
}
|
|
|
|
/**
|
|
* Retrieves video info.
|
|
* @param video_id - The video id.
|
|
*/
|
|
async getInfo(video_id: string): Promise<VideoInfo> {
|
|
const player_payload = PlayerEndpoint.build({
|
|
sts: this.#session.player?.sts,
|
|
client: 'YTKIDS',
|
|
video_id
|
|
});
|
|
|
|
const next_payload = NextEndpoint.build({
|
|
video_id,
|
|
client: 'YTKIDS'
|
|
});
|
|
|
|
const player_response = this.#session.actions.execute(PlayerEndpoint.PATH, player_payload);
|
|
const next_response = this.#session.actions.execute(NextEndpoint.PATH, next_payload);
|
|
const response = await Promise.all([ player_response, next_response ]);
|
|
|
|
const cpn = generateRandomString(16);
|
|
|
|
return new VideoInfo(response, this.#session.actions, cpn);
|
|
}
|
|
|
|
/**
|
|
* Retrieves the contents of the given channel.
|
|
* @param channel_id - The channel id.
|
|
*/
|
|
async getChannel(channel_id: string): Promise<Channel> {
|
|
const response = await this.#session.actions.execute(
|
|
BrowseEndpoint.PATH, BrowseEndpoint.build({
|
|
browse_id: channel_id,
|
|
client: 'YTKIDS'
|
|
})
|
|
);
|
|
return new Channel(this.#session.actions, response);
|
|
}
|
|
|
|
/**
|
|
* Retrieves the home feed.
|
|
*/
|
|
async getHomeFeed(): Promise<HomeFeed> {
|
|
const response = await this.#session.actions.execute(
|
|
BrowseEndpoint.PATH, BrowseEndpoint.build({
|
|
browse_id: 'FEkids_home',
|
|
client: 'YTKIDS'
|
|
})
|
|
);
|
|
return new HomeFeed(this.#session.actions, response);
|
|
}
|
|
} |