Get transcript summaries of Web videos.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.test.ts 1.5 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { writeFileSync } from 'fs';
  2. import { beforeAll, describe, it } from 'vitest';
  3. import { config } from 'dotenv';
  4. import { createSummarizer, VideoType } from '../src';
  5. const writeTranscript = (filename: string, content: string) => {
  6. const transcripts = JSON.parse(content) as {
  7. transcripts: { text: string }[],
  8. summary: string,
  9. };
  10. const transcriptText = transcripts.transcripts.map((t) => t.text).join('\n');
  11. writeFileSync(filename, transcriptText);
  12. };
  13. describe('blah', () => {
  14. beforeAll(() => {
  15. config();
  16. });
  17. it('works', () => new Promise<void>((done) => {
  18. const summarizer = createSummarizer({
  19. type: VideoType.YOUTUBE,
  20. openAiParams: {
  21. apiKey: process.env.OPENAI_API_KEY as string,
  22. },
  23. });
  24. summarizer.on('process', (data) => {
  25. if (data.phase === 'success') {
  26. switch (data.processType) {
  27. case 'fetch-transcript':
  28. writeTranscript('transcript.txt', data.content as string);
  29. break;
  30. case 'normalize-transcript':
  31. writeFileSync('normalized.txt', data.content as string);
  32. break;
  33. case 'summarize-transcript':
  34. writeFileSync('summary.txt', data.content as string);
  35. break;
  36. default:
  37. break;
  38. }
  39. }
  40. });
  41. summarizer.on('error', (err) => {
  42. console.log(err);
  43. done();
  44. });
  45. summarizer.on('end', () => {
  46. done();
  47. });
  48. summarizer.summarize({
  49. url: 'https://www.youtube.com/watch?v=WeNgDxtBiyw',
  50. });
  51. }), { timeout: 180000 });
  52. });