dsh-mikan 0.1.0 → 0.2.0
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/CHANGELOG.md +56 -0
- package/README.md +15 -12
- package/client.js +323 -30
- package/index.js +152 -62
- package/lib/constants.js +7 -1
- package/lib/mikan.js +56 -2
- package/lib/net.js +10 -2
- package/lib/qbittorrent.js +164 -0
- package/package.json +5 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### 新增
|
|
6
|
+
|
|
7
|
+
- **qBittorrent 支持**:与 BitComet 并列的第二种下载器,支持 localhost 免认证
|
|
8
|
+
- **下载器自动检测**:「自动检测」依次尝试两种下载器,找到即自动切换配置
|
|
9
|
+
- **下载器管理弹窗**:点击状态气泡查看端口扫描结果、切换下载器
|
|
10
|
+
- **语言分类**:作品按字幕语言分为简体 / 繁体 / 多字幕(垃圾桶)三类
|
|
11
|
+
- 简 / CHS / GB / 简日 → 简体
|
|
12
|
+
- 繁 / CHT / BIG5 / 繁日 → 繁体
|
|
13
|
+
- 简繁都有 / 多语 / 生肉 / 无标记 → 多字幕
|
|
14
|
+
- **按语言分组视图**:作品列表可切换分组,简体置顶
|
|
15
|
+
- **批量下载**:全部 / 简中 / 繁中 / 多字幕四种方式,数量实时统计,空类置灰
|
|
16
|
+
- **当季 / 往季浏览**:当季按月份自动判断;往季可选近 12 年任意季度
|
|
17
|
+
- **全量作品列表**:改用 `/Home/ExpandEpisodeTable`,突破 RSS 单组 100 条上限
|
|
18
|
+
- **显示更多**:列表首次加载 60 条,可翻页至全量
|
|
19
|
+
- **配置 HTTP 接口**:前端可直接修改下载器、代理、目录等设置
|
|
20
|
+
|
|
21
|
+
### 修复
|
|
22
|
+
|
|
23
|
+
- RSS 单组上限 100 条导致长番作品被截断(柯南组实测 100/346)
|
|
24
|
+
- Node 发送 POST 未带 `Content-Length` 时使用 chunked,qBittorrent 拒绝
|
|
25
|
+
- multipart boundary 格式不被 qBittorrent 接受(返回 `Fails.`)
|
|
26
|
+
- 下载目录未配置时静默失败,改为明确报错
|
|
27
|
+
|
|
28
|
+
### 优化
|
|
29
|
+
|
|
30
|
+
- 工具默认返回条数 60 → 30,单次约省一半 token
|
|
31
|
+
- 下载器状态统一称「P2P 下载器」,未连接时不再区分具体软件
|
|
32
|
+
- 连接指引同时展示 BitComet 与 qBittorrent 两套步骤
|
|
33
|
+
- 移除本地调试残留(硬编码路径、调试日志)
|
|
34
|
+
|
|
35
|
+
## 0.1.0
|
|
36
|
+
|
|
37
|
+
首个版本:
|
|
38
|
+
|
|
39
|
+
- 三级懒加载浏览(季度 → 番剧 → 字幕组 → 作品)
|
|
40
|
+
- 按字幕组订阅,每组独立水位
|
|
41
|
+
- 更新通知:侧栏红绿黄状态点 + 更新信息条
|
|
42
|
+
- 静默关注 / 取消订阅
|
|
43
|
+
- BitComet 下载
|
|
44
|
+
- 双镜像自适应(墙内 mikanime.tv / 墙外 mikanani.me)
|
|
45
|
+
- 开播日兜底(bgm.tv / AniList)
|
|
46
|
+
- 对话工具:浏览、订阅、检查更新、下载、状态、配置
|
|
47
|
+
|
|
48
|
+
## 后续计划
|
|
49
|
+
|
|
50
|
+
- 对话内点单预览 + 确认后批量下载
|
|
51
|
+
- Transmission / aria2 适配
|
|
52
|
+
- 多源支持(Erai-raws 等,待定)
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT
|
package/README.md
CHANGED
|
@@ -34,30 +34,33 @@ dsh plugin --profile web add dsh-mikan
|
|
|
34
34
|
```yaml
|
|
35
35
|
- id: dsh-mikan
|
|
36
36
|
config:
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
downloader: 'qbittorrent' # 或 'bitcomet'(默认)
|
|
38
|
+
qbittorrentBase: 'http://127.0.0.1:8080'
|
|
39
39
|
savePath: 'D:\Downloads\Anime'
|
|
40
|
+
proxy: 'http://127.0.0.1:7890'
|
|
40
41
|
checkIntervalMinutes: 30
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
| 字段 | 默认 | 说明 |
|
|
44
45
|
|---|---|---|
|
|
45
|
-
| `
|
|
46
|
-
| `bitcometBase` | `http://127.0.0.1:10816` |
|
|
46
|
+
| `downloader` | `bitcomet` | 下载器后端:`bitcomet` 或 `qbittorrent` |
|
|
47
|
+
| `bitcometBase` | `http://127.0.0.1:10816` | BitComet WebUI 地址 |
|
|
48
|
+
| `qbittorrentBase` | `http://127.0.0.1:8080` | qBittorrent WebUI 地址 |
|
|
49
|
+
| `qbittorrentUser` / `qbittorrentPassword` | 空 | qB 凭据;qB 允许 localhost 免认证时可留空 |
|
|
47
50
|
| `savePath` | 空(必填) | 下载保存目录,未设置时下载会被拒绝 |
|
|
51
|
+
| `proxy` | 空 | 本地代理地址,留空直连 |
|
|
48
52
|
| `checkIntervalMinutes` | 30 | 后台检查间隔 |
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
BitComet 的用户名密码会从 `%APPDATA%\BitComet\BitComet.xml` 自动读取,无需填写。
|
|
51
55
|
|
|
52
|
-
##
|
|
56
|
+
## 下载器
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
5. 不要勾「执行远程访问操作时显示提示窗口」
|
|
58
|
+
| 下载器 | 配置 |
|
|
59
|
+
|---|---|
|
|
60
|
+
| **BitComet** | 选项 → 远程访问 → 开启网页版访问,端口固定值 |
|
|
61
|
+
| **qBittorrent** | 工具 → 选项 → Web UI → 启用 Web 用户界面 |
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
插件不会自己启动或关闭下载器,请保持它运行。
|
|
61
64
|
|
|
62
65
|
## 环境自适应
|
|
63
66
|
|
package/client.js
CHANGED
|
@@ -28,13 +28,21 @@ window.__ModuleLoader__.load({
|
|
|
28
28
|
const panel = { border, borderRadius: 10, background: 'var(--dsw-alias-surface, transparent)' };
|
|
29
29
|
const muted = { opacity: 0.62, fontSize: 12 };
|
|
30
30
|
const row = { display: 'flex', gap: 10, alignItems: 'center', padding: '7px 0', borderBottom: border };
|
|
31
|
+
const SUB_LABEL = { trad: '繁', simp: '简', multi: '多' };
|
|
32
|
+
const SUB_COLOR = {
|
|
33
|
+
trad: 'var(--dsw-alias-warning, #f08c00)',
|
|
34
|
+
simp: 'var(--dsw-alias-success, #2f9e44)',
|
|
35
|
+
multi: 'var(--dsw-alias-text-secondary, #868e96)',
|
|
36
|
+
};
|
|
31
37
|
|
|
32
|
-
function Pill({ ok, children }) {
|
|
38
|
+
function Pill({ ok, children, onClick }) {
|
|
33
39
|
return h('span', {
|
|
40
|
+
onClick,
|
|
34
41
|
style: {
|
|
35
42
|
display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12,
|
|
36
43
|
padding: '2px 8px', borderRadius: 999, border,
|
|
37
44
|
color: ok ? 'var(--dsw-alias-success, #2f9e44)' : 'var(--dsw-alias-danger, #e03131)',
|
|
45
|
+
cursor: onClick ? 'pointer' : 'default',
|
|
38
46
|
},
|
|
39
47
|
}, h('span', { style: { width: 6, height: 6, borderRadius: '50%', background: 'currentColor' } }), children);
|
|
40
48
|
}
|
|
@@ -107,6 +115,10 @@ window.__ModuleLoader__.load({
|
|
|
107
115
|
const [dialog, setDialog] = useState(null);
|
|
108
116
|
const [browse, setBrowse] = useState(null);
|
|
109
117
|
const [expanded, setExpanded] = useState({});
|
|
118
|
+
const [scanResult, setScanResult] = useState(null);
|
|
119
|
+
const [groupByLang, setGroupByLang] = useState(false);
|
|
120
|
+
const [batchTarget, setBatchTarget] = useState(null);
|
|
121
|
+
const [batchStats, setBatchStats] = useState(null);
|
|
110
122
|
|
|
111
123
|
const load = useCallback(async ({ autoCheck = false } = {}) => {
|
|
112
124
|
try {
|
|
@@ -146,6 +158,40 @@ window.__ModuleLoader__.load({
|
|
|
146
158
|
catch (e) { setNotice('断开失败:' + e.message); } finally { setBusy(''); }
|
|
147
159
|
}, [load]);
|
|
148
160
|
|
|
161
|
+
const runScan = useCallback(async () => {
|
|
162
|
+
setBusy('scan');
|
|
163
|
+
try {
|
|
164
|
+
const r = await postJson('/downloader-scan');
|
|
165
|
+
setScanResult(r);
|
|
166
|
+
const label = r.type === 'qbittorrent' ? 'qBittorrent' : 'BitComet';
|
|
167
|
+
if (r.ok) setNotice(r.switched ? `已切换并连接 ${label}:端口 ${r.port}` : `已连接 ${label}:端口 ${r.port}`);
|
|
168
|
+
else setNotice(r.reason);
|
|
169
|
+
await load();
|
|
170
|
+
} catch (e) {
|
|
171
|
+
setNotice('检测失败:' + e.message);
|
|
172
|
+
} finally {
|
|
173
|
+
setBusy('');
|
|
174
|
+
}
|
|
175
|
+
}, [load]);
|
|
176
|
+
|
|
177
|
+
const switchTo = useCallback(async (type) => {
|
|
178
|
+
setBusy('switch');
|
|
179
|
+
try {
|
|
180
|
+
await postJson('/config', { downloader: type });
|
|
181
|
+
await load();
|
|
182
|
+
const r = await postJson('/downloader-scan');
|
|
183
|
+
setScanResult(r);
|
|
184
|
+
const label = r.type === 'qbittorrent' ? 'qBittorrent' : 'BitComet';
|
|
185
|
+
if (r.ok) setNotice(`已切换并连接 ${label}:端口 ${r.port}`);
|
|
186
|
+
else setNotice(r.reason);
|
|
187
|
+
await load();
|
|
188
|
+
} catch (e) {
|
|
189
|
+
setNotice('切换失败:' + e.message);
|
|
190
|
+
} finally {
|
|
191
|
+
setBusy('');
|
|
192
|
+
}
|
|
193
|
+
}, [load]);
|
|
194
|
+
|
|
149
195
|
const download = useCallback(async (hash, label) => {
|
|
150
196
|
setBusy('download');
|
|
151
197
|
try {
|
|
@@ -154,6 +200,28 @@ window.__ModuleLoader__.load({
|
|
|
154
200
|
} catch (e) { setNotice('下载失败:' + e.message); } finally { setBusy(''); }
|
|
155
201
|
}, []);
|
|
156
202
|
|
|
203
|
+
const batchDownload = useCallback(async (lang, label) => {
|
|
204
|
+
if (!browse) return;
|
|
205
|
+
setBusy('batch');
|
|
206
|
+
try {
|
|
207
|
+
const r = await getJson(`/works?bangumiId=${encodeURIComponent(browse.bangumiId)}&subgroupId=${encodeURIComponent(browse.subgroupId || '')}&subgroupName=${encodeURIComponent(browse.subgroupName || '')}&limit=500`);
|
|
208
|
+
const list = r.items || [];
|
|
209
|
+
const candidates = list.filter((w) => lang === 'all' || (w.subtitle || 'multi') === lang);
|
|
210
|
+
if (candidates.length === 0) {
|
|
211
|
+
setNotice(`没有「${label}」的作品`);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const res = await postJson('/download', { hashes: candidates.map((w) => w.hash) });
|
|
215
|
+
setNotice(res.ok
|
|
216
|
+
? `已批量加入 ${candidates.length} 个「${label}」任务`
|
|
217
|
+
: `批量下载部分失败:${res.results?.find((x) => !x.added)?.message || '未知错误'}`);
|
|
218
|
+
} catch (e) {
|
|
219
|
+
setNotice('批量下载失败:' + e.message);
|
|
220
|
+
} finally {
|
|
221
|
+
setBusy('');
|
|
222
|
+
}
|
|
223
|
+
}, [browse]);
|
|
224
|
+
|
|
157
225
|
const checkUpdates = useCallback(async () => {
|
|
158
226
|
setBusy('check');
|
|
159
227
|
setNotice('');
|
|
@@ -195,8 +263,11 @@ window.__ModuleLoader__.load({
|
|
|
195
263
|
/* ---------- browse (three levels) ---------- */
|
|
196
264
|
|
|
197
265
|
const openSeason = useCallback(async (year, season) => {
|
|
198
|
-
const
|
|
199
|
-
const
|
|
266
|
+
const now = new Date();
|
|
267
|
+
const month = now.getMonth() + 1;
|
|
268
|
+
const curSeason = month <= 3 ? '冬' : month <= 6 ? '春' : month <= 9 ? '夏' : '秋';
|
|
269
|
+
const y = year || now.getFullYear();
|
|
270
|
+
const s = season || curSeason;
|
|
200
271
|
setDialog({ type: 'browse' });
|
|
201
272
|
setBrowse({ level: 'season', year: y, season: s, loading: true, groups: [] });
|
|
202
273
|
try {
|
|
@@ -229,8 +300,8 @@ window.__ModuleLoader__.load({
|
|
|
229
300
|
subgroupId: subgroup.subgroupId, subgroupName: subgroup.name, loading: true, works: [],
|
|
230
301
|
}));
|
|
231
302
|
try {
|
|
232
|
-
const r = await getJson(`/works?bangumiId=${encodeURIComponent(id)}&subgroupId=${encodeURIComponent(subgroup.subgroupId || '')}`);
|
|
233
|
-
setBrowse((b) => ({ ...b, loading: false, works: r.items || [] }));
|
|
303
|
+
const r = await getJson(`/works?bangumiId=${encodeURIComponent(id)}&subgroupId=${encodeURIComponent(subgroup.subgroupId || '')}&subgroupName=${encodeURIComponent(subgroup.name || '')}&limit=60`);
|
|
304
|
+
setBrowse((b) => ({ ...b, loading: false, works: r.items || [], total: r.total || 0, limit: 60, counts: r.counts || null }));
|
|
234
305
|
} catch (e) {
|
|
235
306
|
setBrowse((b) => ({ ...b, loading: false, works: [], error: e.message }));
|
|
236
307
|
}
|
|
@@ -260,6 +331,64 @@ window.__ModuleLoader__.load({
|
|
|
260
331
|
return Boolean(sub && sub.subgroups.some((g) => g.subgroupId === subgroup.subgroupId || g.name === subgroup.name));
|
|
261
332
|
}, [schedule, browse]);
|
|
262
333
|
|
|
334
|
+
const loadMoreWorks = useCallback(async () => {
|
|
335
|
+
if (!browse) return;
|
|
336
|
+
const next = Math.min((browse.limit || 60) + 60, browse.total || 0);
|
|
337
|
+
try {
|
|
338
|
+
const r = await getJson(`/works?bangumiId=${encodeURIComponent(browse.bangumiId)}&subgroupId=${encodeURIComponent(browse.subgroupId || '')}&subgroupName=${encodeURIComponent(browse.subgroupName || '')}&limit=${next}`);
|
|
339
|
+
setBrowse((b) => ({ ...b, works: r.items || [], total: r.total || 0, limit: next }));
|
|
340
|
+
} catch (e) {
|
|
341
|
+
setNotice('加载更多失败:' + e.message);
|
|
342
|
+
}
|
|
343
|
+
}, [browse]);
|
|
344
|
+
|
|
345
|
+
const openBatch = useCallback(async (bangumiId, title, subgroup, ctx) => {
|
|
346
|
+
setBatchTarget({
|
|
347
|
+
bangumiId,
|
|
348
|
+
title,
|
|
349
|
+
subgroupId: subgroup.subgroupId,
|
|
350
|
+
subgroupName: subgroup.name,
|
|
351
|
+
season: ctx?.season,
|
|
352
|
+
year: ctx?.year,
|
|
353
|
+
});
|
|
354
|
+
setBatchStats(null);
|
|
355
|
+
setDialog({ type: 'batch' });
|
|
356
|
+
try {
|
|
357
|
+
const r = await getJson(`/works?bangumiId=${encodeURIComponent(bangumiId)}&subgroupId=${encodeURIComponent(subgroup.subgroupId || '')}&subgroupName=${encodeURIComponent(subgroup.name || '')}&limit=500`);
|
|
358
|
+
const list = r.items || [];
|
|
359
|
+
setBatchStats({
|
|
360
|
+
all: list.length,
|
|
361
|
+
simp: list.filter((w) => (w.subtitle || 'multi') === 'simp').length,
|
|
362
|
+
trad: list.filter((w) => (w.subtitle || 'multi') === 'trad').length,
|
|
363
|
+
multi: list.filter((w) => (w.subtitle || 'multi') === 'multi').length,
|
|
364
|
+
items: list,
|
|
365
|
+
});
|
|
366
|
+
} catch (e) {
|
|
367
|
+
setNotice('加载作品失败:' + e.message);
|
|
368
|
+
}
|
|
369
|
+
}, []);
|
|
370
|
+
|
|
371
|
+
const runBatch = useCallback(async (lang, label) => {
|
|
372
|
+
if (!batchStats?.items) return;
|
|
373
|
+
const candidates = batchStats.items.filter((w) => lang === 'all' || (w.subtitle || 'multi') === lang);
|
|
374
|
+
if (candidates.length === 0) {
|
|
375
|
+
setNotice(`没有「${label}」的作品`);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
setBusy('batch');
|
|
379
|
+
try {
|
|
380
|
+
const res = await postJson('/download', { hashes: candidates.map((w) => w.hash) });
|
|
381
|
+
setNotice(res.ok
|
|
382
|
+
? `已批量加入 ${candidates.length} 个「${label}」任务`
|
|
383
|
+
: `批量下载部分失败:${res.results?.find((x) => !x.added)?.message || '未知错误'}`);
|
|
384
|
+
setDialog(null);
|
|
385
|
+
} catch (e) {
|
|
386
|
+
setNotice('批量下载失败:' + e.message);
|
|
387
|
+
} finally {
|
|
388
|
+
setBusy('');
|
|
389
|
+
}
|
|
390
|
+
}, [batchStats]);
|
|
391
|
+
|
|
263
392
|
/* ---------- render ---------- */
|
|
264
393
|
|
|
265
394
|
if (error) {
|
|
@@ -337,28 +466,84 @@ window.__ModuleLoader__.load({
|
|
|
337
466
|
disabled: busy === 'subscribe' || isSubscribed(s),
|
|
338
467
|
onClick: () => subscribeGroup(s),
|
|
339
468
|
}, isSubscribed(s) ? '✓ 已订阅' : '订阅'),
|
|
469
|
+
h('button', { onClick: () => openBatch(browse.bangumiId, browse.title, s, browse) }, '批量下载'),
|
|
340
470
|
h('button', { onClick: () => openWorks(browse.bangumiId, browse.title, s, browse) }, '查看作品'))));
|
|
341
471
|
}
|
|
342
472
|
|
|
473
|
+
function renderWorkItem(w) {
|
|
474
|
+
return h('div', { key: w.hash, style: row },
|
|
475
|
+
h('div', { style: { flex: 1 } },
|
|
476
|
+
h('div', { style: { fontSize: 13, lineHeight: 1.35 } },
|
|
477
|
+
h('span', {
|
|
478
|
+
style: {
|
|
479
|
+
fontSize: 11, padding: '1px 5px', borderRadius: 4, marginRight: 6, border,
|
|
480
|
+
color: SUB_COLOR[w.subtitle] || SUB_COLOR.multi,
|
|
481
|
+
},
|
|
482
|
+
}, SUB_LABEL[w.subtitle] || '多'),
|
|
483
|
+
`[${w.episode || '?'}] ${w.title}`),
|
|
484
|
+
h('div', { style: muted }, `${w.size} · ${w.hash.slice(0, 8)}…`)),
|
|
485
|
+
h('button', { disabled: busy === 'download', onClick: () => download(w.hash, `第 ${w.episode} 集`) }, '下载'));
|
|
486
|
+
}
|
|
487
|
+
|
|
343
488
|
function renderWorksBrowse() {
|
|
344
489
|
const sub = { subgroupId: browse.subgroupId, name: browse.subgroupName };
|
|
490
|
+
const buckets = [
|
|
491
|
+
['simp', '简体'],
|
|
492
|
+
['trad', '繁体'],
|
|
493
|
+
['multi', '多字幕 / 生肉 / 未知'],
|
|
494
|
+
];
|
|
495
|
+
const items = browse.works || [];
|
|
496
|
+
const counts = browse.counts || {
|
|
497
|
+
all: items.length,
|
|
498
|
+
simp: items.filter((w) => (w.subtitle || 'multi') === 'simp').length,
|
|
499
|
+
trad: items.filter((w) => (w.subtitle || 'multi') === 'trad').length,
|
|
500
|
+
multi: items.filter((w) => (w.subtitle || 'multi') === 'multi').length,
|
|
501
|
+
};
|
|
502
|
+
const grouped = buckets.map(([key, label]) => ({
|
|
503
|
+
key,
|
|
504
|
+
label,
|
|
505
|
+
items: items.filter((w) => (w.subtitle || 'multi') === key),
|
|
506
|
+
}));
|
|
345
507
|
return h('div', null,
|
|
346
|
-
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginBottom: 12 } },
|
|
508
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginBottom: 12, flexWrap: 'wrap' } },
|
|
347
509
|
h('button', {
|
|
348
510
|
disabled: busy === 'subscribe' || isSubscribed(sub),
|
|
349
511
|
onClick: () => subscribeGroup(sub),
|
|
350
|
-
}, isSubscribed(sub) ? '✓ 已订阅本组' : '订阅本组')
|
|
512
|
+
}, isSubscribed(sub) ? '✓ 已订阅本组' : '订阅本组'),
|
|
513
|
+
h('button', {
|
|
514
|
+
onClick: () => setGroupByLang((v) => !v),
|
|
515
|
+
style: groupByLang
|
|
516
|
+
? { borderColor: 'var(--dsw-alias-accent, #4c8dff)', color: 'var(--dsw-alias-accent, #4c8dff)' }
|
|
517
|
+
: undefined,
|
|
518
|
+
}, groupByLang ? '✓ 按语言分组' : '按语言分组'),
|
|
519
|
+
h('span', { style: { flex: 1 } }),
|
|
520
|
+
h('button', { disabled: Boolean(busy) || counts.all === 0, onClick: () => batchDownload('all', '全部') }, `全部下载(${counts.all})`),
|
|
521
|
+
h('button', { disabled: Boolean(busy) || counts.simp === 0, onClick: () => batchDownload('simp', '简中') }, `简中(${counts.simp})`),
|
|
522
|
+
h('button', { disabled: Boolean(busy) || counts.trad === 0, onClick: () => batchDownload('trad', '繁中') }, `繁中(${counts.trad})`),
|
|
523
|
+
h('button', { disabled: Boolean(busy) || counts.multi === 0, onClick: () => batchDownload('multi', '多字幕') }, `多字幕(${counts.multi})`)),
|
|
351
524
|
browse.loading
|
|
352
525
|
? h('div', { style: muted }, '加载中…')
|
|
353
526
|
: (browse.error
|
|
354
527
|
? h('div', { style: muted }, browse.error)
|
|
355
|
-
: (
|
|
528
|
+
: (items.length === 0
|
|
356
529
|
? h('div', { style: muted }, '这个字幕组还没有上传作品。')
|
|
357
|
-
:
|
|
358
|
-
h('div', { style: {
|
|
359
|
-
h('div', {
|
|
360
|
-
|
|
361
|
-
|
|
530
|
+
: (groupByLang
|
|
531
|
+
? grouped.map((g) => h('div', { key: g.key, style: { marginBottom: 18 } },
|
|
532
|
+
h('div', {
|
|
533
|
+
style: {
|
|
534
|
+
fontWeight: 600, fontSize: 13, marginBottom: 6,
|
|
535
|
+
color: SUB_COLOR[g.key] || 'inherit',
|
|
536
|
+
},
|
|
537
|
+
}, `${g.label}(${g.items.length})`),
|
|
538
|
+
g.items.length === 0
|
|
539
|
+
? h('div', { style: muted }, '—')
|
|
540
|
+
: g.items.map(renderWorkItem)))
|
|
541
|
+
: items.map(renderWorkItem)))),
|
|
542
|
+
items.length > 0 && items.length < (browse.total || 0)
|
|
543
|
+
? h('div', { style: { textAlign: 'center', marginTop: 14 } },
|
|
544
|
+
h('button', { onClick: loadMoreWorks, disabled: Boolean(busy) },
|
|
545
|
+
`显示更多(已显示 ${items.length} / 共 ${browse.total})`))
|
|
546
|
+
: null);
|
|
362
547
|
}
|
|
363
548
|
|
|
364
549
|
return h('div', { style: { padding: '18px 22px', overflow: 'auto', height: '100%' } },
|
|
@@ -366,7 +551,8 @@ window.__ModuleLoader__.load({
|
|
|
366
551
|
h('h2', { style: { margin: 0, fontSize: 20 } }, '追番周历'),
|
|
367
552
|
h('span', { style: muted }, `${total} 部订阅`),
|
|
368
553
|
h('span', { style: { flex: 1 } }),
|
|
369
|
-
h('button', { onClick: () => openSeason(), disabled: Boolean(busy) }, '
|
|
554
|
+
h('button', { onClick: () => openSeason(), disabled: Boolean(busy) }, '当季浏览'),
|
|
555
|
+
h('button', { onClick: () => setDialog({ type: 'season-picker' }), disabled: Boolean(busy) }, '往季浏览'),
|
|
370
556
|
h('button', { onClick: checkUpdates, disabled: Boolean(busy) }, busy === 'check' ? '检查中…' : '检查更新'),
|
|
371
557
|
h('button', { onClick: () => load(), disabled: Boolean(busy) }, '刷新')),
|
|
372
558
|
|
|
@@ -374,15 +560,20 @@ window.__ModuleLoader__.load({
|
|
|
374
560
|
h(Pill, { ok: state.mode === 'proxy' }, state.mode === 'proxy' ? '代理模式' : '直连模式'),
|
|
375
561
|
h('span', { style: muted }, '蜜柑 ' + String(state.mikan || '').replace(/^https?:\/\//, '')),
|
|
376
562
|
h(Pill, { ok: state.bgm }, 'bgm ' + (state.bgm ? '可用' : '不可用')),
|
|
377
|
-
h(Pill, {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
563
|
+
h(Pill, {
|
|
564
|
+
ok: state.downloader?.ok,
|
|
565
|
+
onClick: () => setDialog({ type: 'downloader' }),
|
|
566
|
+
}, state.downloader?.ok
|
|
567
|
+
? `${state.downloader?.type === 'qbittorrent' ? 'qBittorrent' : 'BitComet'} 已连接`
|
|
568
|
+
: 'P2P 下载器 未连接')),
|
|
569
|
+
|
|
570
|
+
state && !state.downloader?.ok ? h('div', {
|
|
571
|
+
onClick: () => setDialog({ type: 'guide', title: '下载器连接指引' }),
|
|
381
572
|
style: {
|
|
382
573
|
...panel, padding: '8px 12px', marginBottom: 12, cursor: 'pointer',
|
|
383
574
|
borderColor: 'var(--dsw-alias-warning, #f08c00)', color: 'var(--dsw-alias-warning, #f08c00)', fontSize: 13,
|
|
384
575
|
},
|
|
385
|
-
}, '⚠
|
|
576
|
+
}, '⚠ P2P 下载器未连接 —— 点击查看配置指引') : null,
|
|
386
577
|
|
|
387
578
|
(() => {
|
|
388
579
|
const count = updateStatus?.count || 0;
|
|
@@ -452,6 +643,23 @@ window.__ModuleLoader__.load({
|
|
|
452
643
|
? h('div', { style: { ...muted, marginTop: 16 } }, '还没有订阅。点「浏览季度」找番剧,或去对话里说「追某某番的某个字幕组」。')
|
|
453
644
|
: h('div', { style: { ...muted, marginTop: 12 } }, '点番剧卡片可查看字幕组与作品;卡片上可「静默」或「取消订阅」。'),
|
|
454
645
|
|
|
646
|
+
dialog && dialog.type === 'season-picker' ? h(Overlay, {
|
|
647
|
+
title: '往季浏览', onClose: () => setDialog(null),
|
|
648
|
+
}, h('div', null,
|
|
649
|
+
h('div', { style: { ...muted, marginBottom: 10 } }, '选一个年份和季节'),
|
|
650
|
+
Array.from({ length: 12 }, (_, i) => new Date().getFullYear() - i).map((y) => h('div', {
|
|
651
|
+
key: y,
|
|
652
|
+
style: { display: 'flex', gap: 8, alignItems: 'center', padding: '7px 0', borderBottom: border },
|
|
653
|
+
},
|
|
654
|
+
h('span', { style: { width: 52, fontWeight: 600, fontSize: 13 } }, String(y)),
|
|
655
|
+
[['冬', '1月'], ['春', '4月'], ['夏', '7月'], ['秋', '10月']].map(([s, m]) => h('button', {
|
|
656
|
+
key: s,
|
|
657
|
+
style: { minWidth: 72 },
|
|
658
|
+
onClick: () => openSeason(y, s),
|
|
659
|
+
}, `${s}(${m})`)),
|
|
660
|
+
)),
|
|
661
|
+
)) : null,
|
|
662
|
+
|
|
455
663
|
dialog && dialog.type === 'browse' && browse ? h(Overlay, {
|
|
456
664
|
title: breadcrumb,
|
|
457
665
|
onClose: () => { setDialog(null); setBrowse(null); },
|
|
@@ -488,32 +696,117 @@ window.__ModuleLoader__.load({
|
|
|
488
696
|
h('div', { style: muted }, `${e.size}`)),
|
|
489
697
|
h('button', { onClick: () => download(e.hash, `${u.title} 第${e.episode}集`) }, '下载'))))))) : null,
|
|
490
698
|
|
|
699
|
+
dialog && dialog.type === 'batch' && batchTarget ? h(Overlay, {
|
|
700
|
+
title: `批量下载 · ${batchTarget.title} / ${batchTarget.subgroupName}`, onClose: () => setDialog(null),
|
|
701
|
+
}, h('div', null,
|
|
702
|
+
batchStats
|
|
703
|
+
? h('div', null,
|
|
704
|
+
h('div', { style: { ...muted, marginBottom: 12 } },
|
|
705
|
+
`共 ${batchStats.all} 个作品 · 简中 ${batchStats.simp} · 繁中 ${batchStats.trad} · 多字幕 ${batchStats.multi}`),
|
|
706
|
+
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
707
|
+
h('button', {
|
|
708
|
+
disabled: Boolean(busy) || batchStats.all === 0,
|
|
709
|
+
onClick: () => runBatch('all', '全部'),
|
|
710
|
+
}, `全部下载(${batchStats.all})`),
|
|
711
|
+
h('button', {
|
|
712
|
+
disabled: Boolean(busy) || batchStats.simp === 0,
|
|
713
|
+
onClick: () => runBatch('simp', '简中'),
|
|
714
|
+
}, `简中(${batchStats.simp})`),
|
|
715
|
+
h('button', {
|
|
716
|
+
disabled: Boolean(busy) || batchStats.trad === 0,
|
|
717
|
+
onClick: () => runBatch('trad', '繁中'),
|
|
718
|
+
}, `繁中(${batchStats.trad})`),
|
|
719
|
+
h('button', {
|
|
720
|
+
disabled: Boolean(busy) || batchStats.multi === 0,
|
|
721
|
+
onClick: () => runBatch('multi', '多字幕'),
|
|
722
|
+
}, `多字幕(${batchStats.multi})`)))
|
|
723
|
+
: h('div', { style: muted }, '加载作品中…'),
|
|
724
|
+
h('div', { style: { ...muted, marginTop: 12 } }, '没有对应语言的作品会置灰。'))) : null,
|
|
725
|
+
|
|
726
|
+
dialog && dialog.type === 'downloader' ? (() => {
|
|
727
|
+
const dl = state?.downloader || {};
|
|
728
|
+
const typeLabel = dl.type === 'qbittorrent' ? 'qBittorrent' : 'BitComet';
|
|
729
|
+
let currentPort = '';
|
|
730
|
+
try { currentPort = new URL(dl.base || '').port; } catch { /* unknown */ }
|
|
731
|
+
return h(Overlay, {
|
|
732
|
+
title: 'P2P 下载器', onClose: () => setDialog(null),
|
|
733
|
+
}, h('div', null,
|
|
734
|
+
h('div', { style: { marginBottom: 12, fontSize: 13 } },
|
|
735
|
+
dl.ok ? `当前:${typeLabel} 已连接 · 端口 ${currentPort || '?????'}` : '当前:P2P 下载器 未连接'),
|
|
736
|
+
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', marginBottom: 14 } },
|
|
737
|
+
h('button', { onClick: runScan, disabled: Boolean(busy) }, busy === 'scan' ? '检测中…' : '自动检测'),
|
|
738
|
+
h('button', {
|
|
739
|
+
onClick: () => switchTo('qbittorrent'),
|
|
740
|
+
disabled: Boolean(busy) || dl.type === 'qbittorrent',
|
|
741
|
+
}, '使用 qBittorrent'),
|
|
742
|
+
h('button', {
|
|
743
|
+
onClick: () => switchTo('bitcomet'),
|
|
744
|
+
disabled: Boolean(busy) || dl.type === 'bitcomet',
|
|
745
|
+
}, '使用 BitComet')),
|
|
746
|
+
scanResult
|
|
747
|
+
? h('div', null,
|
|
748
|
+
h('div', { style: { ...muted, marginBottom: 6 } }, '上次扫描结果:'),
|
|
749
|
+
(scanResult.tried || []).map((t, i) => h('div', { key: i, style: row },
|
|
750
|
+
h('span', { style: { flex: 1, fontSize: 13 } },
|
|
751
|
+
`${t.type === 'qbittorrent' ? 'qBittorrent' : 'BitComet'} · 端口 ${t.port}`),
|
|
752
|
+
h('span', {
|
|
753
|
+
style: {
|
|
754
|
+
fontSize: 12,
|
|
755
|
+
color: t.ok ? 'var(--dsw-alias-success, #2f9e44)' : 'var(--dsw-alias-danger, #e03131)',
|
|
756
|
+
},
|
|
757
|
+
}, t.ok ? '✓ 已连接' : `✗ ${t.reason || '未连接'}`))))
|
|
758
|
+
: h('div', { style: muted }, '点「自动检测」查看各端口的连接状态'),
|
|
759
|
+
h('div', { style: { ...muted, marginTop: 12 } }, '切换会写入插件配置,并立即重新检测。'),
|
|
760
|
+
));
|
|
761
|
+
})() : null,
|
|
762
|
+
|
|
491
763
|
dialog && dialog.type === 'guide' ? h(Overlay, {
|
|
492
|
-
title: '
|
|
764
|
+
title: '下载器连接指引', onClose: () => setDialog(null),
|
|
493
765
|
}, h('div', null,
|
|
494
|
-
h('
|
|
495
|
-
|
|
496
|
-
|
|
766
|
+
h('div', { style: { ...muted, marginBottom: 12 } },
|
|
767
|
+
'任选一个 P2P 下载器开启 Web 接口,然后在插件配置里用 downloader 指定它。'),
|
|
768
|
+
|
|
769
|
+
h('div', { style: { fontWeight: 600, fontSize: 13, marginBottom: 6 } }, 'qBittorrent(端口默认 8080)'),
|
|
770
|
+
h('ol', { style: { paddingLeft: 20, lineHeight: 1.9, fontSize: 13, margin: 0 } },
|
|
771
|
+
h('li', null, '工具 → 选项 → Web UI'),
|
|
772
|
+
h('li', null, '勾选「启用 Web 用户界面」'),
|
|
773
|
+
h('li', null, '端口默认 8080,可改(记下实际值)'),
|
|
774
|
+
h('li', null, '设置「用户名 / 密码」;只在本机使用可勾「对本地主机跳过身份验证」'),
|
|
775
|
+
h('li', null, '点击「应用」保存')),
|
|
776
|
+
|
|
777
|
+
h('div', { style: { fontWeight: 600, fontSize: 13, margin: '16px 0 6px' } }, 'BitComet(监听端口自定,例如 10816)'),
|
|
778
|
+
h('ol', { style: { paddingLeft: 20, lineHeight: 1.9, fontSize: 13, margin: 0 } },
|
|
779
|
+
h('li', null, '选项 → 远程访问'),
|
|
780
|
+
h('li', null, '「监听端口」填固定值(不要用 0 或随机端口)'),
|
|
497
781
|
h('li', null, '勾选「启用网页版远程访问」'),
|
|
498
782
|
h('li', null, '不要勾「始终使用 HTTPS」'),
|
|
499
783
|
h('li', null, '设置「用户名 / 密码」——插件会自动从 BitComet 配置文件读取'),
|
|
500
784
|
h('li', null, '不要勾「执行远程访问操作时显示提示窗口」'),
|
|
501
|
-
h('li', null, '点击「应用」保存'),
|
|
502
|
-
|
|
503
|
-
h('div', { style: { ...muted, marginTop: 14 } },
|
|
785
|
+
h('li', null, '点击「应用」保存')),
|
|
786
|
+
|
|
787
|
+
h('div', { style: { ...muted, marginTop: 14, lineHeight: 1.8 } },
|
|
788
|
+
'插件不会自己启动或关闭下载器,请保持它运行。',
|
|
789
|
+
h('br'),
|
|
790
|
+
'配置项:downloader 填 qbittorrent 或 bitcomet,并把对应的 base 字段填成上面的地址。'),
|
|
791
|
+
|
|
504
792
|
h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 8, marginTop: 18 } },
|
|
505
793
|
h('button', { onClick: () => setDialog(null) }, '关闭'),
|
|
506
794
|
h('button', {
|
|
507
795
|
onClick: async () => {
|
|
508
796
|
setBusy('scan');
|
|
509
797
|
try {
|
|
510
|
-
const r = await postJson('/
|
|
511
|
-
|
|
798
|
+
const r = await postJson('/downloader-scan');
|
|
799
|
+
const label = r.type === 'qbittorrent' ? 'qBittorrent' : 'BitComet';
|
|
800
|
+
if (r.ok) {
|
|
801
|
+
setNotice(r.switched ? `已切换并连接 ${label}:端口 ${r.port}` : `已连接 ${label}:端口 ${r.port}`);
|
|
802
|
+
} else {
|
|
803
|
+
setNotice(r.reason);
|
|
804
|
+
}
|
|
512
805
|
await load();
|
|
513
|
-
} catch (e) { setNotice('
|
|
806
|
+
} catch (e) { setNotice('检测失败:' + e.message); } finally { setBusy(''); }
|
|
514
807
|
setDialog(null);
|
|
515
808
|
},
|
|
516
|
-
}, busy === 'scan' ? '
|
|
809
|
+
}, busy === 'scan' ? '检测中…' : '自动检测'),
|
|
517
810
|
h('button', {
|
|
518
811
|
onClick: async () => { setBusy('probe'); try { await load(); } finally { setBusy(''); setDialog(null); } },
|
|
519
812
|
}, busy === 'probe' ? '检测中…' : '重新检测')))) : null,
|
package/index.js
CHANGED
|
@@ -20,11 +20,13 @@ import {
|
|
|
20
20
|
parseRss,
|
|
21
21
|
parseSeasonFlow,
|
|
22
22
|
parseBangumiPage,
|
|
23
|
+
parseBangumiWorks,
|
|
23
24
|
parseSearchPage,
|
|
24
25
|
magnetFromHash,
|
|
25
26
|
hashFromLink,
|
|
26
27
|
} from './lib/mikan.js';
|
|
27
28
|
import { createBitCometClient } from './lib/bitcomet.js';
|
|
29
|
+
import { createQbittorrentClient } from './lib/qbittorrent.js';
|
|
28
30
|
import { resolveAirDate } from './lib/airdate.js';
|
|
29
31
|
import * as store from './lib/store.js';
|
|
30
32
|
import { probeProxy, parseProxy, probePort } from './lib/net.js';
|
|
@@ -184,7 +186,39 @@ export async function apply(ctx) {
|
|
|
184
186
|
});
|
|
185
187
|
}
|
|
186
188
|
|
|
187
|
-
/**
|
|
189
|
+
/** Resolve the configured downloader: BitComet or qBittorrent. */
|
|
190
|
+
async function downloaderClient() {
|
|
191
|
+
const cfg = await loadConfig();
|
|
192
|
+
if (String(cfg.downloader || 'bitcomet').toLowerCase() === 'qbittorrent') {
|
|
193
|
+
return createQbittorrentClient({
|
|
194
|
+
base: cfg.qbittorrentBase || 'http://127.0.0.1:8080',
|
|
195
|
+
user: cfg.qbittorrentUser || '',
|
|
196
|
+
password: cfg.qbittorrentPassword || '',
|
|
197
|
+
proxy: '',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return bitcometClient();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Human-readable downloader descriptor for status responses. */
|
|
204
|
+
async function downloaderInfo() {
|
|
205
|
+
const cfg = await loadConfig();
|
|
206
|
+
const type = String(cfg.downloader || 'bitcomet').toLowerCase();
|
|
207
|
+
let client;
|
|
208
|
+
try {
|
|
209
|
+
client = await downloaderClient();
|
|
210
|
+
const auth = await client.checkAuth();
|
|
211
|
+
return {
|
|
212
|
+
type,
|
|
213
|
+
base: type === 'qbittorrent' ? (cfg.qbittorrentBase || 'http://127.0.0.1:8080') : cfg.bitcometBase,
|
|
214
|
+
ok: auth.ok,
|
|
215
|
+
version: auth.version || '',
|
|
216
|
+
reason: auth.reason || '',
|
|
217
|
+
};
|
|
218
|
+
} catch (err) {
|
|
219
|
+
return { type, ok: false, reason: err.message };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
188
222
|
async function checkAll() {
|
|
189
223
|
await detectEnv();
|
|
190
224
|
const cfg = await loadConfig();
|
|
@@ -289,18 +323,38 @@ export async function apply(ctx) {
|
|
|
289
323
|
}
|
|
290
324
|
|
|
291
325
|
/** Level 3: one subgroup's releases for a bangumi; hashes only, no magnets. */
|
|
292
|
-
async function works(bangumiId, subgroupId = '') {
|
|
326
|
+
async function works(bangumiId, subgroupId = '', limit = 30) {
|
|
293
327
|
await detectEnv();
|
|
294
328
|
const cfg = await loadConfig();
|
|
295
|
-
|
|
296
|
-
|
|
329
|
+
let items;
|
|
330
|
+
if (subgroupId) {
|
|
331
|
+
// /Home/ExpandEpisodeTable returns the subgroup's complete table; RSS
|
|
332
|
+
// stops at 100 entries, which truncates long-running shows.
|
|
333
|
+
const html = await mikanClient(cfg).get(
|
|
334
|
+
`/Home/ExpandEpisodeTable?bangumiId=${encodeURIComponent(bangumiId)}&subtitleGroupId=${encodeURIComponent(subgroupId)}&take=1000`,
|
|
335
|
+
);
|
|
336
|
+
items = parseBangumiWorks(html);
|
|
337
|
+
} else {
|
|
338
|
+
const q = `/RSS/Bangumi?bangumiId=${encodeURIComponent(bangumiId)}`;
|
|
339
|
+
items = parseRss(await mikanClient(cfg).get(q));
|
|
340
|
+
}
|
|
341
|
+
const cap = Math.max(1, Math.min(Number(limit) || 30, 500));
|
|
342
|
+
const bucket = (v) => items.filter((r) => (r.subtitle || 'multi') === v).length;
|
|
297
343
|
return {
|
|
298
344
|
total: items.length,
|
|
299
|
-
|
|
345
|
+
displayed: Math.min(items.length, cap),
|
|
346
|
+
counts: {
|
|
347
|
+
all: items.length,
|
|
348
|
+
simp: bucket('simp'),
|
|
349
|
+
trad: bucket('trad'),
|
|
350
|
+
multi: bucket('multi'),
|
|
351
|
+
},
|
|
352
|
+
items: items.slice(0, cap).map((r) => ({
|
|
300
353
|
title: r.title,
|
|
301
354
|
episode: r.episode,
|
|
302
|
-
size:
|
|
355
|
+
size: r.size || '',
|
|
303
356
|
hash: r.hash,
|
|
357
|
+
subtitle: r.subtitle || 'multi',
|
|
304
358
|
})),
|
|
305
359
|
};
|
|
306
360
|
}
|
|
@@ -341,7 +395,7 @@ export async function apply(ctx) {
|
|
|
341
395
|
|
|
342
396
|
ctx.tools.register(defineTool({
|
|
343
397
|
name: 'mikan_status',
|
|
344
|
-
description: 'Report the current Mikan environment: proxy reachability, chosen mirror domain, air-date fallback availability, and
|
|
398
|
+
description: 'Report the current Mikan environment: proxy reachability, chosen mirror domain, air-date fallback availability, and P2P downloader connection state.',
|
|
345
399
|
parameters: {
|
|
346
400
|
type: 'object',
|
|
347
401
|
properties: {
|
|
@@ -353,19 +407,13 @@ export async function apply(ctx) {
|
|
|
353
407
|
async execute(args) {
|
|
354
408
|
const e = await detectEnv(Boolean(args?.refresh));
|
|
355
409
|
const cfg = await loadConfig();
|
|
356
|
-
const
|
|
357
|
-
let bc = { ok: false, reason: 'not-checked' };
|
|
358
|
-
try {
|
|
359
|
-
bc = await (await bitcometClient()).checkAuth();
|
|
360
|
-
} catch (err) {
|
|
361
|
-
bc = { ok: false, reason: err.message };
|
|
362
|
-
}
|
|
410
|
+
const dl = await downloaderInfo();
|
|
363
411
|
return {
|
|
364
412
|
mode: e.mode,
|
|
365
413
|
proxy: e.proxy || '(none)',
|
|
366
414
|
bgm: { ok: e.bgmOk, reason: e.bgmReason },
|
|
367
415
|
mikan: { base: e.mikanBase, viaProxy: e.mikanViaProxy, reason: e.mikanReason },
|
|
368
|
-
|
|
416
|
+
downloader: dl,
|
|
369
417
|
savePath: cfg.savePath,
|
|
370
418
|
checkIntervalMinutes: cfg.checkIntervalMinutes,
|
|
371
419
|
};
|
|
@@ -374,13 +422,17 @@ export async function apply(ctx) {
|
|
|
374
422
|
|
|
375
423
|
ctx.tools.register(defineTool({
|
|
376
424
|
name: 'mikan_config',
|
|
377
|
-
description: 'Read or update plugin settings (proxy,
|
|
425
|
+
description: 'Read or update plugin settings (downloader, proxy, base URLs, save path, check interval). Changes apply on the next request.',
|
|
378
426
|
parameters: {
|
|
379
427
|
type: 'object',
|
|
380
428
|
properties: {
|
|
429
|
+
downloader: { type: 'string', enum: ['bitcomet', 'qbittorrent'], description: 'Which downloader backend to use.' },
|
|
381
430
|
proxy: { type: 'string', description: 'Local proxy, e.g. http://127.0.0.1:7890. Empty string means direct.' },
|
|
382
431
|
bitcometBase: { type: 'string', description: 'BitComet WebUI base URL.' },
|
|
383
|
-
|
|
432
|
+
qbittorrentBase: { type: 'string', description: 'qBittorrent WebUI base URL.' },
|
|
433
|
+
qbittorrentUser: { type: 'string', description: 'qBittorrent username.' },
|
|
434
|
+
qbittorrentPassword: { type: 'string', description: 'qBittorrent password.' },
|
|
435
|
+
savePath: { type: 'string', description: 'Default download directory inside the downloader.' },
|
|
384
436
|
checkIntervalMinutes: { type: 'number', description: 'Background check interval in minutes.' },
|
|
385
437
|
},
|
|
386
438
|
additionalProperties: false,
|
|
@@ -388,7 +440,7 @@ export async function apply(ctx) {
|
|
|
388
440
|
output: { schema: OBJ, render: renderJson },
|
|
389
441
|
async execute(args) {
|
|
390
442
|
const patch = {};
|
|
391
|
-
for (const key of ['proxy', 'bitcometBase', 'savePath', 'checkIntervalMinutes']) {
|
|
443
|
+
for (const key of ['downloader', 'proxy', 'bitcometBase', 'qbittorrentBase', 'qbittorrentUser', 'qbittorrentPassword', 'savePath', 'checkIntervalMinutes']) {
|
|
392
444
|
if (args?.[key] !== undefined) patch[key] = args[key];
|
|
393
445
|
}
|
|
394
446
|
if (Object.keys(patch).length === 0) return { config: await loadConfig(), changed: false };
|
|
@@ -491,7 +543,7 @@ export async function apply(ctx) {
|
|
|
491
543
|
|
|
492
544
|
ctx.tools.register(defineTool({
|
|
493
545
|
name: 'mikan_download',
|
|
494
|
-
description: 'Send releases to
|
|
546
|
+
description: 'Send releases to the configured P2P downloader by 40-character info hash (full magnet URIs are also accepted). The downloader reports unreliable status, so the task list is verified afterwards.',
|
|
495
547
|
parameters: {
|
|
496
548
|
type: 'object',
|
|
497
549
|
properties: {
|
|
@@ -508,9 +560,9 @@ export async function apply(ctx) {
|
|
|
508
560
|
output: { schema: OBJ, render: renderJson },
|
|
509
561
|
async execute(args) {
|
|
510
562
|
const cfg = await loadConfig();
|
|
511
|
-
const client = await
|
|
563
|
+
const client = await downloaderClient();
|
|
512
564
|
const auth = await client.checkAuth();
|
|
513
|
-
if (!auth.ok) return { ok: false, reason:
|
|
565
|
+
if (!auth.ok) return { ok: false, reason: `下载器未就绪(${cfg.downloader || 'bitcomet'}):${auth.reason}` };
|
|
514
566
|
const savePath = args.savePath || cfg.savePath;
|
|
515
567
|
if (!savePath) return { ok: false, reason: '未配置下载目录(savePath),请先用 mikan_config 设置' };
|
|
516
568
|
const results = [];
|
|
@@ -579,16 +631,14 @@ export async function apply(ctx) {
|
|
|
579
631
|
if (route === '/state' && req.method === 'GET') {
|
|
580
632
|
const e = await detectEnv();
|
|
581
633
|
const cfg = await loadConfig();
|
|
582
|
-
const
|
|
583
|
-
let bc = { ok: false, reason: 'not-checked' };
|
|
584
|
-
try { bc = await (await bitcometClient()).checkAuth(); } catch (err) { bc = { ok: false, reason: err.message }; }
|
|
634
|
+
const dl = await downloaderInfo();
|
|
585
635
|
return send(res, 200, {
|
|
586
636
|
mode: e.mode,
|
|
587
637
|
proxy: e.proxy,
|
|
588
638
|
bgm: e.bgmOk,
|
|
589
639
|
mikan: e.mikanBase,
|
|
590
640
|
mikanViaProxy: e.mikanViaProxy,
|
|
591
|
-
|
|
641
|
+
downloader: dl,
|
|
592
642
|
savePath: cfg.savePath,
|
|
593
643
|
checkIntervalMinutes: cfg.checkIntervalMinutes,
|
|
594
644
|
lastCheckAt: await store.getLastCheck(),
|
|
@@ -626,7 +676,7 @@ export async function apply(ctx) {
|
|
|
626
676
|
if (!cfg.savePath) {
|
|
627
677
|
return send(res, 200, { ok: false, reason: '未配置下载目录(savePath),请先在插件配置中设置' });
|
|
628
678
|
}
|
|
629
|
-
const client = await
|
|
679
|
+
const client = await downloaderClient();
|
|
630
680
|
const auth = await client.checkAuth();
|
|
631
681
|
if (!auth.ok) return send(res, 200, { ok: false, reason: `BitComet 未就绪:${auth.reason}` });
|
|
632
682
|
const results = [];
|
|
@@ -658,33 +708,71 @@ export async function apply(ctx) {
|
|
|
658
708
|
await store.setLastUpdates([]);
|
|
659
709
|
return send(res, 200, { ok: true });
|
|
660
710
|
}
|
|
661
|
-
if (route === '/
|
|
662
|
-
const creds = await loadBitCometCreds();
|
|
711
|
+
if (route === '/downloader-scan' && req.method === 'POST') {
|
|
663
712
|
const cfg = await loadConfig();
|
|
664
|
-
const
|
|
665
|
-
const password = cfg.bitcometPassword || creds.password;
|
|
666
|
-
const candidates = [];
|
|
667
|
-
if (creds.port) candidates.push(creds.port);
|
|
668
|
-
for (const port of [10816, 19135, 19136, 8080, 8081, 9999, 1235, 5000, 8888]) {
|
|
669
|
-
if (!candidates.includes(port)) candidates.push(port);
|
|
670
|
-
}
|
|
713
|
+
const current = String(cfg.downloader || 'bitcomet').toLowerCase();
|
|
671
714
|
const tried = [];
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
715
|
+
// Try the configured backend first, then the other one.
|
|
716
|
+
const order = current === 'qbittorrent' ? ['qbittorrent', 'bitcomet'] : ['bitcomet', 'qbittorrent'];
|
|
717
|
+
|
|
718
|
+
const probeQb = async () => {
|
|
719
|
+
const ports = [8080];
|
|
675
720
|
try {
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
} catch
|
|
679
|
-
|
|
721
|
+
const cur = new URL(cfg.qbittorrentBase || 'http://127.0.0.1:8080');
|
|
722
|
+
if (cur.port) ports.unshift(Number(cur.port));
|
|
723
|
+
} catch { /* keep default */ }
|
|
724
|
+
for (const port of [...new Set(ports)]) {
|
|
725
|
+
const base = `http://127.0.0.1:${port}`;
|
|
726
|
+
const r = await createQbittorrentClient({
|
|
727
|
+
base,
|
|
728
|
+
user: cfg.qbittorrentUser || '',
|
|
729
|
+
password: cfg.qbittorrentPassword || '',
|
|
730
|
+
proxy: '',
|
|
731
|
+
}).checkAuth();
|
|
732
|
+
tried.push({ type: 'qbittorrent', port, ok: r.ok, reason: r.reason || '' });
|
|
733
|
+
if (r.ok) return { type: 'qbittorrent', port, base };
|
|
734
|
+
}
|
|
735
|
+
return null;
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
const probeBc = async () => {
|
|
739
|
+
const creds = await loadBitCometCreds();
|
|
740
|
+
const user = cfg.bitcometUser || creds.user;
|
|
741
|
+
const password = cfg.bitcometPassword || creds.password;
|
|
742
|
+
const candidates = [];
|
|
743
|
+
if (creds.port) candidates.push(creds.port);
|
|
744
|
+
for (const port of [10816, 19135, 19136, 8080, 8081, 9999, 1235, 5000, 8888]) {
|
|
745
|
+
if (!candidates.includes(port)) candidates.push(port);
|
|
746
|
+
}
|
|
747
|
+
for (const port of candidates) {
|
|
748
|
+
const base = `http://127.0.0.1:${port}`;
|
|
749
|
+
let r = { ok: false, reason: '' };
|
|
750
|
+
try {
|
|
751
|
+
r = await createBitCometClient({ base, user, password, proxy: '' }).checkAuth();
|
|
752
|
+
} catch (err) {
|
|
753
|
+
r = { ok: false, reason: err.message };
|
|
754
|
+
}
|
|
755
|
+
tried.push({ type: 'bitcomet', port, ok: r.ok, reason: r.reason || '' });
|
|
756
|
+
if (r.ok) return { type: 'bitcomet', port, base };
|
|
680
757
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
758
|
+
return null;
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
for (const type of order) {
|
|
762
|
+
const hit = type === 'qbittorrent' ? await probeQb() : await probeBc();
|
|
763
|
+
if (hit) {
|
|
764
|
+
const patch = { downloader: hit.type };
|
|
765
|
+
if (hit.type === 'qbittorrent') patch.qbittorrentBase = hit.base;
|
|
766
|
+
else patch.bitcometBase = hit.base;
|
|
767
|
+
await saveConfig(patch);
|
|
768
|
+
return send(res, 200, { ok: true, ...hit, switched: hit.type !== current, tried });
|
|
685
769
|
}
|
|
686
770
|
}
|
|
687
|
-
return send(res, 200, {
|
|
771
|
+
return send(res, 200, {
|
|
772
|
+
ok: false,
|
|
773
|
+
reason: '未找到可用的 P2P 下载器(qBittorrent 和 BitComet 都试过了)',
|
|
774
|
+
tried,
|
|
775
|
+
});
|
|
688
776
|
}
|
|
689
777
|
if (route === '/preview' && req.method === 'GET') {
|
|
690
778
|
const year = Number(u.searchParams.get('year')) || new Date().getFullYear();
|
|
@@ -770,22 +858,10 @@ export async function apply(ctx) {
|
|
|
770
858
|
if (route === '/works' && req.method === 'GET') {
|
|
771
859
|
const bangumiId = u.searchParams.get('bangumiId') || '';
|
|
772
860
|
const subgroupId = u.searchParams.get('subgroupId') || '';
|
|
861
|
+
const subgroupName = u.searchParams.get('subgroupName') || '';
|
|
862
|
+
const limit = u.searchParams.get('limit') || '60';
|
|
773
863
|
if (!bangumiId) return send(res, 400, { ok: false, reason: 'bangumiId is required' });
|
|
774
|
-
await
|
|
775
|
-
const cfg = await loadConfig();
|
|
776
|
-
const q = `/RSS/Bangumi?bangumiId=${encodeURIComponent(bangumiId)}${subgroupId ? `&subgroupid=${encodeURIComponent(subgroupId)}` : ''}`;
|
|
777
|
-
const items = parseRss(await mikanClient(cfg).get(q));
|
|
778
|
-
return send(res, 200, {
|
|
779
|
-
bangumiId,
|
|
780
|
-
subgroupId,
|
|
781
|
-
total: items.length,
|
|
782
|
-
items: items.slice(0, 60).map((r) => ({
|
|
783
|
-
title: r.title,
|
|
784
|
-
episode: r.episode,
|
|
785
|
-
size: fmtSize(r.size),
|
|
786
|
-
hash: r.hash,
|
|
787
|
-
})),
|
|
788
|
-
});
|
|
864
|
+
return send(res, 200, await works(bangumiId, subgroupId, limit));
|
|
789
865
|
}
|
|
790
866
|
if (route === '/subscribe-group' && req.method === 'POST') {
|
|
791
867
|
const body = await readBody(req);
|
|
@@ -871,6 +947,20 @@ export async function apply(ctx) {
|
|
|
871
947
|
}
|
|
872
948
|
return send(res, 200, { ok: false, reason: '未找到可用代理,已保持直连模式', tried });
|
|
873
949
|
}
|
|
950
|
+
if (route === '/config' && req.method === 'POST') {
|
|
951
|
+
const body = await readBody(req);
|
|
952
|
+
const allowed = ['downloader', 'proxy', 'bitcometBase', 'qbittorrentBase', 'qbittorrentUser', 'qbittorrentPassword', 'savePath', 'checkIntervalMinutes'];
|
|
953
|
+
const patch = {};
|
|
954
|
+
for (const key of allowed) {
|
|
955
|
+
if (body[key] !== undefined) patch[key] = body[key];
|
|
956
|
+
}
|
|
957
|
+
if (Object.keys(patch).length === 0) {
|
|
958
|
+
return send(res, 400, { ok: false, reason: '没有可更新的字段' });
|
|
959
|
+
}
|
|
960
|
+
const next = await saveConfig(patch);
|
|
961
|
+
env = null;
|
|
962
|
+
return send(res, 200, { ok: true, config: next });
|
|
963
|
+
}
|
|
874
964
|
if (route === '/disconnect' && req.method === 'POST') {
|
|
875
965
|
await saveConfig({ proxy: '' });
|
|
876
966
|
env = null;
|
package/lib/constants.js
CHANGED
|
@@ -25,6 +25,8 @@ export const DOW_LABELS = {
|
|
|
25
25
|
|
|
26
26
|
/** Default plugin configuration. */
|
|
27
27
|
export const DEFAULT_CONFIG = {
|
|
28
|
+
/** Downloader backend: 'bitcomet' or 'qbittorrent'. */
|
|
29
|
+
downloader: 'bitcomet',
|
|
28
30
|
/** Empty string = direct connection. */
|
|
29
31
|
proxy: '',
|
|
30
32
|
/** BitComet WebUI base URL. */
|
|
@@ -32,7 +34,11 @@ export const DEFAULT_CONFIG = {
|
|
|
32
34
|
/** BitComet WebUI credentials; read from BitComet.xml when empty. */
|
|
33
35
|
bitcometUser: '',
|
|
34
36
|
bitcometPassword: '',
|
|
35
|
-
/**
|
|
37
|
+
/** qBittorrent WebUI. */
|
|
38
|
+
qbittorrentBase: 'http://127.0.0.1:8080',
|
|
39
|
+
qbittorrentUser: '',
|
|
40
|
+
qbittorrentPassword: '',
|
|
41
|
+
/** Download directory inside the downloader; must be set before downloading. */
|
|
36
42
|
savePath: '',
|
|
37
43
|
/** Minutes between automatic update checks. */
|
|
38
44
|
checkIntervalMinutes: 30,
|
package/lib/mikan.js
CHANGED
|
@@ -120,7 +120,61 @@ export function parseRss(xml) {
|
|
|
120
120
|
return items;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Classify a release's subtitle language into three buckets.
|
|
125
|
+
*
|
|
126
|
+
* - `trad`: traditional Chinese only (繁 / CHT / BIG5 / 繁日)
|
|
127
|
+
* - `simp`: simplified Chinese only (简 / CHS / GB / 简日)
|
|
128
|
+
* - `multi`: both scripts in one release, or multi-language / raw (简繁, 多语, 生肉, unmarked)
|
|
129
|
+
*
|
|
130
|
+
* `繁日` counts as trad and `简日` as simp; only a release carrying both
|
|
131
|
+
* scripts is promoted to `multi`.
|
|
132
|
+
*/
|
|
133
|
+
export function detectSubtitleTag(title) {
|
|
134
|
+
const t = String(title || '');
|
|
135
|
+
const hasSimp = /简|簡|CHS|GBK?/i.test(t);
|
|
136
|
+
const hasTrad = /繁|CHT|BIG5/i.test(t);
|
|
137
|
+
if (hasSimp && hasTrad) return 'multi';
|
|
138
|
+
if (hasSimp) return 'simp';
|
|
139
|
+
if (hasTrad) return 'trad';
|
|
140
|
+
return 'multi';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Parse the full release table on a bangumi page (`/Home/Bangumi/<id>`).
|
|
145
|
+
*
|
|
146
|
+
* The RSS endpoint caps at 100 entries per subgroup, so long-running shows
|
|
147
|
+
* lose their older episodes there. The bangumi page carries the complete
|
|
148
|
+
* list; each row's first bracket segment is the publishing subgroup.
|
|
149
|
+
*/
|
|
150
|
+
export function parseBangumiWorks(html) {
|
|
151
|
+
const items = [];
|
|
152
|
+
const seen = new Set();
|
|
153
|
+
for (const m of html.matchAll(/<tr>([\s\S]*?)<\/tr>/g)) {
|
|
154
|
+
const row = m[1];
|
|
155
|
+
const ep = row.match(/<a[^>]*class="magnet-link-wrap"[^>]*href="\/Home\/Episode\/([0-9a-fA-F]{40})"[^>]*>([\s\S]*?)<\/a>/);
|
|
156
|
+
if (!ep) continue;
|
|
157
|
+
const hash = ep[1].toLowerCase();
|
|
158
|
+
if (seen.has(hash)) continue;
|
|
159
|
+
seen.add(hash);
|
|
160
|
+
const title = textOf(ep[2]);
|
|
161
|
+
if (!title) continue;
|
|
162
|
+
const sg = title.match(/^\s*[\[【]([^\]】]{1,40})[\]】]/);
|
|
163
|
+
const parsed = parseReleaseTitle(title);
|
|
164
|
+
const sizeMatch = row.match(/<td>\s*(\d+(?:\.\d+)?\s*[MG]B)\s*<\/td>/);
|
|
165
|
+
items.push({
|
|
166
|
+
hash,
|
|
167
|
+
title,
|
|
168
|
+
subgroup: sg ? sg[1].trim() : parsed.subgroup,
|
|
169
|
+
episode: parsed.episode,
|
|
170
|
+
subtitle: parsed.subtitle,
|
|
171
|
+
size: sizeMatch ? sizeMatch[1] : '',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return items;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Pull subgroup, series, episode number and subtitle bucket out of a release title. */
|
|
124
178
|
export function parseReleaseTitle(rawTitle) {
|
|
125
179
|
const title = String(rawTitle || '').trim();
|
|
126
180
|
let subgroup = '';
|
|
@@ -147,7 +201,7 @@ export function parseReleaseTitle(rawTitle) {
|
|
|
147
201
|
const cut = series.search(/\s*[-–—]\s*\d|\[[^\]]*\d{1,3}[^\]]*\]|第\s*\d+\s*[话話集]|S\d{1,2}E\d/i);
|
|
148
202
|
if (cut > 0) series = series.slice(0, cut);
|
|
149
203
|
series = series.replace(/[\[\]【】]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
150
|
-
return { subgroup, series, episode };
|
|
204
|
+
return { subgroup, series, episode, subtitle: detectSubtitleTag(title) };
|
|
151
205
|
}
|
|
152
206
|
|
|
153
207
|
/**
|
package/lib/net.js
CHANGED
|
@@ -176,12 +176,20 @@ function requestDirect(url, opts) {
|
|
|
176
176
|
return new Promise((resolve, reject) => {
|
|
177
177
|
const u = new URL(url);
|
|
178
178
|
const mod = u.protocol === 'https:' ? https : http;
|
|
179
|
+
const bodyBuf = opts.body === undefined ? null : Buffer.from(String(opts.body), 'utf8');
|
|
180
|
+
const headers = {
|
|
181
|
+
'User-Agent': 'dsh-mikan/0.1',
|
|
182
|
+
'Accept-Encoding': 'identity',
|
|
183
|
+
...(opts.headers || {}),
|
|
184
|
+
};
|
|
185
|
+
// qBittorrent rejects chunked multipart bodies, so always declare the length.
|
|
186
|
+
if (bodyBuf && headers['content-length'] === undefined) headers['content-length'] = bodyBuf.length;
|
|
179
187
|
const req = mod.request({
|
|
180
188
|
host: u.hostname,
|
|
181
189
|
port: u.port || (u.protocol === 'https:' ? 443 : 80),
|
|
182
190
|
path: u.pathname + u.search,
|
|
183
191
|
method: opts.method || 'GET',
|
|
184
|
-
headers
|
|
192
|
+
headers,
|
|
185
193
|
timeout: opts.timeout || 20000,
|
|
186
194
|
}, (res) => {
|
|
187
195
|
const chunks = [];
|
|
@@ -199,7 +207,7 @@ function requestDirect(url, opts) {
|
|
|
199
207
|
});
|
|
200
208
|
req.on('timeout', () => { req.destroy(); reject(new Error(`request timeout ${url}`)); });
|
|
201
209
|
req.on('error', reject);
|
|
202
|
-
if (
|
|
210
|
+
if (bodyBuf) req.write(bodyBuf);
|
|
203
211
|
req.end();
|
|
204
212
|
});
|
|
205
213
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* qBittorrent WebAPI v2 client.
|
|
3
|
+
*
|
|
4
|
+
* qB uses a cookie session (`SID`) obtained from `/api/v2/auth/login`, and
|
|
5
|
+
* expects a matching `Referer` on state-changing calls. Magnet uploads go
|
|
6
|
+
* through `multipart/form-data`. Every method mirrors the BitComet client so
|
|
7
|
+
* the plugin can switch downloaders without touching call sites.
|
|
8
|
+
*/
|
|
9
|
+
import { fetchText } from './net.js';
|
|
10
|
+
|
|
11
|
+
const AUTH_REQUIRED = '未配置 qBittorrent 账号密码';
|
|
12
|
+
|
|
13
|
+
function cookieFrom(headers) {
|
|
14
|
+
const raw = headers['set-cookie'];
|
|
15
|
+
if (!raw) return '';
|
|
16
|
+
const list = Array.isArray(raw) ? raw : [raw];
|
|
17
|
+
const parts = list
|
|
18
|
+
.map((c) => String(c).split(';')[0])
|
|
19
|
+
.filter((c) => c && c.includes('='));
|
|
20
|
+
return parts.join('; ');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function multipartBody(fields) {
|
|
24
|
+
// qB's parser is happier with the long dashed boundary curl emits.
|
|
25
|
+
const boundary = '------------------------' + Math.random().toString(16).slice(2) + Date.now().toString(16);
|
|
26
|
+
const chunks = [];
|
|
27
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
28
|
+
chunks.push(
|
|
29
|
+
`--${boundary}\r\n`,
|
|
30
|
+
`Content-Disposition: form-data; name="${key}"\r\n\r\n`,
|
|
31
|
+
String(value),
|
|
32
|
+
'\r\n',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
chunks.push(`--${boundary}--\r\n`);
|
|
36
|
+
return { boundary, body: chunks.join('') };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create a client bound to one qBittorrent WebUI.
|
|
41
|
+
* @param {{base?:string, user?:string, password?:string, proxy?:string}} [options]
|
|
42
|
+
*/
|
|
43
|
+
export function createQbittorrentClient(options = {}) {
|
|
44
|
+
const base = String(options.base || 'http://127.0.0.1:8080').replace(/\/+$/, '');
|
|
45
|
+
const user = String(options.user || '');
|
|
46
|
+
const password = String(options.password || '');
|
|
47
|
+
const proxy = options.proxy || '';
|
|
48
|
+
let sid = '';
|
|
49
|
+
|
|
50
|
+
async function login() {
|
|
51
|
+
// qB's Web UI can allow localhost without authentication; an empty
|
|
52
|
+
// credential pair means the caller relies on that bypass.
|
|
53
|
+
if (!user || !password) return '';
|
|
54
|
+
const res = await fetchText(`${base}/api/v2/auth/login`, {
|
|
55
|
+
proxy,
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: {
|
|
58
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
59
|
+
referer: base,
|
|
60
|
+
},
|
|
61
|
+
body: `username=${encodeURIComponent(user)}&password=${encodeURIComponent(password)}`,
|
|
62
|
+
timeout: 15000,
|
|
63
|
+
});
|
|
64
|
+
if (res.status !== 200 || !/Ok\./.test(res.body)) {
|
|
65
|
+
throw new Error(`qBittorrent 登录失败(HTTP ${res.status}):账号或密码错误`);
|
|
66
|
+
}
|
|
67
|
+
sid = cookieFrom(res.headers);
|
|
68
|
+
if (!sid) throw new Error('qBittorrent 登录失败:没有返回会话 Cookie');
|
|
69
|
+
return sid;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function call(path, { method = 'GET', body, headers = {}, type, retry = true } = {}) {
|
|
73
|
+
const send = async () => fetchText(base + path, {
|
|
74
|
+
proxy,
|
|
75
|
+
method,
|
|
76
|
+
headers: {
|
|
77
|
+
referer: base,
|
|
78
|
+
...(sid ? { cookie: sid } : {}),
|
|
79
|
+
...(type ? { 'content-type': type } : {}),
|
|
80
|
+
...headers,
|
|
81
|
+
},
|
|
82
|
+
body,
|
|
83
|
+
timeout: 20000,
|
|
84
|
+
});
|
|
85
|
+
let res = await send();
|
|
86
|
+
if (res.status === 403 && retry) {
|
|
87
|
+
// session expired or not yet established
|
|
88
|
+
await login();
|
|
89
|
+
res = await send();
|
|
90
|
+
}
|
|
91
|
+
return res;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Confirm the WebUI answers and the credentials work. */
|
|
95
|
+
async function checkAuth() {
|
|
96
|
+
try {
|
|
97
|
+
await login();
|
|
98
|
+
const res = await call('/api/v2/app/version');
|
|
99
|
+
if (res.status !== 200) return { ok: false, reason: `HTTP ${res.status}` };
|
|
100
|
+
return { ok: true, version: res.body.trim() };
|
|
101
|
+
} catch (err) {
|
|
102
|
+
return { ok: false, reason: err.message };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** All torrents as `{ id, name, state, size, progress, downSpeed, upSpeed }`. */
|
|
107
|
+
async function listTasks() {
|
|
108
|
+
if (!sid) await login();
|
|
109
|
+
const res = await call('/api/v2/torrents/info');
|
|
110
|
+
if (res.status !== 200) throw new Error(`qBittorrent 任务列表失败(HTTP ${res.status})`);
|
|
111
|
+
const list = JSON.parse(res.body || '[]');
|
|
112
|
+
return (Array.isArray(list) ? list : []).map((t) => ({
|
|
113
|
+
id: String(t.hash || ''),
|
|
114
|
+
name: t.name || '',
|
|
115
|
+
state: t.state || '',
|
|
116
|
+
size: Number(t.size) || 0,
|
|
117
|
+
progress: Number(t.progress) || 0,
|
|
118
|
+
downSpeed: Number(t.dlspeed) || 0,
|
|
119
|
+
upSpeed: Number(t.upspeed) || 0,
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Add one magnet; returns `{ ok, message }`. */
|
|
124
|
+
async function addMagnet(magnet, savePath) {
|
|
125
|
+
if (!sid) await login();
|
|
126
|
+
const fields = { urls: magnet, paused: 'false' };
|
|
127
|
+
if (savePath) fields.savepath = savePath;
|
|
128
|
+
const { boundary, body } = multipartBody(fields);
|
|
129
|
+
const res = await call('/api/v2/torrents/add', {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
type: `multipart/form-data; boundary=${boundary}`,
|
|
132
|
+
body,
|
|
133
|
+
});
|
|
134
|
+
const text = String(res.body || '').trim();
|
|
135
|
+
const ok = res.status === 200 && (/Ok/i.test(text) || text === '');
|
|
136
|
+
return { ok, message: text || `HTTP ${res.status}` };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Delete one torrent by hash; qB answers 200 and the list confirms. */
|
|
140
|
+
async function deleteTask(hash) {
|
|
141
|
+
if (!sid) await login();
|
|
142
|
+
const res = await call('/api/v2/torrents/delete', {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
type: 'application/x-www-form-urlencoded',
|
|
145
|
+
body: `hashes=${encodeURIComponent(hash)}&deleteFiles=false`,
|
|
146
|
+
});
|
|
147
|
+
let verified = false;
|
|
148
|
+
try {
|
|
149
|
+
const tasks = await listTasks();
|
|
150
|
+
verified = !tasks.some((t) => t.id.toLowerCase() === String(hash).toLowerCase());
|
|
151
|
+
} catch { /* leave unverified */ }
|
|
152
|
+
return { ok: res.status === 200, verified };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Find a task whose name contains the fragment. */
|
|
156
|
+
async function hasTaskByName(fragment) {
|
|
157
|
+
const needle = String(fragment || '').toLowerCase();
|
|
158
|
+
if (!needle) return null;
|
|
159
|
+
const tasks = await listTasks();
|
|
160
|
+
return tasks.find((t) => t.name.toLowerCase().includes(needle)) || null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return { listTasks, addMagnet, deleteTask, checkAuth, hasTaskByName };
|
|
164
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mikan",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Mikan Project tracker with BitComet integration: browse seasons, follow subgroups, and send confirmed releases to BitComet.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
"cordis.patch.yml",
|
|
28
28
|
"locale/*.json",
|
|
29
29
|
"docs",
|
|
30
|
-
"icon.svg"
|
|
30
|
+
"icon.svg",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"CHANGELOG.md"
|
|
31
34
|
],
|
|
32
35
|
"dsh": {
|
|
33
36
|
"bundle": {
|