From eac26c12af1e14e178f4e5b7f291141978f52d6a Mon Sep 17 00:00:00 2001 From: Eric-Vondee Date: Wed, 31 Jul 2024 15:39:01 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20set=20stream=20thumbnail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/services/stage.service.ts | 1 + packages/server/src/utils/youtube.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/server/src/services/stage.service.ts b/packages/server/src/services/stage.service.ts index 92a5b2f69..3a88351fa 100644 --- a/packages/server/src/services/stage.service.ts +++ b/packages/server/src/services/stage.service.ts @@ -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, diff --git a/packages/server/src/utils/youtube.ts b/packages/server/src/utils/youtube.ts index 479c619bf..74f94f108 100644 --- a/packages/server/src/utils/youtube.ts +++ b/packages/server/src/utils/youtube.ts @@ -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( @@ -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,