From ffa243bc07eed7b274ec919bd1a8affb2ae6fca5 Mon Sep 17 00:00:00 2001 From: LuanRT Date: Mon, 9 May 2022 18:47:17 -0300 Subject: [PATCH] chore: update type definitions --- typings/lib/Innertube.d.ts | 138 +++++++++++++++++++-------------- typings/lib/core/Livechat.d.ts | 5 +- typings/lib/core/OAuth.d.ts | 1 - typings/lib/core/Player.d.ts | 2 +- typings/lib/utils/Utils.d.ts | 46 ++++++++--- 5 files changed, 120 insertions(+), 72 deletions(-) diff --git a/typings/lib/Innertube.d.ts b/typings/lib/Innertube.d.ts index 1baec494..62037996 100644 --- a/typings/lib/Innertube.d.ts +++ b/typings/lib/Innertube.d.ts @@ -52,84 +52,92 @@ declare class Innertube { /** * Notify about activity from the channels you're subscribed to. * - * @param {boolean} new_value - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @param {boolean} new_value - ON | OFF + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setSubscriptions: (new_value: boolean) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Recommended content notifications. * - * @param {boolean} new_value - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @param {boolean} new_value - ON | OFF + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setRecommendedVideos: (new_value: boolean) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Notify about activity on your channel. * - * @param {boolean} new_value - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @param {boolean} new_value - ON | OFF + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setChannelActivity: (new_value: boolean) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Notify about replies to your comments. * - * @param {boolean} new_value - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @param {boolean} new_value - ON | OFF + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setCommentReplies: (new_value: boolean) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Notify when others mention your channel. * - * @param {boolean} new_value - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @param {boolean} new_value - ON | OFF + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setMentions: (new_value: boolean) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Notify when others share your content on their channels. * - * @param {boolean} new_value - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @param {boolean} new_value - ON | OFF + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setSharedContent: (new_value: boolean) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; }; privacy: { /** * If set to true, your subscriptions won't be visible to others. * - * @param {boolean} new_value - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @param {boolean} new_value - ON | OFF + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setSubscriptionsPrivate: (new_value: boolean) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * If set to true, saved playlists won't appear on your channel. * - * @param {boolean} new_value - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @param {boolean} new_value - ON | OFF + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setSavedPlaylistsPrivate: (new_value: boolean) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; }; }; @@ -139,42 +147,46 @@ declare class Innertube { * Likes a given video. * * @param {string} video_id - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ like: (video_id: string) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Diskes a given video. * * @param {string} video_id - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ dislike: (video_id: string) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Removes a like/dislike. * * @param {string} video_id - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ removeLike: (video_id: string) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Posts a comment on a given video. * * @param {string} video_id * @param {string} text - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ comment: (video_id: string, text: string) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Translates a given text using YouTube's comment translate feature. @@ -185,34 +197,38 @@ declare class Innertube { * @param {string} [args.video_id] * @param {string} [args.comment_id] * - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; translated_content: string; data: object; }>} */ translate: (text: string, target_language: string, args?: { video_id?: string; comment_id?: string; }) => Promise<{ success: boolean; - status_code: string; + status_code: number; + translated_content: string; + data: object; }>; /** * Subscribes to a given channel. * * @param {string} channel_id - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ subscribe: (channel_id: string) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Unsubscribes from a given channel. * * @param {string} channel_id - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ unsubscribe: (channel_id: string) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; /** * Changes notification preferences for a given channel. @@ -220,11 +236,12 @@ declare class Innertube { * * @param {string} channel_id * @param {string} type PERSONALIZED | ALL | NONE - * @returns {Promise.<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} */ setNotificationPreferences: (channel_id: string, type: string) => Promise<{ success: boolean; - status_code: string; + status_code: number; + data: object; }>; }; playlist: { @@ -232,49 +249,54 @@ declare class Innertube { * Creates a playlist. * * @param {string} title - * @param {string} video_ids + * @param {Array.} video_ids * - * @returns {Promise.<{ success: boolean; status_code: string; playlist_id: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; playlist_id: string; data: object; }>} */ - create: (title: string, video_ids: string) => Promise<{ + create: (title: string, video_ids: Array) => Promise<{ success: boolean; - status_code: string; + status_code: number; playlist_id: string; + data: object; }>; /** * Deletes a given playlist. * * @param {string} playlist_id - * @returns {Promise.<{ success: boolean; status_code: string; playlist_id: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; playlist_id: string; data: object; }>} */ delete: (playlist_id: string) => Promise<{ success: boolean; - status_code: string; + status_code: number; playlist_id: string; + data: object; }>; /** * Adds an array of videos to a given playlist. * * @param {string} playlist_id * @param {Array.} video_ids - * @returns {Promise.<{ success: boolean; status_code: string; playlist_id: string; }>} + * @returns {Promise.<{ success: boolean; status_code: number; playlist_id: string; data: object; }>} */ addVideos: (playlist_id: string, video_ids: Array) => Promise<{ success: boolean; - status_code: string; + status_code: number; playlist_id: string; + data: object; }>; /** * Removes videos from a given playlist. * * @param {string} playlist_id * @param {Array.} video_ids - * @returns {Promise.<{ success: boolean; status_code: string; playlist_id: string; }>} + * + * @returns {Promise.<{ success: boolean; status_code: number; playlist_id: string; data: object; }>} */ removeVideos: (playlist_id: string, video_ids: Array) => Promise<{ success: boolean; - status_code: string; + status_code: number; playlist_id: string; + data: object; }>; }; /** @@ -317,17 +339,17 @@ declare class Innertube { * @param {string} query - search query. * @param {object} options - search options. * @param {string} options.client - client used to perform the search, can be: `YTMUSIC` or `YOUTUBE`. - * @param {string} options.period - filter videos uploaded within a period, can be: any | hour | day | week | month | year * @param {string} options.order - filter results by order, can be: relevance | rating | age | views + * @param {string} options.period - filter videos uploaded within a period, can be: any | hour | day | week | month | year * @param {string} options.duration - filter video results by duration, can be: any | short | long * * @returns {Promise.<{ query: string; corrected_query: string; estimated_results: number; videos: [] } | * { results: { songs: []; videos: []; albums: []; community_playlists: [] } }>} */ - search(query: string, options?: { + search(query: string, options: { client: string; - period: string; order: string; + period: string; duration: string; }): Promise<{ query: string; @@ -513,7 +535,7 @@ declare class Innertube { * An alternative to {@link download}. * Returns deciphered streaming data. * - * @param {string} id - video id + * @param {string} video_id - video id * @param {object} options - download options. * @param {string} options.quality - video quality; 360p, 720p, 1080p, etc... * @param {string} options.type - download type, can be: video, audio or videoandaudio @@ -521,7 +543,7 @@ declare class Innertube { * * @returns {Promise.<{ selected_format: {}; formats: [] }>} */ - getStreamingData(id: string, options?: { + getStreamingData(video_id: string, options?: { quality: string; type: string; format: string; @@ -532,7 +554,7 @@ declare class Innertube { /** * Downloads a given video. If you only need the direct download link take a look at {@link getStreamingData}. * - * @param {string} id - video id + * @param {string} video_id - video id * @param {object} options - download options. * @param {string} [options.quality] - video quality; 360p, 720p, 1080p, etc... * @param {string} [options.type] - download type, can be: video, audio or videoandaudio @@ -540,12 +562,14 @@ declare class Innertube { * * @return {Stream.PassThrough} */ - download(id: string, options?: { + download(video_id: string, options?: { quality?: string; type?: string; format?: string; }): Stream.PassThrough; #private; } +import EventEmitter = require("events"); import Request = require("./utils/Request"); import Actions = require("./core/Actions"); +import Stream = require("stream"); diff --git a/typings/lib/core/Livechat.d.ts b/typings/lib/core/Livechat.d.ts index a054b698..f709737f 100644 --- a/typings/lib/core/Livechat.d.ts +++ b/typings/lib/core/Livechat.d.ts @@ -1,5 +1,5 @@ export = Livechat; -declare class Livechat { +declare class Livechat extends EventEmitter { constructor(session: any, token: any, channel_id: any, video_id: any); ctoken: any; session: any; @@ -10,7 +10,7 @@ declare class Livechat { poll_intervals_ms: number; running: boolean; metadata_ctoken: any; - livechat_poller: any; + livechat_poller: NodeJS.Timeout; sendMessage(text: any): Promise; /** * Blocks a user. @@ -21,3 +21,4 @@ declare class Livechat { stop(): void; #private; } +import EventEmitter = require("events"); diff --git a/typings/lib/core/OAuth.d.ts b/typings/lib/core/OAuth.d.ts index a87b08ad..0f5bbd23 100644 --- a/typings/lib/core/OAuth.d.ts +++ b/typings/lib/core/OAuth.d.ts @@ -8,7 +8,6 @@ declare class OAuth { init(auth_info: any): Promise; client_id: string; client_secret: string; - refresh_interval: any; /** * Refreshes the access token if necessary. * @returns {Promise.} diff --git a/typings/lib/core/Player.d.ts b/typings/lib/core/Player.d.ts index 38691035..e54cd52b 100644 --- a/typings/lib/core/Player.d.ts +++ b/typings/lib/core/Player.d.ts @@ -6,6 +6,6 @@ declare class Player { get sts(): any; get ntoken_decipher(): any; get signature_decipher(): any; - isCached(): any; + isCached(): boolean; #private; } diff --git a/typings/lib/utils/Utils.d.ts b/typings/lib/utils/Utils.d.ts index 7183c5c1..441a5876 100644 --- a/typings/lib/utils/Utils.d.ts +++ b/typings/lib/utils/Utils.d.ts @@ -17,13 +17,15 @@ export class NoStreamingDataError extends InnertubeError { /** * Utility to help access deep properties of an object. * - * @param {object} obj - The object. - * @param {string} key - Key of the property being accessed. - * @param {string} target - Anything that might be inside of the property. - * @param {number} depth - Maximum number of nested objects to flatten. - * @param {boolean} safe - If set to true arrays will be preserved. + * @param {object} obj - the object. + * @param {string} key - key of the property being accessed. + * @param {string} target - anything that might be inside of the property. + * @param {number} depth - maximum number of nested objects to flatten. + * @param {boolean} safe - if set to true arrays will be preserved. + * + * @returns {object|Array.} */ -export function findNode(obj: object, key: string, target: string, depth: number, safe?: boolean): any; +export function findNode(obj: object, key: string, target: string, depth: number, safe?: boolean): object | Array; /** * Returns a random user agent. * @@ -38,13 +40,21 @@ export function getRandomUserAgent(type: string): object; * @returns {string} */ export function generateSidAuth(sid: string): string; -export function generateRandomString(length: any): string; /** - * Gets a string between two delimiters. + * Generates a random string with a given length. * - * @param {string} data - The data. - * @param {string} start_string - Start string. - * @param {string} end_string - End string. + * @param {number} length + * @returns {string} + */ +export function generateRandomString(length: number): string; +/** + * Finds a string between two delimiters. + * + * @param {string} data - the data. + * @param {string} start_string - start string. + * @param {string} end_string - end string. + * + * @returns {string} */ export function getStringBetweenStrings(data: string, start_string: string, end_string: string): string; /** @@ -54,6 +64,20 @@ export function getStringBetweenStrings(data: string, start_string: string, end_ * @returns {string} */ export function camelToSnake(string: string): string; +/** + * Checks if a given client is valid. + * + * @param {string} client + * @returns {boolean} + */ +export function isValidClient(client: string): boolean; +/** + * Throws an error if given parameters are undefined. + * + * @param {object} params + * @returns + */ +export function throwIfMissing(params: object): void; /** * Converts time (h:m:s) to seconds. *