diff --git a/packages/api/src/jobs/process-youtube-video.ts b/packages/api/src/jobs/process-youtube-video.ts index 339657203..97d4fb0d5 100644 --- a/packages/api/src/jobs/process-youtube-video.ts +++ b/packages/api/src/jobs/process-youtube-video.ts @@ -315,6 +315,20 @@ export interface ProcessYouTubeTranscriptJobData { libraryItemId: string } +const sanitizeTranscript = ( + transcript: TranscriptProperties[] +): TranscriptProperties[] => { + return transcript.map((item) => { + return { + // Youtubei library uses comma and space to separate words in the transcript + // We need to remove the comma to avoid breaking the transcript + text: item.text.replace(/,/g, ''), + start: item.start, + duration: item.duration, + } + }) +} + export const processYouTubeTranscript = async ( jobData: ProcessYouTubeTranscriptJobData ) => { @@ -350,10 +364,12 @@ export const processYouTubeTranscript = async ( let transcript: TranscriptProperties[] | undefined = undefined if ('getTranscript' in video) { - transcript = await video.getTranscript() + transcript = await video.captions?.get() } if (transcript) { + transcript = sanitizeTranscript(transcript) + if (chapters) { transcript = addTranscriptChapters(chapters, transcript) }