feat: add YouTube segments CLI using yt-dlp

This commit is contained in:
Kilo Code Cloud
2026-01-14 18:46:21 +00:00
parent dbb067fbab
commit a657434723
6 changed files with 393 additions and 6 deletions

58
src/cli/args.ts Normal file
View File

@@ -0,0 +1,58 @@
export interface CliArgs {
url?: string;
output: string;
format: string;
noChapters: boolean;
}
export function parseArgs(): CliArgs {
const args: CliArgs = {
output: "./downloads",
format: "best",
noChapters: false,
};
const rawArgs = Bun.argv;
for (let i = 0; i < rawArgs.length; i++) {
const arg = rawArgs[i];
const nextArg = rawArgs[i + 1];
if (arg === "-o" || arg === "--output") {
args.output = nextArg || "./downloads";
i++;
} else if (arg === "-f" || arg === "--format") {
args.format = nextArg || "best";
i++;
} else if (arg === "--no-chapters") {
args.noChapters = true;
} else if (arg === "-h" || arg === "--help") {
console.log(`YouTube Video Segments Downloader
Usage: yt-segments <url> [options]
Arguments:
<url> YouTube video URL (required)
Options:
-o, --output <dir> Output directory (default: ./downloads)
-f, --format <fmt> Video format (default: best)
--no-chapters Skip chapter extraction
-h, --help Show this help message
Examples:
yt-segments "https://www.youtube.com/watch?v=abc123"
yt-segments "https://youtu.be/abc123" -o ./videos -f mp4
yt-segments "https://www.youtube.com/watch?v=abc123" --no-chapters
`);
process.exit(0);
} else if (!arg.startsWith("-") && !arg.includes("bun")) {
// This is likely the URL
if (!arg.startsWith("bun") && !arg.includes("node")) {
args.url = arg;
}
}
}
return args;
}