41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
#!/usr/bin/env bun
|
|
|
|
import { downloadVideoSegments } from "./downloader.js";
|
|
import { parseArgs } from "./args.js";
|
|
|
|
async function main() {
|
|
const args = parseArgs();
|
|
|
|
if (!args.url) {
|
|
console.error("Error: YouTube URL is required");
|
|
console.log("Usage: yt-segments <url> [options]");
|
|
console.log("Options:");
|
|
console.log(" -o, --output <dir> Output directory (default: ./downloads)");
|
|
console.log(" -f, --format <fmt> Video format (default: best)");
|
|
console.log(" --no-chapters Skip chapter extraction");
|
|
console.log(" -h, --help Show help");
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`Downloading segments from: ${args.url}`);
|
|
console.log(`Output directory: ${args.output}`);
|
|
console.log(`Format: ${args.format}`);
|
|
console.log(`Extract chapters: ${!args.noChapters}`);
|
|
console.log("");
|
|
|
|
try {
|
|
await downloadVideoSegments({
|
|
url: args.url,
|
|
outputDir: args.output,
|
|
format: args.format,
|
|
extractChapters: !args.noChapters,
|
|
});
|
|
console.log("\nDownload complete!");
|
|
} catch (error) {
|
|
console.error("Error:", error instanceof Error ? error.message : error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|