mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 04:21:35 +00:00
refactor!: overhaul core classes and remove redundant code (#388)
* 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
This commit is contained in:
23
src/types/Clients.ts
Normal file
23
src/types/Clients.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// Studio.ts
|
||||
export type UpdateVideoMetadataOptions = Partial<{
|
||||
title: string;
|
||||
description: string;
|
||||
tags: string[];
|
||||
category: number;
|
||||
license: string;
|
||||
age_restricted: boolean;
|
||||
made_for_kids: boolean;
|
||||
privacy: 'PUBLIC' | 'PRIVATE' | 'UNLISTED';
|
||||
}>;
|
||||
|
||||
export type UploadedVideoMetadataOptions = Partial<{
|
||||
title: string;
|
||||
description: string;
|
||||
privacy: 'PUBLIC' | 'PRIVATE' | 'UNLISTED';
|
||||
is_draft: boolean;
|
||||
}>;
|
||||
|
||||
// Music.ts
|
||||
export type MusicSearchFilters = Partial<{
|
||||
type: 'all' | 'song' | 'video' | 'album' | 'playlist' | 'artist';
|
||||
}>;
|
||||
343
src/types/Endpoints.ts
Normal file
343
src/types/Endpoints.ts
Normal file
@@ -0,0 +1,343 @@
|
||||
import type { InnerTubeClient } from '../Innertube.js';
|
||||
|
||||
export type SnakeToCamel<S extends string> = S extends `${infer T}_${infer U}` ? `${Lowercase<T>}${Capitalize<SnakeToCamel<U>>}` : S;
|
||||
|
||||
export type ObjectSnakeToCamel<T> = {
|
||||
[K in keyof T as SnakeToCamel<K & string>]: T[K] extends object ? ObjectSnakeToCamel<T[K]> : T[K];
|
||||
}
|
||||
|
||||
export interface IPlayerRequest {
|
||||
playbackContext: {
|
||||
contentPlaybackContext: {
|
||||
vis: number;
|
||||
splay: boolean;
|
||||
referer: string;
|
||||
currentUrl: string;
|
||||
autonavState: string;
|
||||
signatureTimestamp?: number;
|
||||
autoCaptionsDefaultOn: boolean;
|
||||
html5Preference: string;
|
||||
lactMilliseconds: string;
|
||||
}
|
||||
},
|
||||
videoId: string;
|
||||
racyCheckOk: boolean;
|
||||
contentCheckOk: boolean;
|
||||
client?: InnerTubeClient;
|
||||
playlistId?: string;
|
||||
}
|
||||
|
||||
export type PlayerEndpointOptions = {
|
||||
/**
|
||||
* The video ID.
|
||||
*/
|
||||
video_id: string;
|
||||
/**
|
||||
* The player's signature timestamp.
|
||||
*/
|
||||
sts?: number;
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
/**
|
||||
* The playlist ID.
|
||||
*/
|
||||
playlist_id?: string;
|
||||
}
|
||||
|
||||
export type NextEndpointOptions = {
|
||||
/**
|
||||
* The video ID.
|
||||
*/
|
||||
video_id?: string;
|
||||
/**
|
||||
* The playlist associated with the video.
|
||||
*/
|
||||
playlist_id?: string;
|
||||
/**
|
||||
* Protobuf parameters.
|
||||
*/
|
||||
params?: string;
|
||||
/**
|
||||
* The playlist index.
|
||||
*/
|
||||
playlist_index?: number;
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
/**
|
||||
* The continuation token. Mostly used for pagination.
|
||||
*/
|
||||
continuation?: string;
|
||||
}
|
||||
|
||||
export type INextRequest = ObjectSnakeToCamel<NextEndpointOptions>;
|
||||
|
||||
export type BrowseEndpointOptions = {
|
||||
/**
|
||||
* The browse ID.
|
||||
*/
|
||||
browse_id?: string;
|
||||
/**
|
||||
* Additional protobuf parameters.
|
||||
*/
|
||||
params?: string;
|
||||
/**
|
||||
* The continuation token. Mostly used for pagination.
|
||||
*/
|
||||
continuation?: string;
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
}
|
||||
|
||||
export type IBrowseRequest = ObjectSnakeToCamel<BrowseEndpointOptions>;
|
||||
|
||||
export interface ISearchRequest {
|
||||
/**
|
||||
* The query to search for.
|
||||
*/
|
||||
query?: string;
|
||||
/**
|
||||
* Additional protobuf parameters.
|
||||
*/
|
||||
params?: string;
|
||||
/**
|
||||
* The continuation token. Mostly sed for pagination.
|
||||
*/
|
||||
continuation?: string;
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
}
|
||||
|
||||
export type SearchEndpointOptions = ISearchRequest;
|
||||
|
||||
export interface IResolveURLRequest {
|
||||
/**
|
||||
* The URL to resolve.
|
||||
*/
|
||||
url: string;
|
||||
}
|
||||
|
||||
export type ResolveURLEndpointOptions = IResolveURLRequest;
|
||||
|
||||
export type GetNotificationMenuEndpointOptions = {
|
||||
/**
|
||||
* The type of notifications to request.
|
||||
*/
|
||||
notifications_menu_request_type: 'NOTIFICATIONS_MENU_REQUEST_TYPE_INBOX' | 'NOTIFICATIONS_MENU_REQUEST_TYPE_COMMENTS';
|
||||
}
|
||||
|
||||
export type IGetNotificationMenuRequest = ObjectSnakeToCamel<GetNotificationMenuEndpointOptions>;
|
||||
|
||||
export type MusicGetSearchSuggestionsEndpointOptions = {
|
||||
/**
|
||||
* The query to search for.
|
||||
*/
|
||||
input: string;
|
||||
}
|
||||
|
||||
export interface IMusicGetSearchSuggestionsRequest extends MusicGetSearchSuggestionsEndpointOptions {
|
||||
client: 'YTMUSIC';
|
||||
}
|
||||
|
||||
export type ChannelEditNameEndpointOptions = {
|
||||
/**
|
||||
* The new channel name.
|
||||
*/
|
||||
given_name: string;
|
||||
}
|
||||
|
||||
export interface IChannelEditNameRequest extends ObjectSnakeToCamel<ChannelEditNameEndpointOptions> {
|
||||
client: 'ANDROID';
|
||||
}
|
||||
|
||||
export type ChannelEditDescriptionEndpointOptions = {
|
||||
/**
|
||||
* The new channel description.
|
||||
*/
|
||||
given_description: string;
|
||||
}
|
||||
|
||||
export interface IChannelEditDescriptionRequest extends ObjectSnakeToCamel<ChannelEditDescriptionEndpointOptions> {
|
||||
client: 'ANDROID';
|
||||
}
|
||||
|
||||
export interface IAccountListRequest {
|
||||
client: 'ANDROID';
|
||||
}
|
||||
|
||||
export type LikeEndpointOptions = {
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
/**
|
||||
* The target video.
|
||||
*/
|
||||
target: {
|
||||
video_id: string;
|
||||
}
|
||||
}
|
||||
|
||||
export type ILikeRequest = ObjectSnakeToCamel<LikeEndpointOptions>;
|
||||
|
||||
export type IDislikeRequest = ILikeRequest;
|
||||
export type DislikeEndpointOptions = LikeEndpointOptions;
|
||||
|
||||
export type IRemoveLikeRequest = ILikeRequest;
|
||||
export type RemoveLikeEndpointOptions = LikeEndpointOptions;
|
||||
|
||||
export type SubscribeEndpointOptions = {
|
||||
/**
|
||||
* The channel IDs to subscribe to/unsubscribe from.
|
||||
*/
|
||||
channel_ids: string[];
|
||||
/**
|
||||
* Additional protobuf parameters.
|
||||
*/
|
||||
params?: string;
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
}
|
||||
|
||||
export type ISubscribeRequest = ObjectSnakeToCamel<SubscribeEndpointOptions>;
|
||||
|
||||
export type IUnsubscribeRequest = ISubscribeRequest;
|
||||
export type UnsubscribeEndpointOptions = SubscribeEndpointOptions;
|
||||
|
||||
export interface IPerformCommentActionRequest {
|
||||
/**
|
||||
* An array of protobuf-encoded actions.
|
||||
*/
|
||||
actions: string[];
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
}
|
||||
|
||||
export type PerformCommentActionEndpointOptions = IPerformCommentActionRequest;
|
||||
|
||||
export type CreateCommentEndpointOptions = {
|
||||
/**
|
||||
* The comment text.
|
||||
*/
|
||||
comment_text: string;
|
||||
/**
|
||||
* Additional protobuf parameters.
|
||||
*/
|
||||
create_comment_params: string;
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
}
|
||||
|
||||
export type ICreateCommentRequest = ObjectSnakeToCamel<CreateCommentEndpointOptions>;
|
||||
|
||||
export interface IModifyChannelPreferenceRequest {
|
||||
/**
|
||||
* Protobuf-encoded parameters.
|
||||
*/
|
||||
params: string;
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
}
|
||||
|
||||
export type ModifyChannelPreferenceEndpointOptions = IModifyChannelPreferenceRequest;
|
||||
|
||||
export type CreateVideoEndpointOptions = {
|
||||
/**
|
||||
* The id of the uploaded resource.
|
||||
*/
|
||||
resource_id: {
|
||||
scotty_resource_id: {
|
||||
id: string;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* The id of the frontend.
|
||||
*/
|
||||
frontend_upload_id: string;
|
||||
/**
|
||||
* The metadata to set after the video is uploaded.
|
||||
*/
|
||||
initial_metadata: {
|
||||
title: {
|
||||
new_title: string;
|
||||
};
|
||||
description: {
|
||||
new_description: string;
|
||||
should_segment: boolean;
|
||||
};
|
||||
privacy: {
|
||||
new_privacy: string;
|
||||
};
|
||||
draft_state: {
|
||||
is_draft?: boolean;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* The client to use.
|
||||
*/
|
||||
client?: InnerTubeClient;
|
||||
}
|
||||
|
||||
export type ICreateVideoRequest = ObjectSnakeToCamel<CreateVideoEndpointOptions>;
|
||||
|
||||
export type CreatePlaylistEndpointOptions = {
|
||||
/**
|
||||
* The playlist title.
|
||||
*/
|
||||
title: string;
|
||||
/**
|
||||
* The video IDs to add to the playlist.
|
||||
*/
|
||||
ids: string[];
|
||||
}
|
||||
|
||||
export type ICreatePlaylistRequest = CreatePlaylistEndpointOptions;
|
||||
|
||||
export type DeletePlaylistEndpointOptions = {
|
||||
/**
|
||||
* The ID of the playlist to delete.
|
||||
*/
|
||||
playlist_id: string;
|
||||
}
|
||||
|
||||
export type IDeletePlaylistRequest = ObjectSnakeToCamel<DeletePlaylistEndpointOptions>;
|
||||
|
||||
export type EditPlaylistEndpointOptions = {
|
||||
/**
|
||||
* The ID of the playlist to edit.
|
||||
*/
|
||||
playlist_id: string;
|
||||
/**
|
||||
* The changes to make to the playlist.
|
||||
*/
|
||||
actions: {
|
||||
action: 'ACTION_ADD_VIDEO' | 'ACTION_REMOVE_VIDEO' | 'ACTION_MOVE_VIDEO_AFTER';
|
||||
added_video_id?: string;
|
||||
set_video_id?: string;
|
||||
moved_set_video_id_predecessor?: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface IEditPlaylistRequest extends ObjectSnakeToCamel<EditPlaylistEndpointOptions> {
|
||||
actions: {
|
||||
action: 'ACTION_ADD_VIDEO' | 'ACTION_REMOVE_VIDEO' | 'ACTION_MOVE_VIDEO_AFTER';
|
||||
addedVideoId?: string;
|
||||
setVideoId?: string;
|
||||
movedSetVideoIdPredecessor?: string;
|
||||
}[];
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
export * from './Cache.js';
|
||||
|
||||
export type { default as PlatformShim } from './PlatformShim.js';
|
||||
|
||||
export * from './Cache.js';
|
||||
export * from './PlatformShim.js';
|
||||
export * from './Clients.js';
|
||||
export * from './Endpoints.js';
|
||||
Reference in New Issue
Block a user