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.
- package/LICENSE +201 -0
- package/README.md +424 -0
- package/dist/api.js +39 -0
- package/dist/auth.js +72 -0
- package/dist/commands/channels.js +29 -0
- package/dist/commands/comment-threads.js +73 -0
- package/dist/commands/comments.js +97 -0
- package/dist/commands/playlist-items.js +113 -0
- package/dist/commands/playlists.js +126 -0
- package/dist/commands/search.js +68 -0
- package/dist/commands/subscriptions.js +90 -0
- package/dist/commands/videos.js +23 -0
- package/dist/index.js +56 -0
- package/dist/utils.js +12 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. Please also get an in-place
|
|
186
|
+
temporary or permanent copyright header for your project as
|
|
187
|
+
described on https://www.apache.org/legal/src-headers.html
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Benn Huang
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
# youtube-data-cli
|
|
2
|
+
|
|
3
|
+
YouTube Data API CLI for AI agents (and humans). Search videos, manage playlists, read and post comments, handle subscriptions, and more.
|
|
4
|
+
|
|
5
|
+
**Works with:** OpenClaw, Claude Code, Cursor, Codex, and any agent that can run shell commands.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Tell your AI agent (e.g. OpenClaw):
|
|
10
|
+
|
|
11
|
+
> Install this CLI and skills from https://github.com/Bin-Huang/youtube-data-cli
|
|
12
|
+
|
|
13
|
+
Or install manually:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g youtube-data-cli
|
|
17
|
+
|
|
18
|
+
# Add skills for AI agents (Claude Code, Cursor, Codex, etc.)
|
|
19
|
+
npx skills add Bin-Huang/youtube-data-cli
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or run directly: `npx youtube-data-cli --help`
|
|
23
|
+
|
|
24
|
+
## How it works
|
|
25
|
+
|
|
26
|
+
Built on the official [YouTube Data API v3](https://developers.google.com/youtube/v3). Uses native `fetch` with no external dependencies beyond `commander`. Every command outputs structured JSON to stdout, ready for agents to parse without extra processing.
|
|
27
|
+
|
|
28
|
+
Core endpoints covered:
|
|
29
|
+
|
|
30
|
+
- **[Search](https://developers.google.com/youtube/v3/docs/search/list)** -- search for videos, channels, and playlists
|
|
31
|
+
- **[Channels](https://developers.google.com/youtube/v3/docs/channels/list)** -- get channel details and statistics
|
|
32
|
+
- **[Videos](https://developers.google.com/youtube/v3/docs/videos/list)** -- get video details and statistics
|
|
33
|
+
- **[Playlists](https://developers.google.com/youtube/v3/docs/playlists)** -- list, create, update, and delete playlists
|
|
34
|
+
- **[PlaylistItems](https://developers.google.com/youtube/v3/docs/playlistItems)** -- manage videos in playlists
|
|
35
|
+
- **[CommentThreads](https://developers.google.com/youtube/v3/docs/commentThreads)** -- list and post top-level comments
|
|
36
|
+
- **[Comments](https://developers.google.com/youtube/v3/docs/comments)** -- list, reply, update, and delete comments
|
|
37
|
+
- **[Subscriptions](https://developers.google.com/youtube/v3/docs/subscriptions)** -- list, subscribe, and unsubscribe
|
|
38
|
+
|
|
39
|
+
## Setup
|
|
40
|
+
|
|
41
|
+
### Authentication
|
|
42
|
+
|
|
43
|
+
This CLI supports two authentication methods:
|
|
44
|
+
|
|
45
|
+
| Method | Use case | Commands |
|
|
46
|
+
|--------|----------|----------|
|
|
47
|
+
| **API key** | Public data (search, channels, videos, playlists, comments) | Read-only commands |
|
|
48
|
+
| **OAuth 2.0** | Private data + write operations | All commands (required for `*-insert`, `*-update`, `*-delete`, `mine` queries) |
|
|
49
|
+
|
|
50
|
+
### Option 1: API key only (public data)
|
|
51
|
+
|
|
52
|
+
For read-only access to public data:
|
|
53
|
+
|
|
54
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com/).
|
|
55
|
+
2. Create a project and enable the **YouTube Data API v3**.
|
|
56
|
+
3. Create an API key under "Credentials".
|
|
57
|
+
|
|
58
|
+
### Option 2: OAuth 2.0 (full access)
|
|
59
|
+
|
|
60
|
+
For write operations and private data:
|
|
61
|
+
|
|
62
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com/).
|
|
63
|
+
2. Create a project and enable the **YouTube Data API v3**.
|
|
64
|
+
3. Create an **OAuth 2.0 Client ID** (Desktop app type) under "Credentials".
|
|
65
|
+
4. Use the [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/) or your own flow to obtain a refresh token with the required scopes:
|
|
66
|
+
- `https://www.googleapis.com/auth/youtube` (full access)
|
|
67
|
+
- or `https://www.googleapis.com/auth/youtube.readonly` (read-only)
|
|
68
|
+
- or `https://www.googleapis.com/auth/youtube.force-ssl` (for comments)
|
|
69
|
+
|
|
70
|
+
> **Note:** Service accounts do NOT work with YouTube APIs. You must use OAuth 2.0 with a refresh token.
|
|
71
|
+
|
|
72
|
+
### Place credentials
|
|
73
|
+
|
|
74
|
+
Choose one of these options:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Option A: Default path (recommended)
|
|
78
|
+
mkdir -p ~/.config/youtube-data-cli
|
|
79
|
+
cat > ~/.config/youtube-data-cli/credentials.json << EOF
|
|
80
|
+
{
|
|
81
|
+
"api_key": "YOUR_API_KEY",
|
|
82
|
+
"client_id": "YOUR_CLIENT_ID",
|
|
83
|
+
"client_secret": "YOUR_CLIENT_SECRET",
|
|
84
|
+
"refresh_token": "YOUR_REFRESH_TOKEN"
|
|
85
|
+
}
|
|
86
|
+
EOF
|
|
87
|
+
|
|
88
|
+
# Option B: Environment variables
|
|
89
|
+
export YOUTUBE_API_KEY=your_api_key
|
|
90
|
+
export YOUTUBE_CLIENT_ID=your_client_id
|
|
91
|
+
export YOUTUBE_CLIENT_SECRET=your_client_secret
|
|
92
|
+
export YOUTUBE_REFRESH_TOKEN=your_refresh_token
|
|
93
|
+
|
|
94
|
+
# Option C: Pass per command
|
|
95
|
+
youtube-data-cli --credentials /path/to/credentials.json search --q "test"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Credentials are resolved in this order:
|
|
99
|
+
1. `--credentials <path>` flag
|
|
100
|
+
2. `YOUTUBE_API_KEY`, `YOUTUBE_CLIENT_ID`, `YOUTUBE_CLIENT_SECRET`, `YOUTUBE_REFRESH_TOKEN` env vars
|
|
101
|
+
3. `~/.config/youtube-data-cli/credentials.json` (auto-detected)
|
|
102
|
+
|
|
103
|
+
## Usage
|
|
104
|
+
|
|
105
|
+
All commands output pretty-printed JSON by default. Use `--format compact` for compact single-line JSON.
|
|
106
|
+
|
|
107
|
+
### search
|
|
108
|
+
|
|
109
|
+
Search YouTube for videos, channels, and playlists.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
youtube-data-cli search --q "node.js tutorial"
|
|
113
|
+
youtube-data-cli search --q "cooking" --type video --max-results 10
|
|
114
|
+
youtube-data-cli search --q "live coding" --event-type live --type video
|
|
115
|
+
youtube-data-cli search --q "music" --order viewCount --published-after 2026-01-01T00:00:00Z
|
|
116
|
+
youtube-data-cli search --q "tech" --region-code US --relevance-language en
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Options:
|
|
120
|
+
- `--q <query>` -- search query (required)
|
|
121
|
+
- `--type <type>` -- resource type: `video`, `channel`, `playlist` (default: `video,channel,playlist`)
|
|
122
|
+
- `--max-results <n>` -- max results 1-50 (default: `5`)
|
|
123
|
+
- `--order <order>` -- sort: `relevance`, `date`, `rating`, `title`, `videoCount`, `viewCount`
|
|
124
|
+
- `--channel-id <id>` -- limit to a specific channel
|
|
125
|
+
- `--page-token <token>` -- pagination token
|
|
126
|
+
- `--published-after <datetime>` -- filter by publish date (RFC 3339)
|
|
127
|
+
- `--published-before <datetime>` -- filter by publish date (RFC 3339)
|
|
128
|
+
- `--region-code <code>` -- country code (ISO 3166-1 alpha-2)
|
|
129
|
+
- `--relevance-language <lang>` -- language code (ISO 639-1)
|
|
130
|
+
- `--safe-search <level>` -- `none`, `moderate`, `strict`
|
|
131
|
+
- `--video-duration <duration>` -- `any`, `short`, `medium`, `long`
|
|
132
|
+
- `--video-definition <def>` -- `any`, `high`, `standard`
|
|
133
|
+
- `--video-type <type>` -- `any`, `episode`, `movie`
|
|
134
|
+
- `--event-type <type>` -- `completed`, `live`, `upcoming`
|
|
135
|
+
- `--topic-id <id>` -- Freebase topic ID
|
|
136
|
+
- `--video-category-id <id>` -- video category ID
|
|
137
|
+
|
|
138
|
+
### channels
|
|
139
|
+
|
|
140
|
+
Get channel details. Omit ID to get the authenticated user's channel (requires OAuth).
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
youtube-data-cli channels UCxxxxxxxxxxxxxx
|
|
144
|
+
youtube-data-cli channels # your own channel (OAuth required)
|
|
145
|
+
youtube-data-cli channels UCxxxxxxxxxxxxxx --part snippet,statistics,brandingSettings
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Options:
|
|
149
|
+
- `--part <parts>` -- parts to include (default: `snippet,statistics,contentDetails`)
|
|
150
|
+
|
|
151
|
+
### videos
|
|
152
|
+
|
|
153
|
+
Get video details by IDs (comma-separated).
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
youtube-data-cli videos dQw4w9WgXcQ
|
|
157
|
+
youtube-data-cli videos dQw4w9WgXcQ,jNQXAC9IVRw --part snippet,statistics,contentDetails
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Options:
|
|
161
|
+
- `--part <parts>` -- parts to include (default: `snippet,statistics,contentDetails`)
|
|
162
|
+
|
|
163
|
+
### playlists
|
|
164
|
+
|
|
165
|
+
List playlists by ID, channel, or authenticated user.
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
youtube-data-cli playlists --channel-id UCxxxxxxxxxxxxxx
|
|
169
|
+
youtube-data-cli playlists --mine # your playlists (OAuth required)
|
|
170
|
+
youtube-data-cli playlists --id PLxxxxxxxxxxxxxx
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Options:
|
|
174
|
+
- `--id <id>` -- playlist ID(s), comma-separated
|
|
175
|
+
- `--channel-id <id>` -- channel ID
|
|
176
|
+
- `--mine` -- list your playlists (OAuth required)
|
|
177
|
+
- `--part <parts>` -- parts to include (default: `snippet,contentDetails`)
|
|
178
|
+
- `--max-results <n>` -- max results 1-50 (default: `25`)
|
|
179
|
+
- `--page-token <token>` -- pagination token
|
|
180
|
+
|
|
181
|
+
### playlists-insert
|
|
182
|
+
|
|
183
|
+
Create a new playlist (OAuth required).
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
youtube-data-cli playlists-insert --title "My Playlist"
|
|
187
|
+
youtube-data-cli playlists-insert --title "Public Playlist" --description "A great playlist" --privacy public
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Options:
|
|
191
|
+
- `--title <title>` -- playlist title (required)
|
|
192
|
+
- `--description <desc>` -- playlist description
|
|
193
|
+
- `--privacy <status>` -- `public`, `private`, `unlisted` (default: `private`)
|
|
194
|
+
- `--default-language <lang>` -- default language (ISO 639-1)
|
|
195
|
+
|
|
196
|
+
### playlists-update
|
|
197
|
+
|
|
198
|
+
Update a playlist (OAuth required).
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
youtube-data-cli playlists-update --id PLxxxxxxxxxxxxxx --title "Updated Title"
|
|
202
|
+
youtube-data-cli playlists-update --id PLxxxxxxxxxxxxxx --title "New Title" --privacy public
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Options:
|
|
206
|
+
- `--id <id>` -- playlist ID (required)
|
|
207
|
+
- `--title <title>` -- playlist title (required)
|
|
208
|
+
- `--description <desc>` -- playlist description
|
|
209
|
+
- `--privacy <status>` -- `public`, `private`, `unlisted`
|
|
210
|
+
- `--default-language <lang>` -- default language (ISO 639-1)
|
|
211
|
+
|
|
212
|
+
### playlists-delete
|
|
213
|
+
|
|
214
|
+
Delete a playlist (OAuth required).
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
youtube-data-cli playlists-delete --id PLxxxxxxxxxxxxxx
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Options:
|
|
221
|
+
- `--id <id>` -- playlist ID (required)
|
|
222
|
+
|
|
223
|
+
### playlist-items
|
|
224
|
+
|
|
225
|
+
List items in a playlist.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
youtube-data-cli playlist-items --playlist-id PLxxxxxxxxxxxxxx
|
|
229
|
+
youtube-data-cli playlist-items --playlist-id PLxxxxxxxxxxxxxx --max-results 50
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Options:
|
|
233
|
+
- `--playlist-id <id>` -- playlist ID (required)
|
|
234
|
+
- `--part <parts>` -- parts to include (default: `snippet,contentDetails`)
|
|
235
|
+
- `--max-results <n>` -- max results 1-50 (default: `25`)
|
|
236
|
+
- `--page-token <token>` -- pagination token
|
|
237
|
+
- `--video-id <id>` -- filter by video ID
|
|
238
|
+
|
|
239
|
+
### playlist-items-insert
|
|
240
|
+
|
|
241
|
+
Add a video to a playlist (OAuth required).
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
youtube-data-cli playlist-items-insert --playlist-id PLxxxxxxxxxxxxxx --video-id dQw4w9WgXcQ
|
|
245
|
+
youtube-data-cli playlist-items-insert --playlist-id PLxxxxxxxxxxxxxx --video-id dQw4w9WgXcQ --position 0
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Options:
|
|
249
|
+
- `--playlist-id <id>` -- playlist ID (required)
|
|
250
|
+
- `--video-id <id>` -- video ID to add (required)
|
|
251
|
+
- `--position <n>` -- position in the playlist (0-based)
|
|
252
|
+
|
|
253
|
+
### playlist-items-update
|
|
254
|
+
|
|
255
|
+
Update a playlist item position (OAuth required).
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
youtube-data-cli playlist-items-update --id ITEM_ID --playlist-id PLxxxxxxxxxxxxxx --video-id dQw4w9WgXcQ --position 3
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Options:
|
|
262
|
+
- `--id <id>` -- playlist item ID (required)
|
|
263
|
+
- `--playlist-id <id>` -- playlist ID (required)
|
|
264
|
+
- `--video-id <id>` -- video ID (required)
|
|
265
|
+
- `--position <n>` -- new position (0-based)
|
|
266
|
+
|
|
267
|
+
### playlist-items-delete
|
|
268
|
+
|
|
269
|
+
Remove an item from a playlist (OAuth required).
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
youtube-data-cli playlist-items-delete --id ITEM_ID
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Options:
|
|
276
|
+
- `--id <id>` -- playlist item ID (required)
|
|
277
|
+
|
|
278
|
+
### comment-threads
|
|
279
|
+
|
|
280
|
+
List comment threads for a video, channel, or by ID.
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
youtube-data-cli comment-threads --video-id dQw4w9WgXcQ
|
|
284
|
+
youtube-data-cli comment-threads --video-id dQw4w9WgXcQ --order time --max-results 50
|
|
285
|
+
youtube-data-cli comment-threads --channel-id UCxxxxxxxxxxxxxx
|
|
286
|
+
youtube-data-cli comment-threads --video-id dQw4w9WgXcQ --search-terms "great video"
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Options:
|
|
290
|
+
- `--video-id <id>` -- video ID
|
|
291
|
+
- `--channel-id <id>` -- channel ID
|
|
292
|
+
- `--id <id>` -- comment thread ID(s), comma-separated
|
|
293
|
+
- `--part <parts>` -- parts to include (default: `snippet,replies`)
|
|
294
|
+
- `--max-results <n>` -- max results 1-100 (default: `20`)
|
|
295
|
+
- `--page-token <token>` -- pagination token
|
|
296
|
+
- `--order <order>` -- `time` or `relevance` (default: `relevance`)
|
|
297
|
+
- `--search-terms <q>` -- filter by search terms
|
|
298
|
+
|
|
299
|
+
### comment-threads-insert
|
|
300
|
+
|
|
301
|
+
Post a top-level comment on a video (OAuth required).
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
youtube-data-cli comment-threads-insert --video-id dQw4w9WgXcQ --text "Great video!"
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Options:
|
|
308
|
+
- `--video-id <id>` -- video ID (required)
|
|
309
|
+
- `--text <text>` -- comment text (required)
|
|
310
|
+
|
|
311
|
+
### comments
|
|
312
|
+
|
|
313
|
+
List replies to a comment thread.
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
youtube-data-cli comments --parent-id COMMENT_ID
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Options:
|
|
320
|
+
- `--parent-id <id>` -- parent comment ID (required)
|
|
321
|
+
- `--part <parts>` -- parts to include (default: `snippet`)
|
|
322
|
+
- `--max-results <n>` -- max results 1-100 (default: `20`)
|
|
323
|
+
- `--page-token <token>` -- pagination token
|
|
324
|
+
|
|
325
|
+
### comments-insert
|
|
326
|
+
|
|
327
|
+
Reply to a comment (OAuth required).
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
youtube-data-cli comments-insert --parent-id COMMENT_ID --text "Thanks for the feedback!"
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Options:
|
|
334
|
+
- `--parent-id <id>` -- parent comment ID (required)
|
|
335
|
+
- `--text <text>` -- reply text (required)
|
|
336
|
+
|
|
337
|
+
### comments-update
|
|
338
|
+
|
|
339
|
+
Update a comment (OAuth required).
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
youtube-data-cli comments-update --id COMMENT_ID --text "Updated comment text"
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Options:
|
|
346
|
+
- `--id <id>` -- comment ID (required)
|
|
347
|
+
- `--text <text>` -- updated text (required)
|
|
348
|
+
|
|
349
|
+
### comments-delete
|
|
350
|
+
|
|
351
|
+
Delete a comment (OAuth required).
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
youtube-data-cli comments-delete --id COMMENT_ID
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Options:
|
|
358
|
+
- `--id <id>` -- comment ID (required)
|
|
359
|
+
|
|
360
|
+
### subscriptions
|
|
361
|
+
|
|
362
|
+
List subscriptions.
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
youtube-data-cli subscriptions --mine # your subscriptions (OAuth required)
|
|
366
|
+
youtube-data-cli subscriptions --channel-id UCxxxxxxxxxxxxxx
|
|
367
|
+
youtube-data-cli subscriptions --mine --order alphabetical --max-results 50
|
|
368
|
+
youtube-data-cli subscriptions --mine --for-channel-id UCxxxxxxxxxxxxxx
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Options:
|
|
372
|
+
- `--channel-id <id>` -- list subscriptions for a channel
|
|
373
|
+
- `--id <id>` -- subscription ID(s), comma-separated
|
|
374
|
+
- `--mine` -- list your subscriptions (OAuth required)
|
|
375
|
+
- `--part <parts>` -- parts to include (default: `snippet,contentDetails`)
|
|
376
|
+
- `--max-results <n>` -- max results 1-50 (default: `25`)
|
|
377
|
+
- `--page-token <token>` -- pagination token
|
|
378
|
+
- `--order <order>` -- `alphabetical`, `relevance`, `unread`
|
|
379
|
+
- `--for-channel-id <id>` -- filter by subscribed channel ID(s)
|
|
380
|
+
|
|
381
|
+
### subscriptions-insert
|
|
382
|
+
|
|
383
|
+
Subscribe to a channel (OAuth required).
|
|
384
|
+
|
|
385
|
+
```bash
|
|
386
|
+
youtube-data-cli subscriptions-insert --channel-id UCxxxxxxxxxxxxxx
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
Options:
|
|
390
|
+
- `--channel-id <id>` -- channel ID to subscribe to (required)
|
|
391
|
+
|
|
392
|
+
### subscriptions-delete
|
|
393
|
+
|
|
394
|
+
Unsubscribe (OAuth required).
|
|
395
|
+
|
|
396
|
+
```bash
|
|
397
|
+
youtube-data-cli subscriptions-delete --id SUBSCRIPTION_ID
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Options:
|
|
401
|
+
- `--id <id>` -- subscription ID (required)
|
|
402
|
+
|
|
403
|
+
## Error output
|
|
404
|
+
|
|
405
|
+
Errors are written to stderr as JSON with an `error` field and a non-zero exit code:
|
|
406
|
+
|
|
407
|
+
```json
|
|
408
|
+
{"error": "OAuth credentials required (client_id, client_secret, refresh_token). API key alone is not sufficient for this command."}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
## API Reference
|
|
412
|
+
|
|
413
|
+
- YouTube Data API v3: https://developers.google.com/youtube/v3
|
|
414
|
+
|
|
415
|
+
## Related
|
|
416
|
+
|
|
417
|
+
- [youtube-analytics-cli](https://github.com/Bin-Huang/youtube-analytics-cli) -- YouTube Analytics CLI for AI agents (and humans)
|
|
418
|
+
- [google-analytics-cli](https://github.com/Bin-Huang/google-analytics-cli) -- Google Analytics CLI for AI agents (and humans)
|
|
419
|
+
- [google-search-console-cli](https://github.com/Bin-Huang/google-search-console-cli) -- Google Search Console CLI for AI agents (and humans)
|
|
420
|
+
- [x-analytics-cli](https://github.com/Bin-Huang/x-analytics-cli) -- X Analytics CLI for AI agents (and humans)
|
|
421
|
+
|
|
422
|
+
## License
|
|
423
|
+
|
|
424
|
+
Apache-2.0
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getAccessToken } from "./auth.js";
|
|
2
|
+
const DATA_API_BASE = "https://www.googleapis.com/youtube/v3";
|
|
3
|
+
export async function callApi(endpoint, opts) {
|
|
4
|
+
const params = { ...opts.params };
|
|
5
|
+
const method = opts.method ?? "GET";
|
|
6
|
+
const headers = {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
};
|
|
9
|
+
// Write operations always require OAuth
|
|
10
|
+
const needsOAuth = opts.requireOAuth || method !== "GET" || !opts.creds.api_key;
|
|
11
|
+
if (needsOAuth) {
|
|
12
|
+
const token = await getAccessToken(opts.creds);
|
|
13
|
+
headers.Authorization = `Bearer ${token}`;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
params.key = opts.creds.api_key;
|
|
17
|
+
}
|
|
18
|
+
const searchParams = new URLSearchParams();
|
|
19
|
+
for (const [key, value] of Object.entries(params)) {
|
|
20
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
21
|
+
searchParams.set(key, value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const url = `${DATA_API_BASE}${endpoint}?${searchParams.toString()}`;
|
|
25
|
+
const fetchOpts = { method, headers };
|
|
26
|
+
if (opts.body && method !== "GET" && method !== "DELETE") {
|
|
27
|
+
fetchOpts.body = JSON.stringify(opts.body);
|
|
28
|
+
}
|
|
29
|
+
const res = await fetch(url, fetchOpts);
|
|
30
|
+
// DELETE may return 204 No Content
|
|
31
|
+
if (method === "DELETE" && res.status === 204) {
|
|
32
|
+
return { deleted: true };
|
|
33
|
+
}
|
|
34
|
+
const json = (await res.json());
|
|
35
|
+
if (!res.ok || json.error) {
|
|
36
|
+
throw new Error(json.error?.message ?? `HTTP ${res.status}`);
|
|
37
|
+
}
|
|
38
|
+
return json;
|
|
39
|
+
}
|