dsh-bili-watch 0.2.25 → 0.2.27
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/package.json +1 -1
- package/tools/look.mjs +26 -9
package/package.json
CHANGED
package/tools/look.mjs
CHANGED
|
@@ -93,7 +93,17 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
|
93
93
|
const jitter = (base, spread) => base + Math.floor(Math.random() * spread)
|
|
94
94
|
|
|
95
95
|
async function jget(url, headers = H, timeoutMs = 30000) {
|
|
96
|
-
|
|
96
|
+
// T36-P1-2:只对网络层抖动重试一次(B 站偶发 ECONNRESET);业务 code(-352/-404)不重试
|
|
97
|
+
let r
|
|
98
|
+
for (let attempt = 0; ; attempt++) {
|
|
99
|
+
try {
|
|
100
|
+
r = await fetch(url, { headers, signal: AbortSignal.timeout(timeoutMs) })
|
|
101
|
+
if (!(r.status >= 500) || attempt >= 1) break
|
|
102
|
+
} catch (e) {
|
|
103
|
+
if (attempt >= 1) throw e
|
|
104
|
+
}
|
|
105
|
+
await sleep(300 + Math.floor(Math.random() * 400))
|
|
106
|
+
}
|
|
97
107
|
const t = await r.text()
|
|
98
108
|
if (!r.ok) return { code: -r.status, message: `HTTP ${r.status}` }
|
|
99
109
|
try {
|
|
@@ -433,7 +443,7 @@ function findFfmpeg(arg) {
|
|
|
433
443
|
for (const c of cands) {
|
|
434
444
|
if (c !== 'ffmpeg' && !existsSync(c)) continue
|
|
435
445
|
try {
|
|
436
|
-
execFileSync(c, ['-version'], { stdio: 'ignore' })
|
|
446
|
+
execFileSync(c, ['-version'], { stdio: 'ignore', timeout: 300000 })
|
|
437
447
|
return c
|
|
438
448
|
} catch {}
|
|
439
449
|
}
|
|
@@ -623,12 +633,12 @@ async function grabFrames(bv, { step = 0, outDir, ffmpeg, fresh = false, p: page
|
|
|
623
633
|
// 场景吸附:逐点 -ss 抽帧
|
|
624
634
|
frameTimes.forEach((t, i) => {
|
|
625
635
|
const out = join(dir, `${bv}-${String(i + 1).padStart(2, '0')}.jpg`)
|
|
626
|
-
execFileSync(bin, ['-y', '-threads', '2', '-ss', String(t), '-i', mp4, '-frames:v', '1', '-q:v', '2', out], { stdio: 'ignore' })
|
|
636
|
+
execFileSync(bin, ['-y', '-threads', '2', '-ss', String(t), '-i', mp4, '-frames:v', '1', '-q:v', '2', out], { stdio: 'ignore', timeout: 300000 })
|
|
627
637
|
})
|
|
628
638
|
} else {
|
|
629
639
|
// 默认等间隔
|
|
630
640
|
const pattern = join(dir, `${bv}-%02d.jpg`)
|
|
631
|
-
execFileSync(bin, ['-y', '-threads', '2', '-i', mp4, '-vf', `fps=1/${useStep}`, '-q:v', '2', pattern], { stdio: 'ignore' })
|
|
641
|
+
execFileSync(bin, ['-y', '-threads', '2', '-i', mp4, '-vf', `fps=1/${useStep}`, '-q:v', '2', pattern], { stdio: 'ignore', timeout: 300000 })
|
|
632
642
|
}
|
|
633
643
|
|
|
634
644
|
const n = jpgs().length
|
|
@@ -1364,7 +1374,7 @@ async function cmdSheet(bv, opts = {}) {
|
|
|
1364
1374
|
if (!bin) { process.exitCode = 1; console.log('✗ 找不到 ffmpeg:' + FFMPEG_HINT); return }
|
|
1365
1375
|
const out = join(CACHE, 'sheets', `${bv}-p${opts.p ?? 1}-${grid}.jpg`)
|
|
1366
1376
|
mkdirSync(dirname(out), { recursive: true })
|
|
1367
|
-
execFileSync(bin, ['-y', '-threads', '2', '-i', join(tmp, '%02d.jpg'), '-vf', `scale=640:-1,tile=${cols}x${rows}`, '-frames:v', '1', out], { stdio: 'ignore' })
|
|
1377
|
+
execFileSync(bin, ['-y', '-threads', '2', '-i', join(tmp, '%02d.jpg'), '-vf', `scale=640:-1,tile=${cols}x${rows}`, '-frames:v', '1', out], { stdio: 'ignore', timeout: 300000 })
|
|
1368
1378
|
console.log(`拼图: ${out}(${(statSync(out).size / 1024).toFixed(0)} KiB,共 ${picked.length} 帧)`)
|
|
1369
1379
|
console.log('读这张图就能过一遍画面;要精确读字用 ocr <BV>。')
|
|
1370
1380
|
}
|
|
@@ -1385,7 +1395,7 @@ async function cmdSubstrip(bv, opts = {}) {
|
|
|
1385
1395
|
if (!bin) { process.exitCode = 1; console.log('✗ 找不到 ffmpeg:' + FFMPEG_HINT); return }
|
|
1386
1396
|
const out = join(CACHE, 'sheets', `${bv}-p${opts.p ?? 1}-substrip.jpg`)
|
|
1387
1397
|
mkdirSync(dirname(out), { recursive: true })
|
|
1388
|
-
execFileSync(bin, ['-y', '-threads', '2', '-i', join(tmp, '%02d.jpg'), '-vf', `crop=iw:ih*0.20:0:ih*0.80,scale=1280:-1,tile=1x${take}`, '-frames:v', '1', out], { stdio: 'ignore' })
|
|
1398
|
+
execFileSync(bin, ['-y', '-threads', '2', '-i', join(tmp, '%02d.jpg'), '-vf', `crop=iw:ih*0.20:0:ih*0.80,scale=1280:-1,tile=1x${take}`, '-frames:v', '1', out], { stdio: 'ignore', timeout: 300000 })
|
|
1389
1399
|
console.log(`字幕带: ${out}(${(statSync(out).size / 1024).toFixed(0)} KiB,共 ${take} 条)`)
|
|
1390
1400
|
console.log('一张图里是整片底部字幕;硬字幕视频用它比逐帧 OCR 省很多。')
|
|
1391
1401
|
}
|
|
@@ -1781,7 +1791,12 @@ async function cmdText(bv, credPath, opts = {}) {
|
|
|
1781
1791
|
// 口播类正常 4–6 字/秒;低于 2 字/秒多半是背景音乐、外语歌或纯画面,
|
|
1782
1792
|
// 这时候转写出来的「字」只是把杂音听成了字,继续往下走 OCR 更靠谱。
|
|
1783
1793
|
const rate = v.dur > 0 ? a.chars / v.dur : 0
|
|
1784
|
-
if (rate >= 2) {
|
|
1794
|
+
if (rate >= 2 && !(a.verify && a.verify.suspect)) {
|
|
1795
|
+
// T40:ASR 也会把杂音/背景音听成字,主入口同样要过诱饵信号(原先只有字幕分支有)
|
|
1796
|
+
const asrBait = baitSignals(a.text, v, credibility(v, a.text))
|
|
1797
|
+
if (asrBait.suspect) {
|
|
1798
|
+
say(`[track] ⚠ 转写可疑:${asrBait.reasons.join(';')}(机器转写本来就可能听错,要看画面加 --verify 再跑一次)`)
|
|
1799
|
+
}
|
|
1785
1800
|
if (emitText(opts, {
|
|
1786
1801
|
video: { bv, title: v.title, up: v.owner, dur: v.dur, p: v.p, pages: v.pages },
|
|
1787
1802
|
source: 'asr',
|
|
@@ -1795,6 +1810,8 @@ async function cmdText(bv, credPath, opts = {}) {
|
|
|
1795
1810
|
printText(a.text, opts, bv)
|
|
1796
1811
|
done()
|
|
1797
1812
|
return
|
|
1813
|
+
} else if (a.verify && a.verify.suspect) {
|
|
1814
|
+
say(`[track] 转写: ⚠ 疑似幻觉(${(a.verify.reasons || []).join(';')}),降级到抽帧/OCR`)
|
|
1798
1815
|
}
|
|
1799
1816
|
say(`[track] 转写: 质量低(${a.chars} 字,${rate.toFixed(1)} 字/秒),继续往下试`)
|
|
1800
1817
|
} else {
|
|
@@ -2011,7 +2028,7 @@ function findYtDlp() {
|
|
|
2011
2028
|
for (const c of cands) {
|
|
2012
2029
|
if (c !== 'yt-dlp' && !existsSync(c)) continue
|
|
2013
2030
|
try {
|
|
2014
|
-
execFileSync(c, ['--version'], { stdio: 'ignore' })
|
|
2031
|
+
execFileSync(c, ['--version'], { stdio: 'ignore', timeout: 300000 })
|
|
2015
2032
|
return c
|
|
2016
2033
|
} catch {}
|
|
2017
2034
|
}
|
|
@@ -2151,7 +2168,7 @@ async function grabFramesLocal(mp4, tag, dur, { step = 0 } = {}) {
|
|
|
2151
2168
|
const bin = findFfmpeg()
|
|
2152
2169
|
if (!bin) throw new Error('找不到 ffmpeg:' + FFMPEG_HINT)
|
|
2153
2170
|
const pattern = join(dir, `${tag}-%02d.jpg`)
|
|
2154
|
-
execFileSync(bin, ['-y', '-threads', '2', '-i', mp4, '-vf', `fps=1/${useStep}`, '-q:v', '2', pattern], { stdio: 'ignore' })
|
|
2171
|
+
execFileSync(bin, ['-y', '-threads', '2', '-i', mp4, '-vf', `fps=1/${useStep}`, '-q:v', '2', pattern], { stdio: 'ignore', timeout: 300000 })
|
|
2155
2172
|
const n = jpgs().length
|
|
2156
2173
|
if (!n) throw new Error('抽帧没产出图片(可能源流异常)')
|
|
2157
2174
|
writeManifest(dir, { ok: true, tag, step: useStep, scene: false, frames: n })
|