mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
remove all the commas in the raw transcript which are added by youtubei
This commit is contained in:
parent
faa3e1d00e
commit
b5fe0cb279
1 changed files with 17 additions and 1 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue