Skip to content

Commit

Permalink
✨ set stream thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Vondee committed Jul 31, 2024
1 parent 6fb9d92 commit eac26c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/server/src/services/stage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default class StageService {
accessToken: accessToken,
title: stage.name,
streamDate: stage.streamDate.toString(),
thumbnail: stage.thumbnail,
});
await createMultiStream({
name: stage.name,
Expand Down
14 changes: 14 additions & 0 deletions packages/server/src/utils/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const createYoutubeLiveStream = async (data: {
accessToken: string;
title: string;
streamDate: string;
thumbnail: string;
}): Promise<{ streamKey: string; ingestUrl: string; broadcastId: string }> => {
const youtube = await getYoutubeClient(data.accessToken);
const broadcastId = await createLiveBroadcast(
Expand All @@ -78,6 +79,19 @@ export const createYoutubeLiveStream = async (data: {
);
const stream = await createLiveStream(youtube, data.title);
await bindBroadCastToStream(youtube, broadcastId, stream.id);
if (data.thumbnail) {
const response = await fetch(data.thumbnail, {
method: 'get',
});
const thumbnailData = await response.arrayBuffer();
const thumbnailBuffer = Buffer.from(thumbnailData);
await youtube.thumbnails.set({
videoId: broadcastId,
media: {
body: thumbnailBuffer,
},
});
}
return {
streamKey: stream.streamKey,
ingestUrl: stream.ingestUrl,
Expand Down

0 comments on commit eac26c1

Please sign in to comment.