|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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<void>((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 });
- });
|