← Public packages
@kody/google
Call Gmail, Calendar, Tasks, Drive, Docs, Sheets, People, YouTube, and Analytics through saved Google OAuth.
src/youtube.ts
23 lines · 3.1 KB · TypeScriptimport { requestGoogle } from './core.ts'
import type { GoogleAuthParams } from './accounts.ts'
import type { JsonObject } from './types.ts'
export type YouTubeChannelsParams = GoogleAuthParams & { part?: string; mine?: boolean; id?: string; forUsername?: string; maxResults?: number; pageToken?: string; fields?: string }
export type YouTubeSearchParams = GoogleAuthParams & { query?: string; q?: string; part?: string; type?: string; channelId?: string; maxResults?: number; pageToken?: string; order?: string; publishedAfter?: string; publishedBefore?: string; fields?: string }
export type YouTubeVideosParams = GoogleAuthParams & { id?: string; chart?: string; part?: string; maxResults?: number; pageToken?: string; fields?: string }
export type YouTubeCommentThreadsParams = GoogleAuthParams & { videoId?: string; channelId?: string; allThreadsRelatedToChannelId?: string; part?: string; maxResults?: number; pageToken?: string; order?: string; fields?: string }
/**
* Return the YouTube Data API helper namespace for channels, search, videos, and comments.
* @returns Helper namespace or overview for this Google product.
* @example
* import youtube from 'kody:@kody/google/youtube'
* const channels = await youtube().listChannels({ integration: 'google-youtube' })
* // => { items: [{ id: 'UC...', snippet: { title: '...' } }] }
*/
export default function youtube() { return { listChannels, search, listVideos, listCommentThreads } }
export async function listChannels(params: YouTubeChannelsParams): Promise<JsonObject> { const { part = 'snippet,contentDetails,statistics', mine = true, id, forUsername, maxResults = 5, pageToken, fields } = params; return await requestGoogle({ ...params, api: 'google', path: '/youtube/v3/channels', query: { part, mine: id || forUsername ? undefined : mine, id, forUsername, maxResults, pageToken, fields } }) as JsonObject }
export async function search(params: YouTubeSearchParams): Promise<JsonObject> { const { query, q = query, part = 'snippet', type, channelId, maxResults = 10, pageToken, order, publishedAfter, publishedBefore, fields } = params; return await requestGoogle({ ...params, api: 'google', path: '/youtube/v3/search', query: { q, part, type, channelId, maxResults, pageToken, order, publishedAfter, publishedBefore, fields } }) as JsonObject }
export async function listVideos(params: YouTubeVideosParams): Promise<JsonObject> { const { id, chart, part = 'snippet,contentDetails,statistics,status', maxResults = 10, pageToken, fields } = params; return await requestGoogle({ ...params, api: 'google', path: '/youtube/v3/videos', query: { id, chart, part, maxResults, pageToken, fields } }) as JsonObject }
export async function listCommentThreads(params: YouTubeCommentThreadsParams): Promise<JsonObject> { const { videoId, channelId, allThreadsRelatedToChannelId, part = 'snippet,replies', maxResults = 10, pageToken, order = 'time', fields } = params; return await requestGoogle({ ...params, api: 'google', path: '/youtube/v3/commentThreads', query: { videoId, channelId, allThreadsRelatedToChannelId, part, maxResults, pageToken, order, fields } }) as JsonObject }