feat: extract most watched segments from YouTube API

This commit is contained in:
Kilo Code Cloud
2026-01-14 19:39:34 +00:00
parent a657434723
commit 1366a4f9ba
3 changed files with 100 additions and 67 deletions

View File

@@ -2,14 +2,14 @@ export interface CliArgs {
url?: string;
output: string;
format: string;
noChapters: boolean;
segments: number;
}
export function parseArgs(): CliArgs {
const args: CliArgs = {
output: "./downloads",
format: "best",
noChapters: false,
segments: 1,
};
const rawArgs = Bun.argv;
@@ -24,10 +24,11 @@ export function parseArgs(): CliArgs {
} else if (arg === "-f" || arg === "--format") {
args.format = nextArg || "best";
i++;
} else if (arg === "--no-chapters") {
args.noChapters = true;
} else if (arg === "-n" || arg === "--segments") {
args.segments = parseInt(nextArg || "1", 10);
i++;
} else if (arg === "-h" || arg === "--help") {
console.log(`YouTube Video Segments Downloader
console.log(`YouTube Most Watched Segments Downloader
Usage: yt-segments <url> [options]
@@ -37,13 +38,13 @@ Arguments:
Options:
-o, --output <dir> Output directory (default: ./downloads)
-f, --format <fmt> Video format (default: best)
--no-chapters Skip chapter extraction
-n, --segments <num> Number of top segments to download (default: 1)
-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
yt-segments "https://www.youtube.com/watch?v=abc123" -n 3
`);
process.exit(0);
} else if (!arg.startsWith("-") && !arg.includes("bun")) {