UNPKG

summarizely-cli

Version:

YouTube summarizer that respects your existing subscriptions. No API keys required.

110 lines 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseArgs = parseArgs; exports.validateArgs = validateArgs; exports.isYouTubeUrl = isYouTubeUrl; function parseArgs(argv) { const args = {}; const rest = []; for (let i = 0; i < argv.length; i++) { const a = argv[i]; if (a === "--help" || a === "-h") { args.help = true; } else if (a === "--version" || a === "-v") { args.version = true; } else if (a === "--captions-only") { args.captionsOnly = true; } else if (a === "--json") { args.json = true; } else if (a === "--stream") { args.stream = true; } else if (a === "--batch") { args.batch = true; } else if (a === "--playlist") { args.playlist = true; } else if (a === "--channel") { args.channel = true; } else if (a === "--channel-limit") { if (i + 1 >= argv.length || String(argv[i + 1]).startsWith('-')) { throw new Error("--channel-limit requires a value"); } const v = argv[++i]; const n = Number(v); if (!Number.isFinite(n) || n <= 0) { throw new Error("--channel-limit requires a positive number"); } args.channelLimit = n; } else if (a === "--model") { if (i + 1 >= argv.length || String(argv[i + 1]).startsWith('-')) { throw new Error("--model requires a value"); } args.model = argv[++i]; } else if (a === "--provider") { if (i + 1 >= argv.length || String(argv[i + 1]).startsWith('-')) { throw new Error("--provider requires a value"); } args.provider = argv[++i]; } else if (a === "--output-dir") { if (i + 1 >= argv.length || String(argv[i + 1]).startsWith('-')) { throw new Error("--output-dir requires a value"); } args.outputDir = argv[++i]; } else if (a === "--no-save-transcript") { args.noSaveTranscript = true; } else if (a === "--max-chars") { if (i + 1 >= argv.length || String(argv[i + 1]).startsWith('-')) { throw new Error("--max-chars requires a value"); } const v = argv[++i]; const n = Number(v); if (!Number.isFinite(n) || n <= 0) { throw new Error("--max-chars requires a positive number"); } args.maxChars = n; } else if (a === "--no-cap") { args.noCap = true; } else { rest.push(a); } } if (rest.length > 0) { args.urls = rest; } return args; } function validateArgs(args) { const validProviders = ['claude-cli', 'codex-cli', 'ollama']; if (args.provider && !validProviders.includes(args.provider)) { throw new Error(`Unknown provider: ${args.provider}. Valid options: ${validProviders.join(', ')}`); } if (!args.help && !args.version && (!args.urls || args.urls.length === 0)) { throw new Error("Please provide at least one YouTube URL"); } } function isYouTubeUrl(u) { if (!u) return false; try { const url = new URL(u); return /(^|\.)youtube\.com$/.test(url.hostname) || url.hostname === "youtu.be"; } catch { return false; } } //# sourceMappingURL=parser.js.map