dsh-mikan 0.1.0 → 0.2.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/CHANGELOG.md +71 -0
- package/README.md +46 -25
- package/client.js +437 -34
- package/docs/DETAIL.md +61 -27
- package/index.js +246 -74
- package/lib/airdate.js +4 -3
- package/lib/constants.js +11 -1
- package/lib/mikan.js +65 -6
- package/lib/mirrors.js +58 -0
- package/lib/net.js +10 -2
- package/lib/qbittorrent.js +164 -0
- package/package.json +7 -3
package/docs/DETAIL.md
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
# 蜜柑追番(dsh-mikan)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
把「蜜柑计划的番剧更新」和「P2P 下载器」连起来的半自动追番工具:**自动发现 → 你确认 → 自动下载**。
|
|
4
|
+
|
|
5
|
+
支持 BitComet 与 qBittorrent 两种下载器,可自动检测切换。
|
|
4
6
|
|
|
5
7
|
## 功能
|
|
6
8
|
|
|
7
9
|
| 能力 | 说明 |
|
|
8
10
|
|---|---|
|
|
9
|
-
|
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
11
|
+
| 当季浏览 | 按当前月份自动判断季度,按放送星期折叠列出新番 |
|
|
12
|
+
| 往季浏览 | 从近 12 年里选任意季度 |
|
|
13
|
+
| 字幕组浏览 | 番剧 → 字幕组 → 作品,三级懒加载 |
|
|
14
|
+
| 语言分类 | 作品按简体 / 繁体 / 多字幕(垃圾桶)三类标记 |
|
|
15
|
+
| 批量下载 | 全部 / 简中 / 繁中 / 多字幕,数量实时统计,空类置灰 |
|
|
16
|
+
| 订阅管理 | 番剧 + 字幕组(可多组),每组独立水位,运行时增删 |
|
|
17
|
+
| 更新跟进 | 定时抓取,该组出新集才通知,别组进度只作参考 |
|
|
18
|
+
| 追番周历 | 周一~周日分列,卡片显示各组进度 |
|
|
19
|
+
| 静默关注 | 从周表下架但仍接收更新 |
|
|
20
|
+
| 下载执行 | 单集或批量,确认后拼 magnet 调用下载器 |
|
|
16
21
|
|
|
17
22
|
## 环境自适应
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
插件启动时自动探测环境:
|
|
20
25
|
|
|
21
|
-
|
|
|
26
|
+
| 场景 | 蜜柑源 | 开播日源 |
|
|
22
27
|
|---|---|---|
|
|
23
|
-
|
|
|
24
|
-
| 无代理 | `mikanime.tv`(墙内) |
|
|
28
|
+
| 有可用代理 | 优先 `mikanani.me`(墙外) | 官方 bgm API(走代理) |
|
|
29
|
+
| 无代理 | 优先 `mikanime.tv`(墙内) | 社区镜像目录里的 API |
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
- 蜜柑探测结果缓存 5 分钟
|
|
32
|
+
- bgm 镜像目录(`bangumi.wiki/api/v1/mirrors`)缓存 1 小时,镜像不硬编码
|
|
33
|
+
- 探测失败会降级,不会让整个插件报错
|
|
27
34
|
|
|
28
35
|
## 配置
|
|
29
36
|
|
|
@@ -32,33 +39,41 @@
|
|
|
32
39
|
```yaml
|
|
33
40
|
- id: dsh-mikan
|
|
34
41
|
config:
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
downloader: 'qbittorrent'
|
|
43
|
+
qbittorrentBase: 'http://127.0.0.1:8080'
|
|
37
44
|
savePath: 'D:\Downloads\Anime'
|
|
45
|
+
proxy: 'http://127.0.0.1:7890'
|
|
38
46
|
checkIntervalMinutes: 30
|
|
39
47
|
```
|
|
40
48
|
|
|
41
49
|
| 字段 | 默认 | 说明 |
|
|
42
50
|
|---|---|---|
|
|
43
|
-
| `
|
|
44
|
-
| `bitcometBase` | `http://127.0.0.1:10816` |
|
|
51
|
+
| `downloader` | `bitcomet` | 下载器后端:`bitcomet` 或 `qbittorrent` |
|
|
52
|
+
| `bitcometBase` | `http://127.0.0.1:10816` | BitComet WebUI 地址 |
|
|
53
|
+
| `qbittorrentBase` | `http://127.0.0.1:8080` | qBittorrent WebUI 地址 |
|
|
54
|
+
| `qbittorrentUser` / `qbittorrentPassword` | 空 | qB 凭据;localhost 免认证时可留空 |
|
|
55
|
+
| `mikanBase` | 空 | 自定义蜜柑镜像,留空自动探测 |
|
|
56
|
+
| `bgmBase` | 空 | 自定义 bgm API,留空用官方 + 目录镜像 |
|
|
45
57
|
| `savePath` | 空(必填) | 下载保存目录,未设置时下载会被拒绝 |
|
|
58
|
+
| `proxy` | 空 | 本地代理地址,留空走直连 |
|
|
46
59
|
| `checkIntervalMinutes` | 30 | 后台更新检查间隔 |
|
|
47
60
|
|
|
48
|
-
|
|
61
|
+
BitComet 的用户名 / 密码会自动从 `%APPDATA%\BitComet\BitComet.xml` 读取,无需填写。
|
|
49
62
|
|
|
50
63
|
## 使用(对话内)
|
|
51
64
|
|
|
52
65
|
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
帮我看看这季有什么新番
|
|
67
|
+
「乱马1/2」有哪些字幕组在做
|
|
68
|
+
追「乱马1/2」,LoliHouse 的
|
|
56
69
|
检查一下有没有更新
|
|
57
|
-
|
|
70
|
+
把这组简中的都下了
|
|
58
71
|
下季度有什么新番,哪天开播
|
|
59
72
|
```
|
|
60
73
|
|
|
61
|
-
##
|
|
74
|
+
## 下载器配置要求
|
|
75
|
+
|
|
76
|
+
**BitComet**
|
|
62
77
|
|
|
63
78
|
1. 远程访问 → 监听端口填固定值(如 10816)
|
|
64
79
|
2. 勾选「启用网页版远程访问」
|
|
@@ -66,11 +81,30 @@
|
|
|
66
81
|
4. 设置用户名 / 密码
|
|
67
82
|
5. 不勾选「执行远程访问操作时显示提示窗口」
|
|
68
83
|
|
|
84
|
+
**qBittorrent**
|
|
85
|
+
|
|
86
|
+
1. 工具 → 选项 → Web UI
|
|
87
|
+
2. 勾选「启用 Web 用户界面」
|
|
88
|
+
3. 端口默认 8080
|
|
89
|
+
4. 设置用户名 / 密码(本机使用可勾「对本地主机跳过身份验证」)
|
|
90
|
+
|
|
91
|
+
## 界面状态
|
|
92
|
+
|
|
93
|
+
状态条上的标签均可点击:
|
|
94
|
+
|
|
95
|
+
| 标签 | 点击后 |
|
|
96
|
+
|---|---|
|
|
97
|
+
| 代理模式(绿)/ 直连模式(黄) | — |
|
|
98
|
+
| Mikan 可用(绿)/ 不可用(红) | 连接详情、自定义镜像、重新检测 |
|
|
99
|
+
| bgm 可用 / 不可用 | 连接详情、自定义 API、重新检测 |
|
|
100
|
+
| 下载器 | 端口扫描结果、切换 BitComet / qBittorrent |
|
|
101
|
+
|
|
69
102
|
## 已知限制
|
|
70
103
|
|
|
71
|
-
1. **无作品的番剧**在蜜柑只有 id/名称/封面,开播日依赖 bgm/AniList;都不可用时标注「未知」,不编造
|
|
104
|
+
1. **无作品的番剧**在蜜柑只有 id/名称/封面,开播日依赖 bgm / AniList;都不可用时标注「未知」,不编造
|
|
72
105
|
2. **剧场版 / OVA 的「放送日期」不可信**(页面显示周日),只用「放送开始」
|
|
73
|
-
3.
|
|
74
|
-
4.
|
|
75
|
-
5.
|
|
106
|
+
3. **运营商封锁 Cloudflare** 时蜜柑会完全不可达(两个内置域名都在 CF 后面),只能走代理或自定义镜像
|
|
107
|
+
4. 下载器的添加 / 删除接口返回值不可靠,一律以任务列表复核结果为准
|
|
108
|
+
5. 插件**不会**自己启动或关闭下载器进程
|
|
76
109
|
6. 后台检查只产生通知,不会自动下载——下载必须由你确认
|
|
110
|
+
7. 特殊集数格式(如「39-下周停播」)可能解析不出集号,但不影响下载
|
package/index.js
CHANGED
|
@@ -13,18 +13,21 @@
|
|
|
13
13
|
import fs from 'node:fs/promises';
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
|
|
16
|
-
import { DEFAULT_CONFIG, MIKAN_INSIDE, MIKAN_OUTSIDE, COMMON_PROXY_PORTS } from './lib/constants.js';
|
|
16
|
+
import { DEFAULT_CONFIG, MIKAN_INSIDE, MIKAN_OUTSIDE, BGM_API, COMMON_PROXY_PORTS } from './lib/constants.js';
|
|
17
|
+
import { fetchBgmMirrors } from './lib/mirrors.js';
|
|
17
18
|
import {
|
|
18
19
|
createMikanClient,
|
|
19
20
|
detectMikanSource,
|
|
20
21
|
parseRss,
|
|
21
22
|
parseSeasonFlow,
|
|
22
23
|
parseBangumiPage,
|
|
24
|
+
parseBangumiWorks,
|
|
23
25
|
parseSearchPage,
|
|
24
26
|
magnetFromHash,
|
|
25
27
|
hashFromLink,
|
|
26
28
|
} from './lib/mikan.js';
|
|
27
29
|
import { createBitCometClient } from './lib/bitcomet.js';
|
|
30
|
+
import { createQbittorrentClient } from './lib/qbittorrent.js';
|
|
28
31
|
import { resolveAirDate } from './lib/airdate.js';
|
|
29
32
|
import * as store from './lib/store.js';
|
|
30
33
|
import { probeProxy, parseProxy, probePort } from './lib/net.js';
|
|
@@ -144,23 +147,96 @@ export async function apply(ctx) {
|
|
|
144
147
|
const cfg = await loadConfig();
|
|
145
148
|
if (!force && env && Date.now() - env.at < ENV_TTL && env.proxy === cfg.proxy) return env;
|
|
146
149
|
const proxy = cfg.proxy || '';
|
|
150
|
+
// bgm: a custom base wins. Otherwise try the official API through a proxy,
|
|
151
|
+
// then fall back to whatever the community mirror directory currently lists.
|
|
152
|
+
// Mirrors change over time, so none of them is hard-coded here.
|
|
153
|
+
const customBgm = String(cfg.bgmBase || '').trim().replace(/\/+$/, '');
|
|
154
|
+
const officialBgm = BGM_API.replace(/\/+$/, '');
|
|
147
155
|
let bgmOk = false;
|
|
148
|
-
let bgmReason = '
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
156
|
+
let bgmReason = 'unreachable';
|
|
157
|
+
let bgmBase = customBgm || officialBgm;
|
|
158
|
+
let bgmViaProxy = false;
|
|
159
|
+
|
|
160
|
+
if (customBgm) {
|
|
161
|
+
try {
|
|
162
|
+
const r = await probeProxy(proxy, `${customBgm}/v0/subjects/274243`, 6000);
|
|
163
|
+
if (r.ok) {
|
|
164
|
+
bgmOk = true;
|
|
165
|
+
bgmBase = customBgm;
|
|
166
|
+
bgmViaProxy = Boolean(proxy);
|
|
167
|
+
bgmReason = 'custom';
|
|
168
|
+
} else {
|
|
169
|
+
bgmReason = r.reason || 'unreachable';
|
|
170
|
+
}
|
|
171
|
+
} catch (err) {
|
|
172
|
+
bgmReason = err.message;
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
if (proxy) {
|
|
176
|
+
try {
|
|
177
|
+
const r = await probeProxy(proxy, `${officialBgm}/v0/subjects/274243`, 6000);
|
|
178
|
+
if (r.ok) {
|
|
179
|
+
bgmOk = true;
|
|
180
|
+
bgmBase = officialBgm;
|
|
181
|
+
bgmViaProxy = true;
|
|
182
|
+
bgmReason = 'official';
|
|
183
|
+
} else {
|
|
184
|
+
bgmReason = r.reason || 'unreachable';
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
bgmReason = err.message;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!bgmOk) {
|
|
191
|
+
const mirrors = await fetchBgmMirrors(proxy);
|
|
192
|
+
for (const m of mirrors) {
|
|
193
|
+
if (m.base === officialBgm) continue;
|
|
194
|
+
try {
|
|
195
|
+
const r = await probeProxy('', `${m.base}/v0/subjects/274243`, 6000);
|
|
196
|
+
if (r.ok) {
|
|
197
|
+
bgmOk = true;
|
|
198
|
+
bgmBase = m.base;
|
|
199
|
+
bgmViaProxy = false;
|
|
200
|
+
bgmReason = 'mirror';
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
} catch { /* try next */ }
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Last resort on a direct connection: the official API (usually blocked
|
|
207
|
+
// from the mainland, hence only attempted after the mirror directory).
|
|
208
|
+
if (!bgmOk && !proxy) {
|
|
209
|
+
try {
|
|
210
|
+
const r = await probeProxy('', `${officialBgm}/v0/subjects/274243`, 6000);
|
|
211
|
+
if (r.ok) {
|
|
212
|
+
bgmOk = true;
|
|
213
|
+
bgmBase = officialBgm;
|
|
214
|
+
bgmViaProxy = false;
|
|
215
|
+
bgmReason = 'official-direct';
|
|
216
|
+
} else {
|
|
217
|
+
bgmReason = r.reason || 'unreachable';
|
|
218
|
+
}
|
|
219
|
+
} catch (err) {
|
|
220
|
+
bgmReason = err.message;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
153
223
|
}
|
|
154
|
-
|
|
224
|
+
|
|
225
|
+
const mikan = await detectMikanSource({ proxy: bgmViaProxy ? proxy : '', customBase: cfg.mikanBase || '' });
|
|
155
226
|
env = {
|
|
156
227
|
at: Date.now(),
|
|
157
228
|
proxy,
|
|
158
229
|
bgmOk,
|
|
159
230
|
bgmReason,
|
|
231
|
+
bgmBase,
|
|
232
|
+
bgmViaProxy,
|
|
160
233
|
mikanBase: mikan.base,
|
|
161
234
|
mikanViaProxy: mikan.viaProxy,
|
|
162
235
|
mikanReason: mikan.reason,
|
|
163
|
-
|
|
236
|
+
mikanOk: mikan.reason !== 'all-probes-failed',
|
|
237
|
+
// "proxy" means the proxy actually carried a request, not that bgm happened
|
|
238
|
+
// to be reachable through a direct mirror.
|
|
239
|
+
mode: (bgmViaProxy || mikan.viaProxy) ? 'proxy' : 'direct',
|
|
164
240
|
};
|
|
165
241
|
logger?.info?.(`[dsh-mikan] env=${env.mode} mikan=${env.mikanBase} bgm=${bgmOk}`);
|
|
166
242
|
return env;
|
|
@@ -184,7 +260,39 @@ export async function apply(ctx) {
|
|
|
184
260
|
});
|
|
185
261
|
}
|
|
186
262
|
|
|
187
|
-
/**
|
|
263
|
+
/** Resolve the configured downloader: BitComet or qBittorrent. */
|
|
264
|
+
async function downloaderClient() {
|
|
265
|
+
const cfg = await loadConfig();
|
|
266
|
+
if (String(cfg.downloader || 'bitcomet').toLowerCase() === 'qbittorrent') {
|
|
267
|
+
return createQbittorrentClient({
|
|
268
|
+
base: cfg.qbittorrentBase || 'http://127.0.0.1:8080',
|
|
269
|
+
user: cfg.qbittorrentUser || '',
|
|
270
|
+
password: cfg.qbittorrentPassword || '',
|
|
271
|
+
proxy: '',
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return bitcometClient();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Human-readable downloader descriptor for status responses. */
|
|
278
|
+
async function downloaderInfo() {
|
|
279
|
+
const cfg = await loadConfig();
|
|
280
|
+
const type = String(cfg.downloader || 'bitcomet').toLowerCase();
|
|
281
|
+
let client;
|
|
282
|
+
try {
|
|
283
|
+
client = await downloaderClient();
|
|
284
|
+
const auth = await client.checkAuth();
|
|
285
|
+
return {
|
|
286
|
+
type,
|
|
287
|
+
base: type === 'qbittorrent' ? (cfg.qbittorrentBase || 'http://127.0.0.1:8080') : cfg.bitcometBase,
|
|
288
|
+
ok: auth.ok,
|
|
289
|
+
version: auth.version || '',
|
|
290
|
+
reason: auth.reason || '',
|
|
291
|
+
};
|
|
292
|
+
} catch (err) {
|
|
293
|
+
return { type, ok: false, reason: err.message };
|
|
294
|
+
}
|
|
295
|
+
}
|
|
188
296
|
async function checkAll() {
|
|
189
297
|
await detectEnv();
|
|
190
298
|
const cfg = await loadConfig();
|
|
@@ -281,7 +389,7 @@ export async function apply(ctx) {
|
|
|
281
389
|
} catch { /* keep the fallback */ }
|
|
282
390
|
if (!info.startDate) {
|
|
283
391
|
try {
|
|
284
|
-
const r = await resolveAirDate({ names: [info.title].filter(Boolean), proxy: cfg.proxy, year: new Date().getFullYear() });
|
|
392
|
+
const r = await resolveAirDate({ names: [info.title].filter(Boolean), proxy: env?.bgmViaProxy ? cfg.proxy : '', bgmBase: env?.bgmBase || cfg.bgmBase || '', year: new Date().getFullYear() });
|
|
285
393
|
if (r.ok) { info.airDate = r.airDate; info.airSource = r.source || ''; }
|
|
286
394
|
} catch { /* unknown */ }
|
|
287
395
|
}
|
|
@@ -289,18 +397,38 @@ export async function apply(ctx) {
|
|
|
289
397
|
}
|
|
290
398
|
|
|
291
399
|
/** Level 3: one subgroup's releases for a bangumi; hashes only, no magnets. */
|
|
292
|
-
async function works(bangumiId, subgroupId = '') {
|
|
400
|
+
async function works(bangumiId, subgroupId = '', limit = 30) {
|
|
293
401
|
await detectEnv();
|
|
294
402
|
const cfg = await loadConfig();
|
|
295
|
-
|
|
296
|
-
|
|
403
|
+
let items;
|
|
404
|
+
if (subgroupId) {
|
|
405
|
+
// /Home/ExpandEpisodeTable returns the subgroup's complete table; RSS
|
|
406
|
+
// stops at 100 entries, which truncates long-running shows.
|
|
407
|
+
const html = await mikanClient(cfg).get(
|
|
408
|
+
`/Home/ExpandEpisodeTable?bangumiId=${encodeURIComponent(bangumiId)}&subtitleGroupId=${encodeURIComponent(subgroupId)}&take=1000`,
|
|
409
|
+
);
|
|
410
|
+
items = parseBangumiWorks(html);
|
|
411
|
+
} else {
|
|
412
|
+
const q = `/RSS/Bangumi?bangumiId=${encodeURIComponent(bangumiId)}`;
|
|
413
|
+
items = parseRss(await mikanClient(cfg).get(q));
|
|
414
|
+
}
|
|
415
|
+
const cap = Math.max(1, Math.min(Number(limit) || 30, 500));
|
|
416
|
+
const bucket = (v) => items.filter((r) => (r.subtitle || 'multi') === v).length;
|
|
297
417
|
return {
|
|
298
418
|
total: items.length,
|
|
299
|
-
|
|
419
|
+
displayed: Math.min(items.length, cap),
|
|
420
|
+
counts: {
|
|
421
|
+
all: items.length,
|
|
422
|
+
simp: bucket('simp'),
|
|
423
|
+
trad: bucket('trad'),
|
|
424
|
+
multi: bucket('multi'),
|
|
425
|
+
},
|
|
426
|
+
items: items.slice(0, cap).map((r) => ({
|
|
300
427
|
title: r.title,
|
|
301
428
|
episode: r.episode,
|
|
302
|
-
size:
|
|
429
|
+
size: r.size || '',
|
|
303
430
|
hash: r.hash,
|
|
431
|
+
subtitle: r.subtitle || 'multi',
|
|
304
432
|
})),
|
|
305
433
|
};
|
|
306
434
|
}
|
|
@@ -341,7 +469,7 @@ export async function apply(ctx) {
|
|
|
341
469
|
|
|
342
470
|
ctx.tools.register(defineTool({
|
|
343
471
|
name: 'mikan_status',
|
|
344
|
-
description: 'Report the current Mikan environment: proxy reachability, chosen mirror domain, air-date fallback availability, and
|
|
472
|
+
description: 'Report the current Mikan environment: proxy reachability, chosen mirror domain, air-date fallback availability, and downloader connection state.',
|
|
345
473
|
parameters: {
|
|
346
474
|
type: 'object',
|
|
347
475
|
properties: {
|
|
@@ -353,19 +481,13 @@ export async function apply(ctx) {
|
|
|
353
481
|
async execute(args) {
|
|
354
482
|
const e = await detectEnv(Boolean(args?.refresh));
|
|
355
483
|
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
|
-
}
|
|
484
|
+
const dl = await downloaderInfo();
|
|
363
485
|
return {
|
|
364
486
|
mode: e.mode,
|
|
365
487
|
proxy: e.proxy || '(none)',
|
|
366
488
|
bgm: { ok: e.bgmOk, reason: e.bgmReason },
|
|
367
489
|
mikan: { base: e.mikanBase, viaProxy: e.mikanViaProxy, reason: e.mikanReason },
|
|
368
|
-
|
|
490
|
+
downloader: dl,
|
|
369
491
|
savePath: cfg.savePath,
|
|
370
492
|
checkIntervalMinutes: cfg.checkIntervalMinutes,
|
|
371
493
|
};
|
|
@@ -374,13 +496,19 @@ export async function apply(ctx) {
|
|
|
374
496
|
|
|
375
497
|
ctx.tools.register(defineTool({
|
|
376
498
|
name: 'mikan_config',
|
|
377
|
-
description: 'Read or update plugin settings (proxy,
|
|
499
|
+
description: 'Read or update plugin settings (downloader, proxy, base URLs, save path, check interval). Changes apply on the next request.',
|
|
378
500
|
parameters: {
|
|
379
501
|
type: 'object',
|
|
380
502
|
properties: {
|
|
503
|
+
downloader: { type: 'string', enum: ['bitcomet', 'qbittorrent'], description: 'Which downloader backend to use.' },
|
|
381
504
|
proxy: { type: 'string', description: 'Local proxy, e.g. http://127.0.0.1:7890. Empty string means direct.' },
|
|
382
505
|
bitcometBase: { type: 'string', description: 'BitComet WebUI base URL.' },
|
|
383
|
-
|
|
506
|
+
qbittorrentBase: { type: 'string', description: 'qBittorrent WebUI base URL.' },
|
|
507
|
+
qbittorrentUser: { type: 'string', description: 'qBittorrent username.' },
|
|
508
|
+
qbittorrentPassword: { type: 'string', description: 'qBittorrent password.' },
|
|
509
|
+
mikanBase: { type: 'string', description: 'Custom Mikan mirror base URL. Empty means auto-detect between built-ins.' },
|
|
510
|
+
bgmBase: { type: 'string', description: 'Custom bgm.tv API base. Empty means official api.bgm.tv, then mirrors from the community directory.' },
|
|
511
|
+
savePath: { type: 'string', description: 'Default download directory inside the downloader.' },
|
|
384
512
|
checkIntervalMinutes: { type: 'number', description: 'Background check interval in minutes.' },
|
|
385
513
|
},
|
|
386
514
|
additionalProperties: false,
|
|
@@ -388,7 +516,7 @@ export async function apply(ctx) {
|
|
|
388
516
|
output: { schema: OBJ, render: renderJson },
|
|
389
517
|
async execute(args) {
|
|
390
518
|
const patch = {};
|
|
391
|
-
for (const key of ['proxy', 'bitcometBase', 'savePath', 'checkIntervalMinutes']) {
|
|
519
|
+
for (const key of ['downloader', 'proxy', 'bitcometBase', 'qbittorrentBase', 'qbittorrentUser', 'qbittorrentPassword', 'mikanBase', 'bgmBase', 'savePath', 'checkIntervalMinutes']) {
|
|
392
520
|
if (args?.[key] !== undefined) patch[key] = args[key];
|
|
393
521
|
}
|
|
394
522
|
if (Object.keys(patch).length === 0) return { config: await loadConfig(), changed: false };
|
|
@@ -491,7 +619,7 @@ export async function apply(ctx) {
|
|
|
491
619
|
|
|
492
620
|
ctx.tools.register(defineTool({
|
|
493
621
|
name: 'mikan_download',
|
|
494
|
-
description: 'Send releases to
|
|
622
|
+
description: 'Send releases to the configured 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
623
|
parameters: {
|
|
496
624
|
type: 'object',
|
|
497
625
|
properties: {
|
|
@@ -508,9 +636,9 @@ export async function apply(ctx) {
|
|
|
508
636
|
output: { schema: OBJ, render: renderJson },
|
|
509
637
|
async execute(args) {
|
|
510
638
|
const cfg = await loadConfig();
|
|
511
|
-
const client = await
|
|
639
|
+
const client = await downloaderClient();
|
|
512
640
|
const auth = await client.checkAuth();
|
|
513
|
-
if (!auth.ok) return { ok: false, reason:
|
|
641
|
+
if (!auth.ok) return { ok: false, reason: `下载器未就绪(${cfg.downloader || 'bitcomet'}):${auth.reason}` };
|
|
514
642
|
const savePath = args.savePath || cfg.savePath;
|
|
515
643
|
if (!savePath) return { ok: false, reason: '未配置下载目录(savePath),请先用 mikan_config 设置' };
|
|
516
644
|
const results = [];
|
|
@@ -577,18 +705,22 @@ export async function apply(ctx) {
|
|
|
577
705
|
const route = u.pathname.slice('/dsh-mikan'.length);
|
|
578
706
|
try {
|
|
579
707
|
if (route === '/state' && req.method === 'GET') {
|
|
580
|
-
const e = await detectEnv();
|
|
708
|
+
const e = await detectEnv(u.searchParams.get('refresh') === '1');
|
|
581
709
|
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 }; }
|
|
710
|
+
const dl = await downloaderInfo();
|
|
585
711
|
return send(res, 200, {
|
|
586
712
|
mode: e.mode,
|
|
587
713
|
proxy: e.proxy,
|
|
588
714
|
bgm: e.bgmOk,
|
|
715
|
+
bgmReason: e.bgmReason,
|
|
716
|
+
bgmActive: e.bgmBase,
|
|
717
|
+
bgmCustom: cfg.bgmBase || '',
|
|
589
718
|
mikan: e.mikanBase,
|
|
590
719
|
mikanViaProxy: e.mikanViaProxy,
|
|
591
|
-
|
|
720
|
+
mikanOk: e.mikanOk,
|
|
721
|
+
mikanReason: e.mikanReason,
|
|
722
|
+
mikanCustom: cfg.mikanBase || '',
|
|
723
|
+
downloader: dl,
|
|
592
724
|
savePath: cfg.savePath,
|
|
593
725
|
checkIntervalMinutes: cfg.checkIntervalMinutes,
|
|
594
726
|
lastCheckAt: await store.getLastCheck(),
|
|
@@ -626,7 +758,7 @@ export async function apply(ctx) {
|
|
|
626
758
|
if (!cfg.savePath) {
|
|
627
759
|
return send(res, 200, { ok: false, reason: '未配置下载目录(savePath),请先在插件配置中设置' });
|
|
628
760
|
}
|
|
629
|
-
const client = await
|
|
761
|
+
const client = await downloaderClient();
|
|
630
762
|
const auth = await client.checkAuth();
|
|
631
763
|
if (!auth.ok) return send(res, 200, { ok: false, reason: `BitComet 未就绪:${auth.reason}` });
|
|
632
764
|
const results = [];
|
|
@@ -658,33 +790,71 @@ export async function apply(ctx) {
|
|
|
658
790
|
await store.setLastUpdates([]);
|
|
659
791
|
return send(res, 200, { ok: true });
|
|
660
792
|
}
|
|
661
|
-
if (route === '/
|
|
662
|
-
const creds = await loadBitCometCreds();
|
|
793
|
+
if (route === '/downloader-scan' && req.method === 'POST') {
|
|
663
794
|
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
|
-
}
|
|
795
|
+
const current = String(cfg.downloader || 'bitcomet').toLowerCase();
|
|
671
796
|
const tried = [];
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
797
|
+
// Try the configured backend first, then the other one.
|
|
798
|
+
const order = current === 'qbittorrent' ? ['qbittorrent', 'bitcomet'] : ['bitcomet', 'qbittorrent'];
|
|
799
|
+
|
|
800
|
+
const probeQb = async () => {
|
|
801
|
+
const ports = [8080];
|
|
675
802
|
try {
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
} catch
|
|
679
|
-
|
|
803
|
+
const cur = new URL(cfg.qbittorrentBase || 'http://127.0.0.1:8080');
|
|
804
|
+
if (cur.port) ports.unshift(Number(cur.port));
|
|
805
|
+
} catch { /* keep default */ }
|
|
806
|
+
for (const port of [...new Set(ports)]) {
|
|
807
|
+
const base = `http://127.0.0.1:${port}`;
|
|
808
|
+
const r = await createQbittorrentClient({
|
|
809
|
+
base,
|
|
810
|
+
user: cfg.qbittorrentUser || '',
|
|
811
|
+
password: cfg.qbittorrentPassword || '',
|
|
812
|
+
proxy: '',
|
|
813
|
+
}).checkAuth();
|
|
814
|
+
tried.push({ type: 'qbittorrent', port, ok: r.ok, reason: r.reason || '' });
|
|
815
|
+
if (r.ok) return { type: 'qbittorrent', port, base };
|
|
816
|
+
}
|
|
817
|
+
return null;
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
const probeBc = async () => {
|
|
821
|
+
const creds = await loadBitCometCreds();
|
|
822
|
+
const user = cfg.bitcometUser || creds.user;
|
|
823
|
+
const password = cfg.bitcometPassword || creds.password;
|
|
824
|
+
const candidates = [];
|
|
825
|
+
if (creds.port) candidates.push(creds.port);
|
|
826
|
+
for (const port of [10816, 19135, 19136, 8080, 8081, 9999, 1235, 5000, 8888]) {
|
|
827
|
+
if (!candidates.includes(port)) candidates.push(port);
|
|
828
|
+
}
|
|
829
|
+
for (const port of candidates) {
|
|
830
|
+
const base = `http://127.0.0.1:${port}`;
|
|
831
|
+
let r = { ok: false, reason: '' };
|
|
832
|
+
try {
|
|
833
|
+
r = await createBitCometClient({ base, user, password, proxy: '' }).checkAuth();
|
|
834
|
+
} catch (err) {
|
|
835
|
+
r = { ok: false, reason: err.message };
|
|
836
|
+
}
|
|
837
|
+
tried.push({ type: 'bitcomet', port, ok: r.ok, reason: r.reason || '' });
|
|
838
|
+
if (r.ok) return { type: 'bitcomet', port, base };
|
|
680
839
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
840
|
+
return null;
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
for (const type of order) {
|
|
844
|
+
const hit = type === 'qbittorrent' ? await probeQb() : await probeBc();
|
|
845
|
+
if (hit) {
|
|
846
|
+
const patch = { downloader: hit.type };
|
|
847
|
+
if (hit.type === 'qbittorrent') patch.qbittorrentBase = hit.base;
|
|
848
|
+
else patch.bitcometBase = hit.base;
|
|
849
|
+
await saveConfig(patch);
|
|
850
|
+
return send(res, 200, { ok: true, ...hit, switched: hit.type !== current, tried });
|
|
685
851
|
}
|
|
686
852
|
}
|
|
687
|
-
return send(res, 200, {
|
|
853
|
+
return send(res, 200, {
|
|
854
|
+
ok: false,
|
|
855
|
+
reason: '未找到可用的下载器(qBittorrent 和 BitComet 都试过了)',
|
|
856
|
+
tried,
|
|
857
|
+
});
|
|
688
858
|
}
|
|
689
859
|
if (route === '/preview' && req.method === 'GET') {
|
|
690
860
|
const year = Number(u.searchParams.get('year')) || new Date().getFullYear();
|
|
@@ -700,7 +870,7 @@ export async function apply(ctx) {
|
|
|
700
870
|
const rows = await mapLimit(flat, 8, async ({ item, group }) => {
|
|
701
871
|
let air = { ok: false };
|
|
702
872
|
try {
|
|
703
|
-
air = await resolveAirDate({ names: [item.title], proxy: cfg.proxy, year });
|
|
873
|
+
air = await resolveAirDate({ names: [item.title], proxy: env?.bgmViaProxy ? cfg.proxy : '', bgmBase: env?.bgmBase || cfg.bgmBase || '', year });
|
|
704
874
|
} catch { /* ignore */ }
|
|
705
875
|
const airDate = air.ok ? air.airDate : '';
|
|
706
876
|
const state = airDate
|
|
@@ -761,7 +931,7 @@ export async function apply(ctx) {
|
|
|
761
931
|
let airSource = '';
|
|
762
932
|
if (!info.startDate) {
|
|
763
933
|
try {
|
|
764
|
-
const r = await resolveAirDate({ names: [info.title].filter(Boolean), proxy: cfg.proxy, year: new Date().getFullYear() });
|
|
934
|
+
const r = await resolveAirDate({ names: [info.title].filter(Boolean), proxy: env?.bgmViaProxy ? cfg.proxy : '', bgmBase: env?.bgmBase || cfg.bgmBase || '', year: new Date().getFullYear() });
|
|
765
935
|
if (r.ok) { airDate = r.airDate; airSource = r.source; }
|
|
766
936
|
} catch { /* unknown */ }
|
|
767
937
|
}
|
|
@@ -770,22 +940,10 @@ export async function apply(ctx) {
|
|
|
770
940
|
if (route === '/works' && req.method === 'GET') {
|
|
771
941
|
const bangumiId = u.searchParams.get('bangumiId') || '';
|
|
772
942
|
const subgroupId = u.searchParams.get('subgroupId') || '';
|
|
943
|
+
const subgroupName = u.searchParams.get('subgroupName') || '';
|
|
944
|
+
const limit = u.searchParams.get('limit') || '60';
|
|
773
945
|
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
|
-
});
|
|
946
|
+
return send(res, 200, await works(bangumiId, subgroupId, limit));
|
|
789
947
|
}
|
|
790
948
|
if (route === '/subscribe-group' && req.method === 'POST') {
|
|
791
949
|
const body = await readBody(req);
|
|
@@ -871,6 +1029,20 @@ export async function apply(ctx) {
|
|
|
871
1029
|
}
|
|
872
1030
|
return send(res, 200, { ok: false, reason: '未找到可用代理,已保持直连模式', tried });
|
|
873
1031
|
}
|
|
1032
|
+
if (route === '/config' && req.method === 'POST') {
|
|
1033
|
+
const body = await readBody(req);
|
|
1034
|
+
const allowed = ['downloader', 'proxy', 'bitcometBase', 'qbittorrentBase', 'qbittorrentUser', 'qbittorrentPassword', 'mikanBase', 'bgmBase', 'savePath', 'checkIntervalMinutes'];
|
|
1035
|
+
const patch = {};
|
|
1036
|
+
for (const key of allowed) {
|
|
1037
|
+
if (body[key] !== undefined) patch[key] = body[key];
|
|
1038
|
+
}
|
|
1039
|
+
if (Object.keys(patch).length === 0) {
|
|
1040
|
+
return send(res, 400, { ok: false, reason: '没有可更新的字段' });
|
|
1041
|
+
}
|
|
1042
|
+
const next = await saveConfig(patch);
|
|
1043
|
+
env = null;
|
|
1044
|
+
return send(res, 200, { ok: true, config: next });
|
|
1045
|
+
}
|
|
874
1046
|
if (route === '/disconnect' && req.method === 'POST') {
|
|
875
1047
|
await saveConfig({ proxy: '' });
|
|
876
1048
|
env = null;
|
package/lib/airdate.js
CHANGED
|
@@ -156,7 +156,7 @@ export async function searchBgm(keyword, opts = {}) {
|
|
|
156
156
|
const name = typeof keyword === 'string' ? keyword.trim() : '';
|
|
157
157
|
if (name === '') return { ok: false, results: [], reason: '搜索关键词为空' };
|
|
158
158
|
const timeout = Number(opts.timeout) > 0 ? Number(opts.timeout) : DEFAULT_TIMEOUT;
|
|
159
|
-
const url = `${BGM_API}/search/subject/${encodeURIComponent(name)}?type=2&responseGroup=large`;
|
|
159
|
+
const url = `${opts.base || BGM_API}/search/subject/${encodeURIComponent(name)}?type=2&responseGroup=large`;
|
|
160
160
|
|
|
161
161
|
let response;
|
|
162
162
|
try {
|
|
@@ -370,9 +370,10 @@ export async function resolveAirDate(options = {}) {
|
|
|
370
370
|
const proxy = options?.proxy;
|
|
371
371
|
const notes = [];
|
|
372
372
|
|
|
373
|
-
|
|
373
|
+
const bgmBase = typeof options?.bgmBase === 'string' ? options.bgmBase.trim() : '';
|
|
374
|
+
if (hasProxy(proxy) || bgmBase) {
|
|
374
375
|
for (const name of candidates) {
|
|
375
|
-
const res = await searchBgm(name, { proxy, timeout });
|
|
376
|
+
const res = await searchBgm(name, { proxy, timeout, base: bgmBase });
|
|
376
377
|
if (!res.ok) {
|
|
377
378
|
notes.push(`bgm「${name}」:${res.reason}`);
|
|
378
379
|
// A network-level failure will hit every name the same way; stop early.
|