Youtube loader whitespace fix (#2051)

youtube loader whitespace fix
This commit is contained in:
Sean Hatfield 2024-08-06 10:16:17 -07:00 committed by GitHub
parent f787502755
commit be3b0b4916
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -47,10 +47,12 @@ class YoutubeTranscript {
let transcript = ""; let transcript = "";
const chunks = transcriptXML.getElementsByTagName("text"); const chunks = transcriptXML.getElementsByTagName("text");
for (const chunk of chunks) { for (const chunk of chunks) {
transcript += chunk.textContent; // Add space after each text chunk
transcript += chunk.textContent + " ";
} }
return transcript; // Trim extra whitespace
return transcript.trim().replace(/\s+/g, " ");
} catch (e) { } catch (e) {
throw new YoutubeTranscriptError(e); throw new YoutubeTranscriptError(e);
} }