mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 18:06:15 +00:00
154 lines
3.5 KiB
TypeScript
154 lines
3.5 KiB
TypeScript
interface AuthInfo {
|
|
access_token: string
|
|
refresh_token: string
|
|
expires: Date
|
|
}
|
|
|
|
interface AccountInfo {
|
|
name: string
|
|
photo: Record<string, any>[]
|
|
country: string
|
|
language: string
|
|
}
|
|
|
|
// { query: string; corrected_query: string; estimated_results: number; videos: [] }
|
|
interface SearchOptions {
|
|
client: 'YTMUSIC' | 'YOUTUBE'
|
|
period: 'any' | 'hour' | 'day' | 'week' | 'month' | 'year'
|
|
order: 'relevance' | 'rating' | 'age' | 'views'
|
|
duration: 'any' | 'short' | 'long'
|
|
}
|
|
|
|
interface SearchOther {
|
|
query: string
|
|
corrected_query: string
|
|
estimated_results: number
|
|
videos: any[]
|
|
}
|
|
|
|
interface Results {
|
|
songs: any[]
|
|
videos: any[]
|
|
albums: any[]
|
|
playlists: any[]
|
|
}
|
|
|
|
type SearchResults = Results | SearchOther
|
|
|
|
type ClientOption = Pick<SearchOptions, 'client'>
|
|
interface Suggestion {
|
|
text: string
|
|
bold_text: string
|
|
}
|
|
|
|
interface ApiStatus {
|
|
success: boolean
|
|
status_code: number
|
|
data: any
|
|
message?: string
|
|
}
|
|
|
|
interface Comments {
|
|
comments: []
|
|
comment_count?: string;
|
|
}
|
|
|
|
interface Video {
|
|
title: string
|
|
description: string
|
|
thumbnail: []
|
|
metadata: Record<any, any>
|
|
like: () => Promise<ApiStatus>
|
|
dislike: () => Promise<ApiStatus>
|
|
removeLike: () => Promise<ApiStatus>
|
|
subscribe: () => Promise<ApiStatus>
|
|
unsubscribe: () => Promise<ApiStatus>
|
|
comment: (test: string) => Promise<ApiStatus>
|
|
getComments: () => Promise<Comments>
|
|
getLivechat: () => any // TODO type LiveChat
|
|
changeNotificationPreferences: () => Promise<ApiStatus>
|
|
}
|
|
|
|
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 CommentData {
|
|
token: string
|
|
channel_id: string
|
|
}
|
|
|
|
interface History {
|
|
items: [{ date: string; videos: any[] }]
|
|
}
|
|
|
|
interface HomeFeed {
|
|
videos: {
|
|
id: string
|
|
title: string
|
|
description: string
|
|
channel: string
|
|
metadata: Record<string, any>
|
|
}[]
|
|
}
|
|
|
|
interface SubscriptionFeed { items: { date: string; videos: any[] } }
|
|
|
|
interface Notifications {
|
|
items: {
|
|
title: string
|
|
sent_time: string
|
|
channel_name: string
|
|
channel_thumbnail: Record<string, any>
|
|
video_thumbnail: Record<string, any>
|
|
video_url: string
|
|
read: boolean
|
|
notification_id: string
|
|
}[]
|
|
}
|
|
|
|
interface StreamingData {
|
|
selected_format: Record<string, any>
|
|
formats: any[]
|
|
}
|
|
interface StreamingOptions {
|
|
quality?: string
|
|
type?: string
|
|
format?: string
|
|
}
|
|
|
|
export default class Innertube {
|
|
constructor(cookie?: string)
|
|
|
|
public signIn(auth_info: AuthInfo): Promise<void>
|
|
public getAccountInfo(): Promise<AccountInfo>
|
|
public search(query: string, options: SearchOptions): Promise<SearchResults>
|
|
public getSearchSuggestions(options: ClientOption): Promise<Suggestion>
|
|
public getDetails(video_id: string): Promise<ApiStatus>
|
|
public getChannel(id: string): Promise<Channel>
|
|
public getLyrics(video_id: string): Promise<string>
|
|
public getPlaylist(playlist_id: string, options?: ClientOption): Promise<PlayList>
|
|
public getComments(video_id: string, options?: CommentData): Promise<Comments[]>
|
|
public getHistory(): Promise<History>
|
|
public getHomeFeed(): Promise<HomeFeed>
|
|
public getSubscriptionsFeed(): Promise<SubscriptionFeed>
|
|
public getNotifications(): Promise<Notifications>
|
|
public getUnseenNotificationsCount(): Promise<number>
|
|
public getStreamingData(id: string, options?: StreamingOptions): Promise<StreamingData>
|
|
public download(id: string, options?: StreamingOptions): ReadableStream
|
|
}
|