summarizely-cli
Version:
YouTube summarizer that respects your existing subscriptions. No API keys required.
154 lines • 5.87 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeBatch = executeBatch;
exports.executeSingleVideo = executeSingleVideo;
exports.executePlaylist = executePlaylist;
exports.executeChannel = executeChannel;
const formatter_1 = require("./formatter");
const batch_1 = require("../batch");
const process_video_1 = require("../process-video");
const providers_1 = require("../providers");
const utils_1 = require("../utils");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
async function executeBatch(videos, args) {
const outputDir = args.outputDir || 'summaries';
const startTime = new Date();
const results = [];
const choice = args.provider
? { provider: args.provider, reason: 'User specified' }
: (0, providers_1.selectProvider)(process.env);
if (!choice.provider) {
process.stderr.write('No provider available. Install a CLI provider (claude, codex) or Ollama.\n');
process.stderr.write(`Reason: ${choice.reason}\n`);
process.exitCode = 5;
return;
}
for (let i = 0; i < videos.length; i++) {
const video = videos[i];
process.stderr.write(`\n${(0, formatter_1.formatProgress)(i + 1, videos.length, video.title || video.url)}\n`);
const result = await (0, process_video_1.processVideo)({
url: video.url,
provider: choice.provider,
model: args.model,
outputDir,
noSaveTranscript: args.noSaveTranscript,
maxChars: args.maxChars,
noCap: args.noCap,
stream: args.stream && !args.json,
silent: false
});
results.push({
url: result.url,
videoId: result.videoId,
title: result.title,
success: result.success,
path: result.path,
error: result.error,
duration: result.duration
});
if (result.success) {
process.stderr.write(`✓ Summary saved to: ${result.path}\n`);
}
else {
process.stderr.write(`✗ Failed: ${result.error}\n`);
}
}
const endTime = new Date();
const stats = {
totalVideos: videos.length,
successful: results.filter(r => r.success).length,
failed: results.filter(r => !r.success).length,
totalDuration: endTime.getTime() - startTime.getTime(),
startTime,
endTime
};
const indexPath = (0, batch_1.createBatchIndex)(outputDir, results, stats);
const statsPath = (0, batch_1.createBatchStats)(outputDir, results, stats);
process.stderr.write((0, formatter_1.formatBatchSummary)(stats));
process.stderr.write(`\n\nBatch index: ${indexPath}\n`);
process.stderr.write(`Statistics: ${statsPath}\n`);
if (args.json) {
process.stdout.write((0, formatter_1.formatBatchJson)(stats, results) + '\n');
}
if (stats.failed > 0 && stats.successful === 0) {
process.exitCode = 5;
}
else if (stats.failed > 0) {
process.exitCode = 3;
}
}
async function executeSingleVideo(url, args) {
const result = await (0, process_video_1.processVideo)({
url,
provider: args.provider,
model: args.model,
outputDir: args.outputDir,
noSaveTranscript: args.noSaveTranscript,
maxChars: args.maxChars,
noCap: args.noCap,
stream: args.stream && !args.json,
silent: false
});
if (result.success) {
const outputDir = args.outputDir || 'summaries';
const videoDir = path_1.default.dirname(result.path);
const files = fs_1.default.readdirSync(videoDir);
const filesToCopy = files.map(f => ({
source: path_1.default.join(videoDir, f),
name: f
}));
(0, utils_1.writeToLatestDir)(outputDir, filesToCopy);
if (args.json) {
const provider = args.provider || (0, providers_1.selectProvider)().provider;
process.stdout.write((0, formatter_1.formatSingleVideoJson)(result, provider) + '\n');
}
else if (!args.stream) {
const markdown = fs_1.default.readFileSync(result.path, 'utf8');
process.stdout.write(markdown);
}
}
else {
process.stderr.write(`Error: ${result.error}\n`);
process.exitCode = 5;
}
}
async function executePlaylist(url, args) {
process.stderr.write('> Extracting playlist videos...\n');
try {
const videos = (0, batch_1.extractPlaylistVideos)(url);
process.stderr.write(`> Found ${videos.length} videos in playlist\n`);
if (videos.length === 0) {
process.stderr.write('No videos found in playlist.\n');
process.exitCode = 4;
return;
}
await executeBatch(videos, args);
}
catch (e) {
process.stderr.write(`Failed to extract playlist: ${e.message}\n`);
process.exitCode = 4;
}
}
async function executeChannel(url, args) {
process.stderr.write('> Extracting channel videos...\n');
try {
const limit = args.channelLimit || 10;
const videos = (0, batch_1.extractChannelVideos)(url, limit);
process.stderr.write(`> Found ${videos.length} recent videos from channel\n`);
if (videos.length === 0) {
process.stderr.write('No videos found in channel.\n');
process.exitCode = 4;
return;
}
await executeBatch(videos, args);
}
catch (e) {
process.stderr.write(`Failed to extract channel videos: ${e.message}\n`);
process.exitCode = 4;
}
}
//# sourceMappingURL=executor.js.map