Skip to content

Commit

Permalink
add try catch around youtube parsing (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
glowingjade authored Oct 31, 2024
1 parent f76ca72 commit 6ea0b58
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/utils/promptGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,17 @@ When writing out new markdown blocks, remember not to include "line_number|" at
*/
private async getWebsiteContent(url: string): Promise<string> {
if (isYoutubeUrl(url)) {
// TODO: pass language based on user preferences
const { title, transcript } =
await YoutubeTranscript.fetchTranscriptAndMetadata(url)

return `Title: ${title}
Transcript:
${transcript.map((t) => `${t.offset}: ${t.text}`).join('\n')}
`
try {
// TODO: pass language based on user preferences
const { title, transcript } =
await YoutubeTranscript.fetchTranscriptAndMetadata(url)

return `Title: ${title}
Video Transcript:
${transcript.map((t) => `${t.offset}: ${t.text}`).join('\n')}`
} catch (error) {
console.error('Error fetching YouTube transcript', error)
}
}

const response = await requestUrl({ url })
Expand Down

0 comments on commit 6ea0b58

Please sign in to comment.