From 4a97c7d2addc3f0dceef31a54f3bff7297e97e96 Mon Sep 17 00:00:00 2001 From: Ryan Li Date: Sun, 29 Sep 2024 20:53:34 -0400 Subject: [PATCH] new channel function --- functions/src/index.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/functions/src/index.ts b/functions/src/index.ts index 8a9f528..8c4d787 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -27,3 +27,24 @@ export const getVideosFromPlaylist = onCall(async (request) => { logger.debug(videos.data.items); return { videos: videos.data.items }; }); + +export const getVideosFromChannel = onCall(async (request) => { + const channelId = request.data.id; + const channelVideos = await youtubeClient.search.list({ + channelId: channelId, + part: ["contentDetails", "snippet"], + maxResults: 50, + }); + + const videoIds = channelVideos?.data?.items + ?.map((videoItem) => videoItem.id?.videoId ?? "") + .filter((id) => id !== ""); + + const videos = await youtubeClient.videos.list({ + part: ["statistics", "snippet", "contentDetails"], + id: videoIds, + }); + + logger.debug(videos.data.items); + return { videos: videos.data.items }; +});