Skip to content

Commit 3ebc46f

Browse files
feat(bilibili): favorite command supports specifying fid (#1013)
* feat(bilibili): favorite command supports specifying fid * fix(bilibili): sync favorite help and docs contract --------- Co-authored-by: jackwener <jakevingoo@gmail.com>
1 parent 6e29845 commit 3ebc46f

4 files changed

Lines changed: 35 additions & 16 deletions

File tree

cli-manifest.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,11 +1267,17 @@
12671267
{
12681268
"site": "bilibili",
12691269
"name": "favorite",
1270-
"description": "我的默认收藏夹",
1270+
"description": "我的收藏夹",
12711271
"domain": "www.bilibili.com",
12721272
"strategy": "cookie",
12731273
"browser": true,
12741274
"args": [
1275+
{
1276+
"name": "fid",
1277+
"type": "int",
1278+
"required": false,
1279+
"help": "Favorite folder ID (defaults to first folder)"
1280+
},
12751281
{
12761282
"name": "limit",
12771283
"type": "int",

clis/bilibili/favorite.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@ import { apiGet, payloadData, getSelfUid } from './utils.js';
33
cli({
44
site: 'bilibili',
55
name: 'favorite',
6-
description: '我的默认收藏夹',
6+
description: '我的收藏夹',
77
domain: 'www.bilibili.com',
88
strategy: Strategy.COOKIE,
99
args: [
10+
{ name: 'fid', type: 'int', required: false, help: 'Favorite folder ID (defaults to first folder)' },
1011
{ name: 'limit', type: 'int', default: 20, help: 'Number of results' },
1112
{ name: 'page', type: 'int', default: 1, help: 'Page number' },
1213
],
1314
columns: ['rank', 'title', 'author', 'plays', 'url'],
1415
func: async (page, kwargs) => {
15-
const { limit = 20, page: pageNum = 1 } = kwargs;
16-
// Get current user's UID
17-
const uid = await getSelfUid(page);
18-
// Get default favorite folder ID
19-
const foldersPayload = await apiGet(page, '/x/v3/fav/folder/created/list-all', {
20-
params: { up_mid: uid },
21-
signed: true,
22-
});
23-
const folders = payloadData(foldersPayload)?.list ?? [];
24-
if (!folders.length)
25-
return [];
26-
const fid = folders[0].id;
16+
const { fid: favoriteId, limit = 20, page: pageNum = 1 } = kwargs;
17+
let fid;
18+
if (favoriteId) {
19+
fid = Number(favoriteId);
20+
} else {
21+
// Fall back to the default (first) favorite folder
22+
const uid = await getSelfUid(page);
23+
const foldersPayload = await apiGet(page, '/x/v3/fav/folder/created/list-all', {
24+
params: { up_mid: uid },
25+
signed: true,
26+
});
27+
const folders = payloadData(foldersPayload)?.list ?? [];
28+
if (!folders.length)
29+
return [];
30+
fid = folders[0].id;
31+
}
2732
// Fetch favorite items
2833
const payload = await apiGet(page, '/x/v3/fav/resource/list', {
2934
params: { media_id: fid, pn: pageNum, ps: Math.min(Number(limit), 40) },

docs/adapters/browser/bilibili.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| `opencli bilibili hot` | |
1010
| `opencli bilibili search` | |
1111
| `opencli bilibili me` | |
12-
| `opencli bilibili favorite` | |
12+
| `opencli bilibili favorite` | Read your first favorite folder, or a specific folder with `--fid` |
1313
| `opencli bilibili history` | |
1414
| `opencli bilibili feed` | Read the following feed, or a specific user's dynamics by uid/name |
1515
| `opencli bilibili feed-detail` | Read one dynamic in detail, including exclusive content |
@@ -32,6 +32,12 @@ opencli bilibili search 黑神话 --limit 10
3232
# Read one creator's videos
3333
opencli bilibili user-videos 2 --limit 10
3434

35+
# Read your first favorite folder
36+
opencli bilibili favorite --limit 10
37+
38+
# Read a specific favorite folder
39+
opencli bilibili favorite --fid 123456789 --limit 10
40+
3541
# Read following feed
3642
opencli bilibili feed --limit 10
3743

@@ -63,4 +69,5 @@ opencli bilibili hot -v
6369

6470
- `opencli bilibili feed` without `uid` reads your following feed
6571
- `opencli bilibili feed <uid-or-name>` reads a specific user's dynamics
72+
- `opencli bilibili favorite` defaults to the first favorite folder when `--fid` is omitted
6673
- `feed-detail` expects the dynamic ID from a `https://t.bilibili.com/<id>` URL

skills/opencli-usage/commands.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ opencli bbc news --limit 10 # BBC News RSS headlines
7979
opencli bilibili hot --limit 10 # B站热门视频
8080
opencli bilibili search "rust" # 搜索视频 (query positional)
8181
opencli bilibili me # 我的信息
82-
opencli bilibili favorite # 我的收藏
82+
opencli bilibili favorite # 我的收藏夹(默认第一个收藏夹)
83+
opencli bilibili favorite --fid 123456789 # 指定收藏夹
8384
opencli bilibili history --limit 20 # 观看历史
8485
opencli bilibili feed --limit 10 # 动态时间线
8586
opencli bilibili user-videos --uid 12345 # 用户投稿

0 commit comments

Comments
 (0)