From b6cfdb733c447764bd3970ad104933ecb6efebf8 Mon Sep 17 00:00:00 2001 From: LuanRT Date: Sun, 8 May 2022 05:56:33 -0300 Subject: [PATCH] feat: generate types using jsdoc, #50 --- package-lock.json | 71 ++- package.json | 7 +- tsconfig.json | 19 + typings/index.d.ts | 192 +----- typings/lib/Innertube.d.ts | 551 ++++++++++++++++++ typings/lib/core/Actions.d.ts | 252 ++++++++ typings/lib/core/Livechat.d.ts | 23 + typings/lib/core/OAuth.d.ts | 35 ++ typings/lib/core/Player.d.ts | 11 + typings/lib/core/SessionBuilder.d.ts | 12 + typings/lib/deciphers/NToken.d.ts | 12 + typings/lib/deciphers/Signature.d.ts | 12 + typings/lib/parser/index.d.ts | 9 + typings/lib/parser/youtube/index.d.ts | 11 + .../youtube/others/ChannelMetadata.d.ts | 15 + .../parser/youtube/others/CommentThread.d.ts | 23 + .../youtube/others/GridPlaylistItem.d.ts | 12 + .../parser/youtube/others/GridVideoItem.d.ts | 25 + .../youtube/others/NotificationItem.d.ts | 14 + .../parser/youtube/others/PlaylistItem.d.ts | 15 + .../parser/youtube/others/ShelfRenderer.d.ts | 9 + .../lib/parser/youtube/others/VideoItem.d.ts | 31 + .../youtube/search/SearchSuggestionItem.d.ts | 4 + .../youtube/search/VideoResultItem.d.ts | 31 + typings/lib/parser/ytmusic/index.d.ts | 9 + .../parser/ytmusic/others/PlaylistItem.d.ts | 14 + .../ytmusic/search/AlbumResultItem.d.ts | 11 + .../ytmusic/search/ArtistResultItem.d.ts | 10 + .../search/MusicSearchSuggestionItem.d.ts | 8 + .../ytmusic/search/PlaylistResultItem.d.ts | 11 + .../parser/ytmusic/search/SongResultItem.d.ts | 12 + .../parser/ytmusic/search/TopResultItem.d.ts | 4 + .../ytmusic/search/VideoResultItem.d.ts | 12 + typings/lib/proto/index.d.ts | 100 ++++ typings/lib/proto/messages.d.ts | 96 +++ typings/lib/utils/Constants.d.ts | 90 +++ typings/lib/utils/Request.d.ts | 7 + typings/lib/utils/Utils.d.ts | 70 +++ 38 files changed, 1641 insertions(+), 209 deletions(-) create mode 100644 tsconfig.json create mode 100644 typings/lib/Innertube.d.ts create mode 100644 typings/lib/core/Actions.d.ts create mode 100644 typings/lib/core/Livechat.d.ts create mode 100644 typings/lib/core/OAuth.d.ts create mode 100644 typings/lib/core/Player.d.ts create mode 100644 typings/lib/core/SessionBuilder.d.ts create mode 100644 typings/lib/deciphers/NToken.d.ts create mode 100644 typings/lib/deciphers/Signature.d.ts create mode 100644 typings/lib/parser/index.d.ts create mode 100644 typings/lib/parser/youtube/index.d.ts create mode 100644 typings/lib/parser/youtube/others/ChannelMetadata.d.ts create mode 100644 typings/lib/parser/youtube/others/CommentThread.d.ts create mode 100644 typings/lib/parser/youtube/others/GridPlaylistItem.d.ts create mode 100644 typings/lib/parser/youtube/others/GridVideoItem.d.ts create mode 100644 typings/lib/parser/youtube/others/NotificationItem.d.ts create mode 100644 typings/lib/parser/youtube/others/PlaylistItem.d.ts create mode 100644 typings/lib/parser/youtube/others/ShelfRenderer.d.ts create mode 100644 typings/lib/parser/youtube/others/VideoItem.d.ts create mode 100644 typings/lib/parser/youtube/search/SearchSuggestionItem.d.ts create mode 100644 typings/lib/parser/youtube/search/VideoResultItem.d.ts create mode 100644 typings/lib/parser/ytmusic/index.d.ts create mode 100644 typings/lib/parser/ytmusic/others/PlaylistItem.d.ts create mode 100644 typings/lib/parser/ytmusic/search/AlbumResultItem.d.ts create mode 100644 typings/lib/parser/ytmusic/search/ArtistResultItem.d.ts create mode 100644 typings/lib/parser/ytmusic/search/MusicSearchSuggestionItem.d.ts create mode 100644 typings/lib/parser/ytmusic/search/PlaylistResultItem.d.ts create mode 100644 typings/lib/parser/ytmusic/search/SongResultItem.d.ts create mode 100644 typings/lib/parser/ytmusic/search/TopResultItem.d.ts create mode 100644 typings/lib/parser/ytmusic/search/VideoResultItem.d.ts create mode 100644 typings/lib/proto/index.d.ts create mode 100644 typings/lib/proto/messages.d.ts create mode 100644 typings/lib/utils/Constants.d.ts create mode 100644 typings/lib/utils/Request.d.ts create mode 100644 typings/lib/utils/Utils.d.ts diff --git a/package-lock.json b/package-lock.json index 1b8f63c3..923e8ef2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,10 @@ "user-agents": "^1.0.778", "uuid": "^8.3.2" }, + "devDependencies": { + "@types/node": "^17.0.31", + "typescript": "^4.6.4" + }, "engines": { "node": ">=14" }, @@ -22,6 +26,12 @@ "url": "https://ko-fi.com/luanrt" } }, + "node_modules/@types/node": { + "version": "17.0.31", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.31.tgz", + "integrity": "sha512-AR0x5HbXGqkEx9CadRH3EBYx/VkiUgZIhP4wvPn/+5KIsgpNoyFaRlVe0Zlx9gRtg8fA06a9tskE2MSN7TcG4Q==", + "dev": true + }, "node_modules/axios": { "version": "0.21.4", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", @@ -68,9 +78,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.14.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.0.tgz", + "integrity": "sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==", "funding": [ { "type": "individual", @@ -108,10 +118,23 @@ "varint": "~5.0.0" } }, + "node_modules/typescript": { + "version": "4.6.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz", + "integrity": "sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, "node_modules/underscore": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.2.tgz", - "integrity": "sha512-ekY1NhRzq0B08g4bGuX4wd2jZx5GnKz6mKSqFL4nqBlfyMGiG10gDFhDTMEfYmDL6Jy0FUIZp7wiRB+0BP7J2g==" + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.3.tgz", + "integrity": "sha512-QvjkYpiD+dJJraRA8+dGAU4i7aBbb2s0S3jA45TFOvg2VgqvdCDd/3N6CqA8gluk1W91GLoXg5enMUx560QzuA==" }, "node_modules/underscore-keypath": { "version": "0.0.22", @@ -122,9 +145,9 @@ } }, "node_modules/user-agents": { - "version": "1.0.993", - "resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.993.tgz", - "integrity": "sha512-15uxQ45RVVNSWLkW9V3KkHoQIp+3evKLAfJSe6WOYNLF897mn7m1LTMn4IC7n4CmviDlQJ/SKyCXEutcYo1rAQ==", + "version": "1.0.1010", + "resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.1010.tgz", + "integrity": "sha512-hFILFCBGQcDwQLjl3qbeX3409ZSICHc3dai8dzTAx4rpAS0Q6Fz/n3okPTfrZ4IlwUUHSwBIf5k1uGLU7uT4zg==", "dependencies": { "dot-json": "^1.2.2", "lodash.clonedeep": "^4.5.0" @@ -145,6 +168,12 @@ } }, "dependencies": { + "@types/node": { + "version": "17.0.31", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.31.tgz", + "integrity": "sha512-AR0x5HbXGqkEx9CadRH3EBYx/VkiUgZIhP4wvPn/+5KIsgpNoyFaRlVe0Zlx9gRtg8fA06a9tskE2MSN7TcG4Q==", + "dev": true + }, "axios": { "version": "0.21.4", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", @@ -179,9 +208,9 @@ "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==" }, "follow-redirects": { - "version": "1.14.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.0.tgz", + "integrity": "sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==" }, "lodash.clonedeep": { "version": "4.5.0", @@ -205,10 +234,16 @@ "varint": "~5.0.0" } }, + "typescript": { + "version": "4.6.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz", + "integrity": "sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==", + "dev": true + }, "underscore": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.2.tgz", - "integrity": "sha512-ekY1NhRzq0B08g4bGuX4wd2jZx5GnKz6mKSqFL4nqBlfyMGiG10gDFhDTMEfYmDL6Jy0FUIZp7wiRB+0BP7J2g==" + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.3.tgz", + "integrity": "sha512-QvjkYpiD+dJJraRA8+dGAU4i7aBbb2s0S3jA45TFOvg2VgqvdCDd/3N6CqA8gluk1W91GLoXg5enMUx560QzuA==" }, "underscore-keypath": { "version": "0.0.22", @@ -219,9 +254,9 @@ } }, "user-agents": { - "version": "1.0.993", - "resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.993.tgz", - "integrity": "sha512-15uxQ45RVVNSWLkW9V3KkHoQIp+3evKLAfJSe6WOYNLF897mn7m1LTMn4IC7n4CmviDlQJ/SKyCXEutcYo1rAQ==", + "version": "1.0.1010", + "resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.1010.tgz", + "integrity": "sha512-hFILFCBGQcDwQLjl3qbeX3409ZSICHc3dai8dzTAx4rpAS0Q6Fz/n3okPTfrZ4IlwUUHSwBIf5k1uGLU7uT4zg==", "requires": { "dot-json": "^1.2.2", "lodash.clonedeep": "^4.5.0" diff --git a/package.json b/package.json index 41be93b6..c1d1ac39 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "node": ">=14" }, "scripts": { - "test": "node test" + "test": "node test", + "build:types": "npx tsc" }, "types": "./typings/index.d.ts", "directories": { @@ -26,6 +27,10 @@ "user-agents": "^1.0.778", "uuid": "^8.3.2" }, + "devDependencies": { + "@types/node": "^17.0.31", + "typescript": "^4.6.4" + }, "repository": { "type": "git", "url": "git+https//github.com/LuanRT/YouTube.js.git" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..82db405b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "declaration": true, + "emitDeclarationOnly": true, + "allowJs": true, + "outDir": "./typings", + "lib": ["ESNext"], + "target": "ESNext", + "moduleResolution": "node" + }, + "include": [ + "./lib/**/*.js", + "./index.js" + ], + "exclude": [ + "node_modules", + "**/*.d.ts" + ] +} \ No newline at end of file diff --git a/typings/index.d.ts b/typings/index.d.ts index 76425d6b..810e6c1d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,190 +1,2 @@ -interface AuthInfo { - access_token: string; - refresh_token: string; - expires: Date; -} - -interface AccountInfo { - name: string; - photo: Record[]; - country: string; - language: string; -} - -interface SearchOptions { - client: 'YTMUSIC' | 'YOUTUBE'; - period: 'any' | 'hour' | 'day' | 'week' | 'month' | 'year'; - order: 'relevance' | 'rating' | 'age' | 'views'; - duration: 'any' | 'short' | 'long'; -} - -interface YouTubeSearch { - query: string; - corrected_query: string; - estimated_results: number; - videos: any[]; - getContinuation: () => Promise; -} - -interface YouTubeMusicSearch { - query: string; - corrected_query: string; - results: { - top_result?: any[]; - songs?: any[]; - albums?: any[]; - videos?: any[]; - community_playlists?: any[]; - artists?: any[]; - } -} - -type SearchResults = YouTubeSearch | YouTubeMusicSearch; - -type ClientOption = Pick; - -type SortBy = 'TOP_COMMENTS' | 'NEWEST_FIRST'; - -interface Suggestion { - text: string; - bold_text: string; -} - -interface ApiStatus { - success: boolean; - status_code: number; - data: object; - message?: string; -} - -interface Comments { - page_count: number, - comment_count: number; - items: any[]; - getContinuation: () => Promise; -} - -interface Video { - title: string; - description: string; - thumbnail: object; - metadata: Record; - like: () => Promise; - dislike: () => Promise; - removeLike: () => Promise; - subscribe: () => Promise; - unsubscribe: () => Promise; - comment: (text: string) => Promise; - getComments: () => Promise; - getLivechat: () => any; // TODO type LiveChat - setNotificationPreferences: () => Promise; -} - -interface Channel { - title: string; - description: string; - metadata: object; - content: object; -} - -interface PlayList { - description: string; - items: any[]; - title: string; - total_items: string | number; - duration?: string; - last_updated?: string; - views?: string; - year?: string; -} - -interface History { - items: { - date: string; - videos: any[]; - }[]; - getContinuation: () => Promise; -} - -interface SubscriptionFeed { - items: { - date: string; - videos: any[]; - }[]; - getContinuation: () => Promise; -} - -interface HomeFeed { - videos: { - id: string; - title: string; - description: string; - channel: string; - metadata: Record; - }[]; - getContinuation: () => Promise; -} - -interface Trending { - now: { - content: { - title: string; - videos: []; - }[]; - }; - music: { getVideos: () => Promise; }; - gaming: { getVideos: () => Promise; }; - movies: { getVideos: () => Promise; }; -} - -interface Notifications { - items: { - title: string; - sent_time: string; - channel_name: string; - channel_thumbnail: Record; - video_thumbnail: Record; - video_url: string; - read: boolean; - notification_id: string; - }[]; - getContinuation: () => Promise; -} - -interface StreamingData { - selected_format: Record; - formats: any[]; -} -interface StreamingOptions { - quality?: string; - type?: string; - format?: string; -} - -interface Config { - gl?: string; - cookie?: string; -} - -export default class Innertube { - constructor(auth_info?: Config) - - public signIn(auth_info: AuthInfo): Promise; - public signOut(): Promise; - public getAccountInfo(): Promise; - public search(query: string, options: SearchOptions): Promise; - public getSearchSuggestions(query: string, options?: ClientOption): Promise; - public getDetails(video_id: string): Promise; - public getChannel(id: string): Promise; - public getLyrics(video_id: string): Promise; - public getPlaylist(playlist_id: string, options?: ClientOption): Promise; - public getComments(video_id: string, sort_by?: SortBy): Promise; - public getHistory(): Promise; - public getHomeFeed(): Promise; - public getTrending(): Promise; - public getSubscriptionsFeed(): Promise; - public getNotifications(): Promise; - public getUnseenNotificationsCount(): Promise; - public getStreamingData(id: string, options?: StreamingOptions): Promise; - public download(id: string, options?: StreamingOptions): ReadableStream; -} \ No newline at end of file +declare const _exports: typeof import("./lib/Innertube"); +export = _exports; diff --git a/typings/lib/Innertube.d.ts b/typings/lib/Innertube.d.ts new file mode 100644 index 00000000..1baec494 --- /dev/null +++ b/typings/lib/Innertube.d.ts @@ -0,0 +1,551 @@ +export = Innertube; +declare class Innertube { + /** + * ```js + * const Innertube = require('youtubei.js'); + * const youtube = await new Innertube(); + * ``` + * + * @param {object} [config] + * @param {string} [config.gl] + * @param {string} [config.cookie] + * @param {boolean} [config.debug] + * + * @returns {Innertube} + * @constructor + */ + constructor(config?: { + gl?: string; + cookie?: string; + debug?: boolean; + }); + config: { + gl?: string; + cookie?: string; + debug?: boolean; + }; + key: any; + version: any; + context: any; + logged_in: boolean; + player_url: any; + sts: any; + /** + * @fires Innertube#auth - fired when signing in to an account. + * @fires Innertube#update-credentials - fired when the access token is no longer valid. + * @type {EventEmitter} + */ + ev: EventEmitter; + auth_apisid: any; + request: Request; + actions: Actions; + account: { + info: () => Promise<{ + name: string; + photo: Array; + country: string; + language: string; + }>; + getTimeWatched: () => void; + settings: { + notifications: { + /** + * Notify about activity from the channels you're subscribed to. + * + * @param {boolean} new_value + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setSubscriptions: (new_value: boolean) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Recommended content notifications. + * + * @param {boolean} new_value + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setRecommendedVideos: (new_value: boolean) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Notify about activity on your channel. + * + * @param {boolean} new_value + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setChannelActivity: (new_value: boolean) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Notify about replies to your comments. + * + * @param {boolean} new_value + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setCommentReplies: (new_value: boolean) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Notify when others mention your channel. + * + * @param {boolean} new_value + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setMentions: (new_value: boolean) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Notify when others share your content on their channels. + * + * @param {boolean} new_value + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setSharedContent: (new_value: boolean) => Promise<{ + success: boolean; + status_code: string; + }>; + }; + privacy: { + /** + * If set to true, your subscriptions won't be visible to others. + * + * @param {boolean} new_value + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setSubscriptionsPrivate: (new_value: boolean) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * If set to true, saved playlists won't appear on your channel. + * + * @param {boolean} new_value + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setSavedPlaylistsPrivate: (new_value: boolean) => Promise<{ + success: boolean; + status_code: string; + }>; + }; + }; + }; + interact: { + /** + * Likes a given video. + * + * @param {string} video_id + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + like: (video_id: string) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Diskes a given video. + * + * @param {string} video_id + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + dislike: (video_id: string) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Removes a like/dislike. + * + * @param {string} video_id + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + removeLike: (video_id: string) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Posts a comment on a given video. + * + * @param {string} video_id + * @param {string} text + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + comment: (video_id: string, text: string) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Translates a given text using YouTube's comment translate feature. + * + * @param {string} text + * @param {string} target_language + * @param {object} [args] - optional arguments + * @param {string} [args.video_id] + * @param {string} [args.comment_id] + * + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + translate: (text: string, target_language: string, args?: { + video_id?: string; + comment_id?: string; + }) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Subscribes to a given channel. + * + * @param {string} channel_id + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + subscribe: (channel_id: string) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Unsubscribes from a given channel. + * + * @param {string} channel_id + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + unsubscribe: (channel_id: string) => Promise<{ + success: boolean; + status_code: string; + }>; + /** + * Changes notification preferences for a given channel. + * Only works with channels you are subscribed to. + * + * @param {string} channel_id + * @param {string} type PERSONALIZED | ALL | NONE + * @returns {Promise.<{ success: boolean; status_code: string; }>} + */ + setNotificationPreferences: (channel_id: string, type: string) => Promise<{ + success: boolean; + status_code: string; + }>; + }; + playlist: { + /** + * Creates a playlist. + * + * @param {string} title + * @param {string} video_ids + * + * @returns {Promise.<{ success: boolean; status_code: string; playlist_id: string; }>} + */ + create: (title: string, video_ids: string) => Promise<{ + success: boolean; + status_code: string; + playlist_id: string; + }>; + /** + * Deletes a given playlist. + * + * @param {string} playlist_id + * @returns {Promise.<{ success: boolean; status_code: string; playlist_id: string; }>} + */ + delete: (playlist_id: string) => Promise<{ + success: boolean; + status_code: string; + playlist_id: string; + }>; + /** + * 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; }>} + */ + addVideos: (playlist_id: string, video_ids: Array) => Promise<{ + success: boolean; + status_code: string; + playlist_id: string; + }>; + /** + * Removes videos from a given playlist. + * + * @param {string} playlist_id + * @param {Array.} video_ids + * @returns {Promise.<{ success: boolean; status_code: string; playlist_id: string; }>} + */ + removeVideos: (playlist_id: string, video_ids: Array) => Promise<{ + success: boolean; + status_code: string; + playlist_id: string; + }>; + }; + /** + * Signs-in to a google account. + * + * @param {object} auth_info + * @param {string} auth_info.access_token - Token used to sign in. + * @param {string} auth_info.refresh_token - Token used to get a new access token. + * @param {Date} auth_info.expires - Access token's expiration date, which is usually 24hrs-ish + * @returns {Promise.} + */ + signIn(auth_info?: { + access_token: string; + refresh_token: string; + expires: Date; + }): Promise; + access_token: any; + refresh_token: any; + /** + * Signs out of an account. + * @returns {Promise.<{ success: boolean; status_code: number }>} + */ + signOut(): Promise<{ + success: boolean; + status_code: number; + }>; + /** + * Retrieves account details. + * @returns {Promise.<{ name: string; photo: Array; country: string; language: string; }>} + */ + getAccountInfo(): Promise<{ + name: string; + photo: Array; + country: string; + language: string; + }>; + /** + * Searches on YouTube. + * + * @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.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?: { + client: string; + period: string; + order: string; + duration: string; + }): Promise<{ + query: string; + corrected_query: string; + estimated_results: number; + videos: []; + } | { + results: { + songs: []; + videos: []; + albums: []; + community_playlists: []; + }; + }>; + /** + * Retrieves search suggestions. + * + * @param {string} input - the search query. + * @param {object} [options] - search options. + * @param {string} [options.client='YOUTUBE'] - client used to retrieve search suggestions, can be: `YOUTUBE` or `YTMUSIC`. + * + * @returns {Promise.<[{ text: string; bold_text: string }]>} + */ + getSearchSuggestions(input: string, options?: { + client?: string; + }): Promise<[{ + text: string; + bold_text: string; + }]>; + /** + * Retrieves video info. + * + * @param {string} video_id - video id + * @return {Promise.<{ title: string; description: string; thumbnail: []; metadata: object }>} + */ + getDetails(video_id: string): Promise<{ + title: string; + description: string; + thumbnail: []; + metadata: object; + }>; + /** + * Retrieves comments for a video. + * + * @param {string} video_id - video id + * @param {string} [sort_by] - can be: `TOP_COMMENTS` or `NEWEST_FIRST`. + * @return {Promise.<{ page_count: number; comment_count: number; items: []; }>} + */ + getComments(video_id: string, sort_by?: string): Promise<{ + page_count: number; + comment_count: number; + items: []; + }>; + /** + * Retrieves contents for a given channel. (WIP) + * + * @param {string} id - channel id + * @return {Promise.<{ title: string; description: string; metadata: object; content: object }>} + */ + getChannel(id: string): Promise<{ + title: string; + description: string; + metadata: object; + content: object; + }>; + /** + * Retrieves watch history. + * @returns {Promise.<{ items: [{ date: string; videos: [] }] }>} + */ + getHistory(): Promise<{ + items: [{ + date: string; + videos: []; + }]; + }>; + /** + * Retrieves YouTube's home feed (aka recommendations). + * @returns {Promise.<{ videos: [{ id: string; title: string; description: string; channel: string; metadata: object }] }>} + */ + getHomeFeed(): Promise<{ + videos: [{ + id: string; + title: string; + description: string; + channel: string; + metadata: object; + }]; + }>; + /** + * Retrieves trending content. + * + * @returns {Promise.<{ now: { content: [{ title: string; videos: []; }] }; + * music: { getVideos: Promise.; }; gaming: { getVideos: Promise.; }; + * gaming: { getVideos: Promise.; }; }>} + */ + getTrending(): Promise<{ + now: { + content: [{ + title: string; + videos: []; + }]; + }; + music: { + getVideos: Promise; + }; + gaming: { + getVideos: Promise; + }; + gaming: { + getVideos: Promise; + }; + }>; + /** + * WIP + */ + getLibrary(): Promise; + /** + * Retrieves subscriptions feed. + * @returns {Promise.<{ items: [{ date: string; videos: [] }] }>} + */ + getSubscriptionsFeed(): Promise<{ + items: [{ + date: string; + videos: []; + }]; + }>; + /** + * Retrieves your notifications. + * @returns {Promise.<{ items: [{ title: string; sent_time: string; channel_name: string; channel_thumbnail: {}; video_thumbnail: {}; video_url: string; read: boolean; notification_id: string }] }>} + */ + getNotifications(): Promise<{ + items: [{ + title: string; + sent_time: string; + channel_name: string; + channel_thumbnail: {}; + video_thumbnail: {}; + video_url: string; + read: boolean; + notification_id: string; + }]; + }>; + /** + * Retrieves unseen notifications count. + * @returns {Promise.} + */ + getUnseenNotificationsCount(): Promise; + /** + * Retrieves lyrics for a given song if available. + * + * @param {string} video_id + * @returns {Promise.} + */ + getLyrics(video_id: string): Promise; + /** + * Retrieves a given playlist. + * + * @param {string} playlist_id - playlist id. + * @param {object} options - { client: YOUTUBE | YTMUSIC } + * @param {string} options.client - client used to parse the playlist, can be: `YTMUSIC` | `YOUTUBE` + * @returns {Promise.< + * { title: string; description: string; total_items: string; last_updated: string; views: string; items: [] } | + * { title: string; description: string; total_items: number; duration: string; year: string; items: [] }>} + */ + getPlaylist(playlist_id: string, options?: { + client: string; + }): Promise<{ + title: string; + description: string; + total_items: string; + last_updated: string; + views: string; + items: []; + } | { + title: string; + description: string; + total_items: number; + duration: string; + year: string; + items: []; + }>; + /** + * An alternative to {@link download}. + * Returns deciphered streaming data. + * + * @param {string} 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 + * @param {string} options.format - file format + * + * @returns {Promise.<{ selected_format: {}; formats: [] }>} + */ + getStreamingData(id: string, options?: { + quality: string; + type: string; + format: string; + }): Promise<{ + selected_format: {}; + formats: []; + }>; + /** + * Downloads a given video. If you only need the direct download link take a look at {@link getStreamingData}. + * + * @param {string} 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 + * @param {string} [options.format] - file format + * + * @return {Stream.PassThrough} + */ + download(id: string, options?: { + quality?: string; + type?: string; + format?: string; + }): Stream.PassThrough; + #private; +} +import Request = require("./utils/Request"); +import Actions = require("./core/Actions"); diff --git a/typings/lib/core/Actions.d.ts b/typings/lib/core/Actions.d.ts new file mode 100644 index 00000000..751bf9f8 --- /dev/null +++ b/typings/lib/core/Actions.d.ts @@ -0,0 +1,252 @@ +export = Actions; +declare class Actions { + constructor(session: any); + /** + * Covers Innertube's browse endpoint, mostly used to + * access YouTube's sections such as the home page + * and sometimes to retrieve continuations. + * + * @param {string} id - browseId or a continuation token + * @param {object} args - additional arguments + * @param {string} [args.params] + * @param {boolean} [args.is_ytm] + * @param {boolean} [args.is_ctoken] + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object }>} + */ + browse(id: string, args?: { + params?: string; + is_ytm?: boolean; + is_ctoken?: boolean; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers endpoints used to perform direct interactions + * on YouTube. + * + * @param {string} action + * @param {object} args + * @param {string} [args.video_id] + * @param {string} [args.channel_id] + * @param {string} [args.comment_id] + * @param {string} [args.comment_action] + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + engage(action: string, args?: { + video_id?: string; + channel_id?: string; + comment_id?: string; + comment_action?: string; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers endpoints related to account management. + * + * @param {string} action + * @param {object} args + * @param {string} args.new_value + * @param {string} args.setting_item_id + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object }>} + */ + account(action: string, args?: { + new_value: string; + setting_item_id: string; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers endpoint used for searches. + * + * @param {object} args + * @param {string} args.query + * @param {object} args.options + * @param {string} args.options.period + * @param {string} args.options.duration + * @param {string} args.options.order + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + search(args?: { + query: string; + options: { + period: string; + duration: string; + order: string; + }; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Endpoint used fo Shorts' sound search. + * + * @param {object} args + * @param {string} args.query + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + searchSound(args?: { + query: string; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers endpoints used for playlist management. + * + * @param {string} action + * @param {object} args + * @param {string} [args.title] + * @param {string} [args.ids] + * @param {string} [args.playlist_id] + * @param {string} [args.action] + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + playlist(action: string, args?: { + title?: string; + ids?: string; + playlist_id?: string; + action?: string; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers endpoints used for notifications management. + * + * @param {string} action + * @param {object} args + * @param {string} [args.pref] + * @param {string} [args.channel_id] + * @param {string} [args.ctoken] + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + notifications(action: string, args: { + pref?: string; + channel_id?: string; + ctoken?: string; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers livechat endpoints. + * + * @param {string} action + * @param {object} args + * @param {string} [args.text] + * @param {string} [args.video_id] + * @param {string} [args.channel_id] + * @param {string} [args.ctoken] + * @param {string} [args.params] + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + livechat(action: string, args?: { + text?: string; + video_id?: string; + channel_id?: string; + ctoken?: string; + params?: string; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers endpoints used to report content. + * + * @param {string} action + * @param {object} args + * @param {object} [args.action] + * @param {string} [args.params] + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + flag(action: string, args: { + action?: object; + params?: string; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers specific YouTube Music endpoints. + * + * @param {string} action + * @param {string} args.input + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + music(action: string, args: any): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Mostly used to retrieve data continuation for + * previously executed actions. + * + * @param {string} action + * @param {object} args + * @param {string} args.video_id + * @param {string} args.channel_id + * @param {string} args.ctoken + * @param {boolean} is_ytm + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + next(args?: { + video_id: string; + channel_id: string; + ctoken: string; + }): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Used to retrieve video info. + * + * @param {string} id + * @param {string} [cpn] + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + getVideoInfo(id: string, cpn?: string): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + /** + * Covers search suggestion endpoints. + * + * @param {string} client + * @param {string} input + * + * @returns {Promise.<{ success: boolean; status_code: number; data: object; }>} + */ + getSearchSuggestions(client: string, input: string): Promise<{ + success: boolean; + status_code: number; + data: object; + }>; + #private; +} diff --git a/typings/lib/core/Livechat.d.ts b/typings/lib/core/Livechat.d.ts new file mode 100644 index 00000000..a054b698 --- /dev/null +++ b/typings/lib/core/Livechat.d.ts @@ -0,0 +1,23 @@ +export = Livechat; +declare class Livechat { + constructor(session: any, token: any, channel_id: any, video_id: any); + ctoken: any; + session: any; + video_id: any; + channel_id: any; + message_queue: any[]; + id_cache: any[]; + poll_intervals_ms: number; + running: boolean; + metadata_ctoken: any; + livechat_poller: any; + sendMessage(text: any): Promise; + /** + * Blocks a user. + * @todo Implement this method. + * @param {object} msg_params + */ + blockUser(msg_params: object): Promise; + stop(): void; + #private; +} diff --git a/typings/lib/core/OAuth.d.ts b/typings/lib/core/OAuth.d.ts new file mode 100644 index 00000000..a87b08ad --- /dev/null +++ b/typings/lib/core/OAuth.d.ts @@ -0,0 +1,35 @@ +export = OAuth; +declare class OAuth { + constructor(ev: any); + /** + * Starts the auth flow in case no valid credentials are available. + * @returns {Promise.} + */ + init(auth_info: any): Promise; + client_id: string; + client_secret: string; + refresh_interval: any; + /** + * Refreshes the access token if necessary. + * @returns {Promise.} + */ + checkTokenValidity(): Promise; + /** + * Revokes access token (note that the refresh token will also be revoked). + * @returns {Promise.} + */ + revokeAccessToken(): Promise; + getAccessToken(): any; + getRefreshToken(): any; + /** + * Checks if the auth info is valid. + * @returns {boolean} true | false + */ + isValidAuthInfo(): boolean; + /** + * Checks access token validity. + * @returns {boolean} true | false + */ + shouldRefreshToken(): boolean; + #private; +} diff --git a/typings/lib/core/Player.d.ts b/typings/lib/core/Player.d.ts new file mode 100644 index 00000000..38691035 --- /dev/null +++ b/typings/lib/core/Player.d.ts @@ -0,0 +1,11 @@ +export = Player; +declare class Player { + constructor(id: any); + init(): Promise; + get url(): string; + get sts(): any; + get ntoken_decipher(): any; + get signature_decipher(): any; + isCached(): any; + #private; +} diff --git a/typings/lib/core/SessionBuilder.d.ts b/typings/lib/core/SessionBuilder.d.ts new file mode 100644 index 00000000..15edb46a --- /dev/null +++ b/typings/lib/core/SessionBuilder.d.ts @@ -0,0 +1,12 @@ +export = SessionBuilder; +declare class SessionBuilder { + constructor(config: any); + build(): Promise; + get key(): any; + get context(): any; + get api_version(): any; + get client_version(): any; + get client_name(): any; + get player(): any; + #private; +} diff --git a/typings/lib/deciphers/NToken.d.ts b/typings/lib/deciphers/NToken.d.ts new file mode 100644 index 00000000..6068d357 --- /dev/null +++ b/typings/lib/deciphers/NToken.d.ts @@ -0,0 +1,12 @@ +export = NToken; +declare class NToken { + constructor(raw_code: any, n: any); + n: any; + raw_code: any; + /** + * Solves throttling challange by transforming the n token. + * @returns {string} + */ + transform(): string; + #private; +} diff --git a/typings/lib/deciphers/Signature.d.ts b/typings/lib/deciphers/Signature.d.ts new file mode 100644 index 00000000..1e95a683 --- /dev/null +++ b/typings/lib/deciphers/Signature.d.ts @@ -0,0 +1,12 @@ +export = Signature; +declare class Signature { + constructor(url: any, sig_decipher_sc: any); + url: any; + sig_decipher_sc: any; + /** + * Deciphers signature. + * @returns {string} + */ + decipher(): string; + #private; +} diff --git a/typings/lib/parser/index.d.ts b/typings/lib/parser/index.d.ts new file mode 100644 index 00000000..6fdbae58 --- /dev/null +++ b/typings/lib/parser/index.d.ts @@ -0,0 +1,9 @@ +export = Parser; +declare class Parser { + constructor(session: any, data: any, args?: {}); + data: any; + session: any; + args: {}; + parse(): any; + #private; +} diff --git a/typings/lib/parser/youtube/index.d.ts b/typings/lib/parser/youtube/index.d.ts new file mode 100644 index 00000000..3a9bdf36 --- /dev/null +++ b/typings/lib/parser/youtube/index.d.ts @@ -0,0 +1,11 @@ +import VideoResultItem = require("./search/VideoResultItem"); +import SearchSuggestionItem = require("./search/SearchSuggestionItem"); +import PlaylistItem = require("./others/PlaylistItem"); +import NotificationItem = require("./others/NotificationItem"); +import VideoItem = require("./others/VideoItem"); +import GridVideoItem = require("./others/GridVideoItem"); +import GridPlaylistItem = require("./others/GridPlaylistItem"); +import ChannelMetadata = require("./others/ChannelMetadata"); +import ShelfRenderer = require("./others/ShelfRenderer"); +import CommentThread = require("./others/CommentThread"); +export { VideoResultItem, SearchSuggestionItem, PlaylistItem, NotificationItem, VideoItem, GridVideoItem, GridPlaylistItem, ChannelMetadata, ShelfRenderer, CommentThread }; diff --git a/typings/lib/parser/youtube/others/ChannelMetadata.d.ts b/typings/lib/parser/youtube/others/ChannelMetadata.d.ts new file mode 100644 index 00000000..0057c7aa --- /dev/null +++ b/typings/lib/parser/youtube/others/ChannelMetadata.d.ts @@ -0,0 +1,15 @@ +export = ChannelMetadata; +declare class ChannelMetadata { + static parse(data: any): { + title: any; + description: any; + metadata: { + url: any; + rss_urls: any; + vanity_channel_url: any; + external_id: any; + is_family_safe: any; + keywords: any; + }; + }; +} diff --git a/typings/lib/parser/youtube/others/CommentThread.d.ts b/typings/lib/parser/youtube/others/CommentThread.d.ts new file mode 100644 index 00000000..971d2ee4 --- /dev/null +++ b/typings/lib/parser/youtube/others/CommentThread.d.ts @@ -0,0 +1,23 @@ +export = CommentThread; +declare class CommentThread { + static parseItem(item: any): { + text: any; + author: { + name: any; + thumbnails: any; + channel_id: any; + channel_url: string; + }; + metadata: { + published: any; + is_reply: boolean; + is_liked: any; + is_disliked: any; + is_pinned: boolean; + is_channel_owner: any; + like_count: number; + reply_count: any; + id: any; + }; + }; +} diff --git a/typings/lib/parser/youtube/others/GridPlaylistItem.d.ts b/typings/lib/parser/youtube/others/GridPlaylistItem.d.ts new file mode 100644 index 00000000..b990a83c --- /dev/null +++ b/typings/lib/parser/youtube/others/GridPlaylistItem.d.ts @@ -0,0 +1,12 @@ +export = GridPlaylistItem; +declare class GridPlaylistItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + metadata: { + thumbnail: any; + video_count: any; + }; + }; +} diff --git a/typings/lib/parser/youtube/others/GridVideoItem.d.ts b/typings/lib/parser/youtube/others/GridVideoItem.d.ts new file mode 100644 index 00000000..da609705 --- /dev/null +++ b/typings/lib/parser/youtube/others/GridVideoItem.d.ts @@ -0,0 +1,25 @@ +export = GridVideoItem; +declare class GridVideoItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + channel: { + id: any; + name: any; + url: string; + }; + metadata: { + view_count: any; + short_view_count_text: { + simple_text: any; + accessibility_label: any; + }; + thumbnail: any; + moving_thumbnail: any; + published: any; + badges: any; + owner_badges: any; + }; + }; +} diff --git a/typings/lib/parser/youtube/others/NotificationItem.d.ts b/typings/lib/parser/youtube/others/NotificationItem.d.ts new file mode 100644 index 00000000..d0e779c6 --- /dev/null +++ b/typings/lib/parser/youtube/others/NotificationItem.d.ts @@ -0,0 +1,14 @@ +export = NotificationItem; +declare class NotificationItem { + static parse(data: any): any; + static parseItem(item: any): { + title: any; + sent_time: any; + channel_name: any; + channel_thumbnail: any; + video_thumbnail: any; + video_url: string; + read: any; + notification_id: any; + }; +} diff --git a/typings/lib/parser/youtube/others/PlaylistItem.d.ts b/typings/lib/parser/youtube/others/PlaylistItem.d.ts new file mode 100644 index 00000000..54e2e450 --- /dev/null +++ b/typings/lib/parser/youtube/others/PlaylistItem.d.ts @@ -0,0 +1,15 @@ +export = PlaylistItem; +declare class PlaylistItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + author: any; + duration: { + seconds: number; + simple_text: any; + accessibility_label: any; + }; + thumbnails: any; + }; +} diff --git a/typings/lib/parser/youtube/others/ShelfRenderer.d.ts b/typings/lib/parser/youtube/others/ShelfRenderer.d.ts new file mode 100644 index 00000000..cf080bed --- /dev/null +++ b/typings/lib/parser/youtube/others/ShelfRenderer.d.ts @@ -0,0 +1,9 @@ +export = ShelfRenderer; +declare class ShelfRenderer { + static parse(data: any): { + title: any; + videos: any; + }; + static getTitle(data: any): any; + static parseItems(data: any): any; +} diff --git a/typings/lib/parser/youtube/others/VideoItem.d.ts b/typings/lib/parser/youtube/others/VideoItem.d.ts new file mode 100644 index 00000000..38e42c75 --- /dev/null +++ b/typings/lib/parser/youtube/others/VideoItem.d.ts @@ -0,0 +1,31 @@ +export = VideoItem; +declare class VideoItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + description: any; + channel: { + id: any; + name: any; + url: string; + }; + metadata: { + view_count: any; + short_view_count_text: { + simple_text: any; + accessibility_label: any; + }; + thumbnail: any; + moving_thumbnail: any; + published: any; + duration: { + seconds: number; + simple_text: any; + accessibility_label: any; + }; + badges: any; + owner_badges: any; + }; + }; +} diff --git a/typings/lib/parser/youtube/search/SearchSuggestionItem.d.ts b/typings/lib/parser/youtube/search/SearchSuggestionItem.d.ts new file mode 100644 index 00000000..d382ab08 --- /dev/null +++ b/typings/lib/parser/youtube/search/SearchSuggestionItem.d.ts @@ -0,0 +1,4 @@ +export = SearchSuggestionItem; +declare class SearchSuggestionItem { + static parse(data: any, bold_text: any): any; +} diff --git a/typings/lib/parser/youtube/search/VideoResultItem.d.ts b/typings/lib/parser/youtube/search/VideoResultItem.d.ts new file mode 100644 index 00000000..65e06c68 --- /dev/null +++ b/typings/lib/parser/youtube/search/VideoResultItem.d.ts @@ -0,0 +1,31 @@ +export = VideoResultItem; +declare class VideoResultItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + url: string; + title: any; + description: any; + channel: { + id: any; + name: any; + url: string; + }; + metadata: { + view_count: any; + short_view_count_text: { + simple_text: any; + accessibility_label: any; + }; + thumbnails: any; + duration: { + seconds: number; + simple_text: any; + accessibility_label: any; + }; + published: any; + badges: any; + owner_badges: any; + }; + }; +} diff --git a/typings/lib/parser/ytmusic/index.d.ts b/typings/lib/parser/ytmusic/index.d.ts new file mode 100644 index 00000000..f22d9dbf --- /dev/null +++ b/typings/lib/parser/ytmusic/index.d.ts @@ -0,0 +1,9 @@ +import SongResultItem = require("./search/SongResultItem"); +import VideoResultItem = require("./search/VideoResultItem"); +import AlbumResultItem = require("./search/AlbumResultItem"); +import ArtistResultItem = require("./search/ArtistResultItem"); +import PlaylistResultItem = require("./search/PlaylistResultItem"); +import MusicSearchSuggestionItem = require("./search/MusicSearchSuggestionItem"); +import TopResultItem = require("./search/TopResultItem"); +import PlaylistItem = require("./others/PlaylistItem"); +export { SongResultItem, VideoResultItem, AlbumResultItem, ArtistResultItem, PlaylistResultItem, MusicSearchSuggestionItem, TopResultItem, PlaylistItem }; diff --git a/typings/lib/parser/ytmusic/others/PlaylistItem.d.ts b/typings/lib/parser/ytmusic/others/PlaylistItem.d.ts new file mode 100644 index 00000000..6e7bdbf1 --- /dev/null +++ b/typings/lib/parser/ytmusic/others/PlaylistItem.d.ts @@ -0,0 +1,14 @@ +export = PlaylistItem; +declare class PlaylistItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + author: any; + duration: { + seconds: number; + simple_text: any; + }; + thumbnails: any; + }; +} diff --git a/typings/lib/parser/ytmusic/search/AlbumResultItem.d.ts b/typings/lib/parser/ytmusic/search/AlbumResultItem.d.ts new file mode 100644 index 00000000..13cf5182 --- /dev/null +++ b/typings/lib/parser/ytmusic/search/AlbumResultItem.d.ts @@ -0,0 +1,11 @@ +export = AlbumResultItem; +declare class AlbumResultItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + author: any; + year: any; + thumbnails: any; + }; +} diff --git a/typings/lib/parser/ytmusic/search/ArtistResultItem.d.ts b/typings/lib/parser/ytmusic/search/ArtistResultItem.d.ts new file mode 100644 index 00000000..01b10e58 --- /dev/null +++ b/typings/lib/parser/ytmusic/search/ArtistResultItem.d.ts @@ -0,0 +1,10 @@ +export = ArtistResultItem; +declare class ArtistResultItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + name: any; + subscribers: any; + thumbnails: any; + }; +} diff --git a/typings/lib/parser/ytmusic/search/MusicSearchSuggestionItem.d.ts b/typings/lib/parser/ytmusic/search/MusicSearchSuggestionItem.d.ts new file mode 100644 index 00000000..2891d377 --- /dev/null +++ b/typings/lib/parser/ytmusic/search/MusicSearchSuggestionItem.d.ts @@ -0,0 +1,8 @@ +export = MusicSearchSuggestionItem; +declare class MusicSearchSuggestionItem { + static parse(data: any): any; + static parseItem(item: any): { + text: any; + bold_text: any; + }; +} diff --git a/typings/lib/parser/ytmusic/search/PlaylistResultItem.d.ts b/typings/lib/parser/ytmusic/search/PlaylistResultItem.d.ts new file mode 100644 index 00000000..0a4d4e15 --- /dev/null +++ b/typings/lib/parser/ytmusic/search/PlaylistResultItem.d.ts @@ -0,0 +1,11 @@ +export = PlaylistResultItem; +declare class PlaylistResultItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + author: any; + channel_id: any; + total_items: number; + }; +} diff --git a/typings/lib/parser/ytmusic/search/SongResultItem.d.ts b/typings/lib/parser/ytmusic/search/SongResultItem.d.ts new file mode 100644 index 00000000..c36f509a --- /dev/null +++ b/typings/lib/parser/ytmusic/search/SongResultItem.d.ts @@ -0,0 +1,12 @@ +export = SongResultItem; +declare class SongResultItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + artist: any; + album: any; + duration: any; + thumbnails: any; + }; +} diff --git a/typings/lib/parser/ytmusic/search/TopResultItem.d.ts b/typings/lib/parser/ytmusic/search/TopResultItem.d.ts new file mode 100644 index 00000000..10d187ac --- /dev/null +++ b/typings/lib/parser/ytmusic/search/TopResultItem.d.ts @@ -0,0 +1,4 @@ +export = TopResultItem; +declare class TopResultItem { + static parse(data: any): any; +} diff --git a/typings/lib/parser/ytmusic/search/VideoResultItem.d.ts b/typings/lib/parser/ytmusic/search/VideoResultItem.d.ts new file mode 100644 index 00000000..5ace4608 --- /dev/null +++ b/typings/lib/parser/ytmusic/search/VideoResultItem.d.ts @@ -0,0 +1,12 @@ +export = VideoResultItem; +declare class VideoResultItem { + static parse(data: any): any; + static parseItem(item: any): { + id: any; + title: any; + author: any; + views: any; + duration: any; + thumbnails: any; + }; +} diff --git a/typings/lib/proto/index.d.ts b/typings/lib/proto/index.d.ts new file mode 100644 index 00000000..0eaee7b8 --- /dev/null +++ b/typings/lib/proto/index.d.ts @@ -0,0 +1,100 @@ +export = Proto; +declare class Proto { + /** + * Encodes visitor data. + * + * @param {string} id + * @param {number} timestamp + * + * @returns {string} + */ + static encodeVisitorData(id: string, timestamp: number): string; + /** + * Encodes search filters. + * + * @param {string} period + * @param {string} duration + * @param {string} order + * + * @todo implement remaining filters. + * + * @returns {string} + */ + static encodeSearchFilter(period: string, duration: string, order: string): string; + /** + * Encodes livechat message parameters. + * + * @param {string} channel_id + * @param {string} video_id + * + * @returns {string} + */ + static encodeMessageParams(channel_id: string, video_id: string): string; + /** + * Encodes comment section parameters. + * + * @param {string} video_id + * @param {object} options + * @param {string} options.type + * @param {string} options.sort_by + * + * @returns {string} + */ + static encodeCommentsSectionParams(video_id: string, options?: { + type: string; + sort_by: string; + }): string; + /** + * Encodes replies thread parameters. + * + * @param {string} video_id + * @param {string} comment_id + * + * @returns {string} + */ + static encodeCommentRepliesParams(video_id: string, comment_id: string): string; + /** + * Encodes comment parameters. + * + * @param {string} video_id + * @returns {string} + */ + static encodeCommentParams(video_id: string): string; + /** + * Encodes comment reply parameters. + * + * @param {string} comment_id + * @param {string} video_id + * + * @return {string} + */ + static encodeCommentReplyParams(comment_id: string, video_id: string): string; + /** + * Encodes comment action parameters. + * + * @param {string} type + * @param {string} comment_id + * @param {string} video_id + * @param {string} [text] + * @param {string} [target_language] + * + * @returns {string} + */ + static encodeCommentActionParams(type: string, args?: {}): string; + /** + * Encodes notification preference parameters. + * + * @param {string} channel_id + * @param {number} index + * + * @returns {string} + */ + static encodeNotificationPref(channel_id: string, index: number): string; + /** + * Encodes sound info parameters. + * + * @param {string} id + * @returns {string} + */ + static encodeSoundInfoParams(id: string): string; +} diff --git a/typings/lib/proto/messages.d.ts b/typings/lib/proto/messages.d.ts new file mode 100644 index 00000000..d9e8eb59 --- /dev/null +++ b/typings/lib/proto/messages.d.ts @@ -0,0 +1,96 @@ +export namespace VisitorData { + const buffer: boolean; + const encodingLength: any; + const encode: any; + const decode: any; +} +export namespace InnertubePayload { + const buffer_1: boolean; + export { buffer_1 as buffer }; + const encodingLength_1: any; + export { encodingLength_1 as encodingLength }; + const encode_1: any; + export { encode_1 as encode }; + const decode_1: any; + export { decode_1 as decode }; +} +export namespace SoundInfoParams { + const buffer_2: boolean; + export { buffer_2 as buffer }; + const encodingLength_2: any; + export { encodingLength_2 as encodingLength }; + const encode_2: any; + export { encode_2 as encode }; + const decode_2: any; + export { decode_2 as decode }; +} +export namespace NotificationPreferences { + const buffer_3: boolean; + export { buffer_3 as buffer }; + const encodingLength_3: any; + export { encodingLength_3 as encodingLength }; + const encode_3: any; + export { encode_3 as encode }; + const decode_3: any; + export { decode_3 as decode }; +} +export namespace LiveMessageParams { + const buffer_4: boolean; + export { buffer_4 as buffer }; + const encodingLength_4: any; + export { encodingLength_4 as encodingLength }; + const encode_4: any; + export { encode_4 as encode }; + const decode_4: any; + export { decode_4 as decode }; +} +export namespace GetCommentsSectionParams { + const buffer_5: boolean; + export { buffer_5 as buffer }; + const encodingLength_5: any; + export { encodingLength_5 as encodingLength }; + const encode_5: any; + export { encode_5 as encode }; + const decode_5: any; + export { decode_5 as decode }; +} +export namespace CreateCommentParams { + const buffer_6: boolean; + export { buffer_6 as buffer }; + const encodingLength_6: any; + export { encodingLength_6 as encodingLength }; + const encode_6: any; + export { encode_6 as encode }; + const decode_6: any; + export { decode_6 as decode }; +} +export namespace CreateCommentReplyParams { + const buffer_7: boolean; + export { buffer_7 as buffer }; + const encodingLength_7: any; + export { encodingLength_7 as encodingLength }; + const encode_7: any; + export { encode_7 as encode }; + const decode_7: any; + export { decode_7 as decode }; +} +export namespace PeformCommentActionParams { + const buffer_8: boolean; + export { buffer_8 as buffer }; + const encodingLength_8: any; + export { encodingLength_8 as encodingLength }; + const encode_8: any; + export { encode_8 as encode }; + const decode_8: any; + export { decode_8 as decode }; +} +export namespace SearchFilter { + const buffer_9: boolean; + export { buffer_9 as buffer }; + const encodingLength_9: any; + export { encodingLength_9 as encodingLength }; + const encode_9: any; + export { encode_9 as encode }; + const decode_9: any; + export { decode_9 as decode }; +} diff --git a/typings/lib/utils/Constants.d.ts b/typings/lib/utils/Constants.d.ts new file mode 100644 index 00000000..f3a9ace7 --- /dev/null +++ b/typings/lib/utils/Constants.d.ts @@ -0,0 +1,90 @@ +export namespace URLS { + const YT_BASE: string; + const YT_BASE_API: string; + const YT_STUDIO_BASE_API: string; + const YT_SUGGESTIONS: string; + const YT_MUSIC: string; + const YT_MUSIC_BASE_API: string; +} +export namespace OAUTH { + const SCOPE: string; + const GRANT_TYPE: string; + const MODEL_NAME: string; + namespace HEADERS { + const headers: { + accept: string; + origin: string; + 'user-agent': string; + 'content-type': string; + referer: string; + 'accept-language': string; + }; + } + namespace REGEX { + const AUTH_SCRIPT: RegExp; + const CLIENT_IDENTITY: RegExp; + } +} +export namespace CLIENTS { + namespace YTMUSIC { + const NAME: string; + const VERSION: string; + } + namespace ANDROID { + const NAME_1: string; + export { NAME_1 as NAME }; + const VERSION_1: string; + export { VERSION_1 as VERSION }; + } +} +export const STREAM_HEADERS: { + Accept: string; + 'User-Agent': any; + Connection: string; + Origin: string; + Referer: string; + DNT: string; +}; +export const INNERTUBE_HEADERS_BASE: { + accept: string; + 'content-type': string; +}; +export const METADATA_KEYS: string[]; +export const BLACKLISTED_KEYS: string[]; +export namespace ACCOUNT_SETTINGS { + const SUBSCRIPTIONS: string; + const RECOMMENDED_VIDEOS: string; + const CHANNEL_ACTIVITY: string; + const COMMENT_REPLIES: string; + const USER_MENTION: string; + const SHARED_CONTENT: string; + const PLAYLISTS_PRIVACY: string; + const SUBSCRIPTIONS_PRIVACY: string; +} +export namespace BASE64_DIALECT { + const NORMAL: string[]; + const REVERSE: string[]; +} +export namespace SIG_REGEX { + const ACTIONS: RegExp; + const FUNCTIONS: RegExp; +} +export namespace NTOKEN_REGEX { + export const CALLS: RegExp; + export const PLACEHOLDERS: RegExp; + const FUNCTIONS_1: RegExp; + export { FUNCTIONS_1 as FUNCTIONS }; +} +export namespace FUNCS { + const PUSH: string; + const REVERSE_1: string; + const REVERSE_2: string; + const SPLICE: string; + const SWAP0_1: string; + const SWAP0_2: string; + const ROTATE_1: string; + const ROTATE_2: string; + const BASE64_DIA: string; + const TRANSLATE_1: string; + const TRANSLATE_2: string; +} diff --git a/typings/lib/utils/Request.d.ts b/typings/lib/utils/Request.d.ts new file mode 100644 index 00000000..97b7f033 --- /dev/null +++ b/typings/lib/utils/Request.d.ts @@ -0,0 +1,7 @@ +export = Request; +declare class Request { + constructor(session: any); + session: any; + instance: any; + #private; +} diff --git a/typings/lib/utils/Utils.d.ts b/typings/lib/utils/Utils.d.ts new file mode 100644 index 00000000..7183c5c1 --- /dev/null +++ b/typings/lib/utils/Utils.d.ts @@ -0,0 +1,70 @@ +export class InnertubeError extends Error { + constructor(message: any, info: any); + info: any; + date: Date; + version: any; +} +export class UnavailableContentError extends InnertubeError { +} +export class ParsingError extends InnertubeError { +} +export class DownloadError extends InnertubeError { +} +export class MissingParamError extends InnertubeError { +} +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. + */ +export function findNode(obj: object, key: string, target: string, depth: number, safe?: boolean): any; +/** + * Returns a random user agent. + * + * @param {string} type - mobile | desktop + * @returns {object} + */ +export function getRandomUserAgent(type: string): object; +/** + * Generates an authentication token from a cookies' sid. + * + * @param {string} sid - Sid extracted from cookies + * @returns {string} + */ +export function generateSidAuth(sid: string): string; +export function generateRandomString(length: any): string; +/** + * Gets a string between two delimiters. + * + * @param {string} data - The data. + * @param {string} start_string - Start string. + * @param {string} end_string - End string. + */ +export function getStringBetweenStrings(data: string, start_string: string, end_string: string): string; +/** + * Converts strings in camelCase to snake_case. + * + * @param {string} string The string in camelCase. + * @returns {string} + */ +export function camelToSnake(string: string): string; +/** + * Converts time (h:m:s) to seconds. + * + * @param {string} time + * @returns {number} seconds + */ +export function timeToSeconds(time: string): number; +/** + * Turns the ntoken transform data into a valid json array + * + * @param {string} data + * @returns {string} + */ +export function refineNTokenData(data: string): string;