youtube-data-cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerVideoCommands(program) {
5
+ program
6
+ .command("videos <ids>")
7
+ .description("Get video details by IDs (comma-separated)")
8
+ .option("--part <parts>", "Parts to include", "snippet,statistics,contentDetails")
9
+ .action(async (ids, opts) => {
10
+ try {
11
+ const creds = loadCredentials(program.opts().credentials);
12
+ const params = {
13
+ id: ids,
14
+ part: opts.part,
15
+ };
16
+ const data = await callApi("/videos", { creds, params });
17
+ output(data, program.opts().format);
18
+ }
19
+ catch (err) {
20
+ fatal(err.message);
21
+ }
22
+ });
23
+ }
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ import { Command } from "commander";
4
+ const require = createRequire(import.meta.url);
5
+ const { version } = require("../package.json");
6
+ import { registerSearchCommands } from "./commands/search.js";
7
+ import { registerChannelCommands } from "./commands/channels.js";
8
+ import { registerVideoCommands } from "./commands/videos.js";
9
+ import { registerPlaylistCommands } from "./commands/playlists.js";
10
+ import { registerPlaylistItemCommands } from "./commands/playlist-items.js";
11
+ import { registerCommentThreadCommands } from "./commands/comment-threads.js";
12
+ import { registerCommentCommands } from "./commands/comments.js";
13
+ import { registerSubscriptionCommands } from "./commands/subscriptions.js";
14
+ const program = new Command();
15
+ program
16
+ .name("youtube-data-cli")
17
+ .description("YouTube Data API CLI for AI agents")
18
+ .version(version)
19
+ .option("--format <format>", "Output format", "json")
20
+ .option("--credentials <path>", "Path to credentials JSON file")
21
+ .addHelpText("after", "\nDocs: https://github.com/Bin-Huang/youtube-data-cli");
22
+ program.configureOutput({
23
+ writeErr: (str) => {
24
+ const msg = str.replace(/^error: /i, "").trim();
25
+ if (msg)
26
+ process.stderr.write(JSON.stringify({ error: msg }) + "\n");
27
+ },
28
+ writeOut: (str) => {
29
+ process.stdout.write(str);
30
+ },
31
+ });
32
+ program.showHelpAfterError(false);
33
+ program.hook("preAction", () => {
34
+ const format = program.opts().format;
35
+ if (format !== "json" && format !== "compact") {
36
+ process.stderr.write(JSON.stringify({ error: "Format must be 'json' or 'compact'." }) + "\n");
37
+ process.exit(1);
38
+ }
39
+ });
40
+ registerSearchCommands(program);
41
+ registerChannelCommands(program);
42
+ registerVideoCommands(program);
43
+ registerPlaylistCommands(program);
44
+ registerPlaylistItemCommands(program);
45
+ registerCommentThreadCommands(program);
46
+ registerCommentCommands(program);
47
+ registerSubscriptionCommands(program);
48
+ program.on("command:*", (operands) => {
49
+ process.stderr.write(JSON.stringify({ error: `Unknown command: ${operands[0]}. Run --help for available commands.` }) + "\n");
50
+ process.exit(1);
51
+ });
52
+ if (process.argv.length <= 2) {
53
+ program.outputHelp();
54
+ process.exit(0);
55
+ }
56
+ program.parse();
package/dist/utils.js ADDED
@@ -0,0 +1,12 @@
1
+ export function output(data, format) {
2
+ if (format === "compact") {
3
+ process.stdout.write(JSON.stringify(data) + "\n");
4
+ }
5
+ else {
6
+ process.stdout.write(JSON.stringify(data, null, 2) + "\n");
7
+ }
8
+ }
9
+ export function fatal(message) {
10
+ process.stderr.write(JSON.stringify({ error: message }) + "\n");
11
+ process.exit(1);
12
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "youtube-data-cli",
3
+ "version": "0.0.1",
4
+ "description": "YouTube Data API CLI for AI agents",
5
+ "type": "module",
6
+ "bin": {
7
+ "youtube-data-cli": "dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "prepack": "pnpm build"
17
+ },
18
+ "author": "Benn Huang <tohuangbin@gmail.com>",
19
+ "license": "Apache-2.0",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/Bin-Huang/youtube-data-cli.git"
23
+ },
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "keywords": [
28
+ "youtube",
29
+ "youtube-data-api",
30
+ "cli",
31
+ "ai-agent",
32
+ "api",
33
+ "search",
34
+ "playlists",
35
+ "comments",
36
+ "subscriptions"
37
+ ],
38
+ "packageManager": "pnpm@10.32.1",
39
+ "devDependencies": {
40
+ "@types/node": "^25.5.0",
41
+ "typescript": "^5.9.3"
42
+ },
43
+ "dependencies": {
44
+ "commander": "^14.0.3"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/Bin-Huang/youtube-data-cli/issues"
48
+ },
49
+ "homepage": "https://github.com/Bin-Huang/youtube-data-cli#readme"
50
+ }