import { writeFileSync } from 'fs'; import { beforeAll, describe, it } from 'vitest'; import { config } from 'dotenv'; import { createSummarizer, VideoType } from '../src'; const writeTranscript = (filename: string, content: string) => { const transcripts = JSON.parse(content) as { transcripts: { text: string }[], summary: string, }; const transcriptText = transcripts.transcripts.map((t) => t.text).join('\n'); writeFileSync(filename, transcriptText); }; describe('blah', () => { beforeAll(() => { config(); }); it('works', () => new Promise((done) => { const summarizer = createSummarizer({ type: VideoType.YOUTUBE, openAiParams: { apiKey: process.env.OPENAI_API_KEY as string, }, }); summarizer.on('process', (data) => { if (data.phase === 'success') { switch (data.processType) { case 'fetch-transcript': writeTranscript('transcript.txt', data.content as string); break; case 'normalize-transcript': writeFileSync('normalized.txt', data.content as string); break; case 'summarize-transcript': writeFileSync('summary.txt', data.content as string); break; default: break; } } }); summarizer.on('error', (err) => { console.log(err); done(); }); summarizer.on('end', () => { done(); }); summarizer.summarize({ url: 'https://www.youtube.com/watch?v=WeNgDxtBiyw', }); }), { timeout: 180000 }); });