Skip to content

Commit

Permalink
YT-42: Fetch videos by channel (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanL123 authored Sep 30, 2024
1 parent 31237a5 commit f537764
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
});

0 comments on commit f537764

Please sign in to comment.