Get transcript summaries of Web videos.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.test.ts 1.5 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. url: 'https://www.youtube.com/watch?v=WeNgDxtBiyw',
  21. openaiApiKey: process.env.OPENAI_API_KEY as string,
  22. });
  23. summarizer.on('process', (data) => {
  24. if (data.phase === 'success') {
  25. switch (data.processType) {
  26. case 'fetch-transcript':
  27. writeTranscript('transcript.txt', data.content as string);
  28. break;
  29. case 'normalize-transcript':
  30. writeFileSync('normalized.txt', data.content as string);
  31. break;
  32. case 'summarize-transcript':
  33. writeFileSync('summary.txt', data.content as string);
  34. break;
  35. default:
  36. break;
  37. }
  38. }
  39. });
  40. summarizer.on('error', (err) => {
  41. console.log(err);
  42. done();
  43. });
  44. summarizer.on('end', () => {
  45. done();
  46. });
  47. summarizer.process();
  48. }), { timeout: 180000 });
  49. });