@lucasygu/redbook 0.1.1 → 0.1.5

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +241 -0
  3. package/package.json +3 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas Gu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # redbook — 小红书命令行工具
2
+
3
+ 小红书 CLI 工具:搜索笔记、阅读内容、分析博主、发布图文。使用浏览器 Cookie 认证,无需 API Key。
4
+
5
+ [English](#english) | 中文
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install -g @lucasygu/redbook
11
+ ```
12
+
13
+ 需要 Node.js >= 22。使用 Chrome 浏览器的 Cookie —— 请先在 Chrome 中登录 xiaohongshu.com。
14
+
15
+ ## 快速开始
16
+
17
+ ```bash
18
+ # 检查连接
19
+ redbook whoami
20
+
21
+ # 搜索笔记
22
+ redbook search "AI编程" --sort popular
23
+
24
+ # 阅读笔记
25
+ redbook read https://www.xiaohongshu.com/explore/abc123
26
+
27
+ # 获取评论
28
+ redbook comments https://www.xiaohongshu.com/explore/abc123 --all
29
+
30
+ # 浏览推荐页
31
+ redbook feed
32
+
33
+ # 查看博主信息
34
+ redbook user <userId>
35
+ redbook user-posts <userId>
36
+
37
+ # 搜索话题标签
38
+ redbook topics "Claude Code"
39
+
40
+ # 发布图文笔记
41
+ redbook post --title "标题" --body "正文内容" --images cover.png
42
+ redbook post --title "测试" --body "..." --images img.png --private
43
+ ```
44
+
45
+ ## 命令一览
46
+
47
+ | 命令 | 说明 |
48
+ |------|------|
49
+ | `whoami` | 查看当前登录账号 |
50
+ | `search <关键词>` | 搜索笔记 |
51
+ | `read <url>` | 阅读单篇笔记 |
52
+ | `comments <url>` | 获取笔记评论 |
53
+ | `user <userId>` | 查看用户资料 |
54
+ | `user-posts <userId>` | 列出用户所有笔记 |
55
+ | `feed` | 获取推荐页内容 |
56
+ | `post` | 发布图文笔记 |
57
+ | `topics <关键词>` | 搜索话题/标签 |
58
+
59
+ ### 通用选项
60
+
61
+ | 选项 | 说明 | 默认值 |
62
+ |------|------|--------|
63
+ | `--cookie-source <浏览器>` | Cookie 来源浏览器 | `chrome` |
64
+ | `--json` | JSON 格式输出 | `false` |
65
+
66
+ ### 搜索选项
67
+
68
+ | 选项 | 说明 | 默认值 |
69
+ |------|------|--------|
70
+ | `--sort <类型>` | `general`(综合)、`popular`(热门)、`latest`(最新) | `general` |
71
+ | `--type <类型>` | `all`(全部)、`video`(视频)、`image`(图文) | `all` |
72
+ | `--page <页码>` | 页码 | `1` |
73
+
74
+ ### 发布选项
75
+
76
+ | 选项 | 说明 |
77
+ |------|------|
78
+ | `--title <标题>` | 笔记标题(必填) |
79
+ | `--body <正文>` | 笔记正文(必填) |
80
+ | `--images <路径...>` | 图片文件路径(必填) |
81
+ | `--topic <关键词>` | 附加话题标签 |
82
+ | `--private` | 发布为私密笔记 |
83
+
84
+ ## 工作原理
85
+
86
+ `redbook` 从 Chrome 读取小红书的登录 Cookie(通过 [@steipete/sweet-cookie](https://github.com/nicklockwood/sweet-cookie)),然后用 TypeScript 实现的签名算法对 API 请求签名。无需浏览器自动化,无需 headless Chrome —— 纯 HTTP 请求。
87
+
88
+ **两套签名系统:**
89
+ - **主 API**(`edith.xiaohongshu.com`)—— 读取:搜索、推荐页、笔记、评论、用户资料。使用 144 字节 x-s 签名(v4.3.1)
90
+ - **创作者 API**(`creator.xiaohongshu.com`)—— 写入:上传图片、发布笔记。使用 AES-128-CBC 签名
91
+
92
+ ## 编程接口
93
+
94
+ ```typescript
95
+ import { XhsClient } from "@lucasygu/redbook";
96
+ import { loadCookies } from "@lucasygu/redbook/cookies";
97
+
98
+ const cookies = await loadCookies("chrome");
99
+ const client = new XhsClient(cookies);
100
+
101
+ const results = await client.searchNotes("AI编程", 1, 20, "popular");
102
+ const topics = await client.searchTopics("Claude Code");
103
+ ```
104
+
105
+ ## 致谢
106
+
107
+ 签名算法移植自以下开源项目(MIT 协议):
108
+
109
+ - [Cloxl/xhshow](https://github.com/Cloxl/xhshow) — 主 API 签名(x-s, x-s-common)
110
+ - [Spider_XHS](https://github.com/JoeanAmier/XHS-Downloader) — 创作者 API 签名
111
+ - [ReaJason/xhs](https://github.com/ReaJason/xhs) — API 端点参考
112
+
113
+ Cookie 提取使用 [@steipete/sweet-cookie](https://github.com/nicklockwood/sweet-cookie)。
114
+
115
+ ## 免责声明
116
+
117
+ 本工具使用非官方 API。小红书可能随时更改或封锁这些接口。请合理使用,风险自负。本项目与小红书无任何关联。
118
+
119
+ ---
120
+
121
+ <a id="english"></a>
122
+
123
+ # English
124
+
125
+ A fast CLI tool for [Xiaohongshu (小红书 / RED)](https://www.xiaohongshu.com) — search notes, read content, analyze creators, and publish posts. Uses browser cookie auth (no API key needed).
126
+
127
+ ## Install
128
+
129
+ ```bash
130
+ npm install -g @lucasygu/redbook
131
+ ```
132
+
133
+ Requires Node.js >= 22. Uses cookies from your Chrome browser session — you must be logged into xiaohongshu.com in Chrome.
134
+
135
+ ## Quick Start
136
+
137
+ ```bash
138
+ # Check connection
139
+ redbook whoami
140
+
141
+ # Search notes
142
+ redbook search "AI编程" --sort popular
143
+
144
+ # Read a note
145
+ redbook read https://www.xiaohongshu.com/explore/abc123
146
+
147
+ # Get comments
148
+ redbook comments https://www.xiaohongshu.com/explore/abc123 --all
149
+
150
+ # Browse your feed
151
+ redbook feed
152
+
153
+ # Look up a creator
154
+ redbook user <userId>
155
+ redbook user-posts <userId>
156
+
157
+ # Search hashtags
158
+ redbook topics "Claude Code"
159
+
160
+ # Publish (requires image)
161
+ redbook post --title "标题" --body "正文" --images cover.png
162
+ redbook post --title "测试" --body "..." --images img.png --private
163
+ ```
164
+
165
+ ## Commands
166
+
167
+ | Command | Description |
168
+ |---------|-------------|
169
+ | `whoami` | Check connection and show current user info |
170
+ | `search <keyword>` | Search notes by keyword |
171
+ | `read <url>` | Read a note by URL |
172
+ | `comments <url>` | Get comments on a note |
173
+ | `user <userId>` | Get user profile info |
174
+ | `user-posts <userId>` | List a user's posted notes |
175
+ | `feed` | Get homepage feed |
176
+ | `post` | Publish an image note |
177
+ | `topics <keyword>` | Search for topics/hashtags |
178
+
179
+ ### Global Options
180
+
181
+ | Option | Description | Default |
182
+ |--------|-------------|---------|
183
+ | `--cookie-source <browser>` | Browser to read cookies from | `chrome` |
184
+ | `--json` | Output as JSON | `false` |
185
+
186
+ ### Search Options
187
+
188
+ | Option | Description | Default |
189
+ |--------|-------------|---------|
190
+ | `--sort <type>` | `general`, `popular`, `latest` | `general` |
191
+ | `--type <type>` | `all`, `video`, `image` | `all` |
192
+ | `--page <n>` | Page number | `1` |
193
+
194
+ ### Post Options
195
+
196
+ | Option | Description |
197
+ |--------|-------------|
198
+ | `--title <title>` | Note title (required) |
199
+ | `--body <body>` | Note body text (required) |
200
+ | `--images <paths...>` | Image file paths (required) |
201
+ | `--topic <keyword>` | Topic/hashtag to search and attach |
202
+ | `--private` | Publish as private note |
203
+
204
+ ## How It Works
205
+
206
+ `redbook` reads your XHS session cookies from Chrome (via [@steipete/sweet-cookie](https://github.com/nicklockwood/sweet-cookie)) and signs API requests using a TypeScript port of the XHS signing algorithm. No browser automation, no headless Chrome — just HTTP requests.
207
+
208
+ **Two signing systems:**
209
+ - **Main API** (`edith.xiaohongshu.com`) — for reading: search, feed, notes, comments, user profiles. Uses x-s signature with 144-byte payload (v4.3.1).
210
+ - **Creator API** (`creator.xiaohongshu.com`) — for writing: upload images, publish notes. Uses simpler AES-128-CBC signing.
211
+
212
+ ## Programmatic Usage
213
+
214
+ ```typescript
215
+ import { XhsClient } from "@lucasygu/redbook";
216
+ import { loadCookies } from "@lucasygu/redbook/cookies";
217
+
218
+ const cookies = await loadCookies("chrome");
219
+ const client = new XhsClient(cookies);
220
+
221
+ const results = await client.searchNotes("AI编程", 1, 20, "popular");
222
+ const topics = await client.searchTopics("Claude Code");
223
+ ```
224
+
225
+ ## Acknowledgments
226
+
227
+ Signing algorithms ported from these open-source projects (MIT licensed):
228
+
229
+ - [Cloxl/xhshow](https://github.com/Cloxl/xhshow) — Main API signing (x-s, x-s-common)
230
+ - [Spider_XHS](https://github.com/JoeanAmier/XHS-Downloader) — Creator API signing
231
+ - [ReaJason/xhs](https://github.com/ReaJason/xhs) — API endpoint reference
232
+
233
+ Cookie extraction via [@steipete/sweet-cookie](https://github.com/nicklockwood/sweet-cookie).
234
+
235
+ ## Disclaimer
236
+
237
+ This tool uses unofficial/private APIs. Xiaohongshu may change or block these APIs at any time. Use responsibly and at your own risk. This project is not affiliated with Xiaohongshu.
238
+
239
+ ## License
240
+
241
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucasygu/redbook",
3
- "version": "0.1.1",
3
+ "version": "0.1.5",
4
4
  "description": "CLI tool for Xiaohongshu (Red Note) - read and post via private API",
5
5
  "type": "module",
6
6
  "main": "./dist/lib/client.js",
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "files": [
16
16
  "dist/",
17
- "LICENSE"
17
+ "LICENSE",
18
+ "README.md"
18
19
  ],
19
20
  "scripts": {
20
21
  "build": "tsc && chmod +x dist/cli.js",