@rolme/ytscript
Version:
A CLI tool to download YouTube transcripts and generate summaries
35 lines (34 loc) • 1.31 kB
JavaScript
import { Command } from 'commander';
import { getTranscript } from '../../services/transcript/index.js';
import { TranscriptError } from '../../types/transcript.js';
import ytdl from 'ytdl-core';
export function createSummarizeCommand() {
const summarize = new Command('summarize')
.description('Download and summarize transcript from a YouTube video')
.argument('<url>', 'YouTube video URL')
.option('-l, --language <code>', 'Language code (e.g., en, es, fr)')
.option('-o, --output <path>', 'Output file path')
.action(async (url, options) => {
try {
const info = await ytdl.getInfo(url);
const result = await getTranscript(info, {
lang: options.language
});
console.log('Transcript:', result.transcript);
}
catch (error) {
if (error instanceof TranscriptError) {
console.error(error.message);
process.exit(1);
}
if (error instanceof Error) {
console.error('Failed to download transcript:', error.message);
}
else {
console.error('Failed to download transcript:', error);
}
process.exit(1);
}
});
return summarize;
}