diff --git a/src/Innertube.ts b/src/Innertube.ts index 3562339b..86b61b62 100644 --- a/src/Innertube.ts +++ b/src/Innertube.ts @@ -38,24 +38,11 @@ import * as Constants from './utils/Constants.js'; import { InnertubeError, generateRandomString, throwIfMissing } from './utils/Utils.js'; import type { ApiResponse } from './core/Actions.js'; -import type { INextRequest } from './types/index.js'; +import type { InnerTubeConfig, InnerTubeClient, SearchFilters, INextRequest } from './types/index.js'; import type { IBrowseResponse, IParsedResponse } from './parser/types/index.js'; import type { DownloadOptions, FormatOptions } from './types/FormatUtils.js'; -import type { SessionOptions } from './core/Session.js'; import type Format from './parser/classes/misc/Format.js'; -export type InnerTubeConfig = SessionOptions; - -export type InnerTubeClient = 'IOS' | 'WEB' | 'ANDROID' | 'YTMUSIC' | 'YTMUSIC_ANDROID' | 'YTSTUDIO_ANDROID' | 'TV_EMBEDDED' | 'YTKIDS'; - -export type SearchFilters = Partial<{ - upload_date: 'all' | 'hour' | 'today' | 'week' | 'month' | 'year'; - type: 'all' | 'video' | 'channel' | 'playlist' | 'movie'; - duration: 'all' | 'short' | 'medium' | 'long'; - sort_by: 'relevance' | 'rating' | 'upload_date' | 'view_count'; - features: ('hd' | 'subtitles' | 'creative_commons' | '3d' | 'live' | 'purchased' | '4k' | '360' | 'location' | 'hdr' | 'vr180')[]; -}>; - /** * Provides access to various services and modules in the YouTube API. */ @@ -103,7 +90,7 @@ export default class Innertube { const player_response = this.actions.execute(PlayerEndpoint.PATH, player_payload); const next_response = this.actions.execute(NextEndpoint.PATH, next_payload); - const response = await Promise.all([ player_response, next_response ]); + const response = await Promise.all([player_response, next_response]); const cpn = generateRandomString(16); @@ -124,7 +111,7 @@ export default class Innertube { const cpn = generateRandomString(16); - return new VideoInfo([ response ], this.actions, cpn); + return new VideoInfo([response], this.actions, cpn); } async getShortsVideoInfo(video_id: string, client?: InnerTubeClient): Promise { @@ -140,11 +127,11 @@ export default class Innertube { }) ); - const response = await Promise.all([ watch_response, sequence_response ]); + const response = await Promise.all([watch_response, sequence_response]); const cpn = generateRandomString(16); - return new ShortFormVideoInfo([ response[0] ], this.actions, cpn, response[1]); + return new ShortFormVideoInfo([response[0]], this.actions, cpn, response[1]); } async search(query: string, filters: SearchFilters = {}): Promise { diff --git a/src/core/clients/Studio.ts b/src/core/clients/Studio.ts index 81ebd31c..2b2d6bd3 100644 --- a/src/core/clients/Studio.ts +++ b/src/core/clients/Studio.ts @@ -3,7 +3,7 @@ import { Constants } from '../../utils/index.js'; import { InnertubeError, MissingParamError, Platform } from '../../utils/Utils.js'; import { CreateVideoEndpoint } from '../endpoints/upload/index.js'; -import type { UpdateVideoMetadataOptions, UploadedVideoMetadataOptions } from '../../types/Clients.js'; +import type { UpdateVideoMetadataOptions, UploadedVideoMetadataOptions } from '../../types/Misc.js'; import type { ApiResponse, Session } from '../index.js'; interface UploadResult { diff --git a/src/parser/index.ts b/src/parser/index.ts index 7a71b5f4..b6c66497 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -1,6 +1,4 @@ export * as Parser from './parser.js'; -export * from './continuations.js'; -export * from './types/index.js'; export * as Misc from './misc.js'; export * as YTNodes from './nodes.js'; export * as YT from './youtube/index.js'; @@ -8,4 +6,9 @@ export * as YTMusic from './ytmusic/index.js'; export * as YTKids from './ytkids/index.js'; export * as YTShorts from './ytshorts/index.js'; export * as Helpers from './helpers.js'; -export * as Generator from './generator.js'; \ No newline at end of file +export * as Generator from './generator.js'; +export * as APIResponseTypes from './types/index.js'; +export * from './continuations.js'; + +// @TODO: Remove this when files are updated to use APIResponseTypes or /types/index.js directly. +export * from './types/index.js'; \ No newline at end of file diff --git a/src/parser/types/ParsedResponse.ts b/src/parser/types/ParsedResponse.ts index 5d06fc29..7b253643 100644 --- a/src/parser/types/ParsedResponse.ts +++ b/src/parser/types/ParsedResponse.ts @@ -2,9 +2,10 @@ import type { Memo, ObservedArray, SuperParsedResult, YTNode } from '../helpers. import type { ReloadContinuationItemsCommand, Continuation, GridContinuation, ItemSectionContinuation, LiveChatContinuation, MusicPlaylistShelfContinuation, MusicShelfContinuation, - PlaylistPanelContinuation, SectionListContinuation, ContinuationCommand, - CpnSource + PlaylistPanelContinuation, SectionListContinuation, ContinuationCommand } from '../index.js'; + +import type { CpnSource } from './RawResponse.js'; import type PlayerCaptionsTracklist from '../classes/PlayerCaptionsTracklist.js'; import type CardCollection from '../classes/CardCollection.js'; import type Endscreen from '../classes/Endscreen.js'; diff --git a/src/types/Clients.ts b/src/types/Clients.ts deleted file mode 100644 index 4d83ba6b..00000000 --- a/src/types/Clients.ts +++ /dev/null @@ -1,21 +0,0 @@ -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; -}>; - -export type MusicSearchFilters = Partial<{ - type: 'all' | 'song' | 'video' | 'album' | 'playlist' | 'artist'; -}>; \ No newline at end of file diff --git a/src/types/Endpoints.ts b/src/types/Endpoints.ts index 50de68e7..c07407b0 100644 --- a/src/types/Endpoints.ts +++ b/src/types/Endpoints.ts @@ -1,4 +1,4 @@ -import type { InnerTubeClient } from '../Innertube.js'; +import type { InnerTubeClient } from '../types/index.js'; export type SnakeToCamel = S extends `${infer T}_${infer U}` ? `${Lowercase}${Capitalize>}` : S; diff --git a/src/types/FormatUtils.ts b/src/types/FormatUtils.ts index aff2fc42..748bb251 100644 --- a/src/types/FormatUtils.ts +++ b/src/types/FormatUtils.ts @@ -1,4 +1,4 @@ -import type { InnerTubeClient } from '../Innertube.js'; +import type { InnerTubeClient } from '../types/index.js'; import type { Format } from '../parser/misc.js'; export type URLTransformer = (url: URL) => URL; diff --git a/src/types/Misc.ts b/src/types/Misc.ts new file mode 100644 index 00000000..3bf926e7 --- /dev/null +++ b/src/types/Misc.ts @@ -0,0 +1,42 @@ +import type { SessionOptions } from '../core/index.js'; + +export type InnerTubeConfig = SessionOptions; +export type InnerTubeClient = 'IOS' | 'WEB' | 'ANDROID' | 'YTMUSIC' | 'YTMUSIC_ANDROID' | 'YTSTUDIO_ANDROID' | 'TV_EMBEDDED' | 'YTKIDS'; + +export type UploadDate = 'all' | 'hour' | 'today' | 'week' | 'month' | 'year'; +export type SearchType = 'all' | 'video' | 'channel' | 'playlist' | 'movie'; +export type Duration = 'all' | 'short' | 'medium' | 'long'; +export type SortBy = 'relevance' | 'rating' | 'upload_date' | 'view_count'; +export type Feature = 'hd' | 'subtitles' | 'creative_commons' | '3d' | 'live' | 'purchased' | '4k' | '360' | 'location' | 'hdr' | 'vr180'; + +export type SearchFilters = { + upload_date?: UploadDate; + type?: SearchType; + duration?: Duration; + sort_by?: SortBy; + features?: Feature[]; +}; + +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; +}>; + +export type MusicSearchType = 'all' | 'song' | 'video' | 'album' | 'playlist' | 'artist'; + +export type MusicSearchFilters = { + type?: MusicSearchType; +}; \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index 47c9fe86..9147beef 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,6 +2,6 @@ export type { default as PlatformShim } from './PlatformShim.js'; export * from './Cache.js'; export * from './PlatformShim.js'; -export * from './Clients.js'; +export * from './Misc.js'; export * from './Endpoints.js'; export * from './FormatUtils.js'; \ No newline at end of file