@pls-compile-owo/fisheye 0.8.0 → 0.8.2
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 +14 -0
- package/README.md +1 -1
- package/lib/bili.mjs +19 -0
- package/lib/danmaku.mjs +4 -0
- package/package.json +1 -1
- package/test/golden/fixtures/BV1Cc411Q78T.json +27 -0
- package/test/golden/fixtures/BV1kr4y1x7DU.json +521 -0
- package/test/golden/fixtures/BV1uV411s7gm.json +448 -0
- package/test/golden/fixtures/BV1ziWP6qENy.json +1975 -0
- package/test/golden.test.mjs +54 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// golden case 验收集:用真实视频样本(test/golden/fixtures/*.json)验证核心启发式规则的输出。
|
|
2
|
+
// 样本来自真实 B站 视频(字幕/弹幕已落盘),测试离线运行,不依赖网络。
|
|
3
|
+
// 这些用例会随算法调整而更新预期——改阈值时先跑这里,确认变化是有意的。
|
|
4
|
+
import test from 'node:test'
|
|
5
|
+
import assert from 'node:assert/strict'
|
|
6
|
+
import fs from 'node:fs'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
import { assessSubtitleQuality } from '../lib/bili.mjs'
|
|
10
|
+
import { detectAdSegments } from '../lib/danmaku.mjs'
|
|
11
|
+
import { pickTimes } from '../lib/frame.mjs'
|
|
12
|
+
|
|
13
|
+
const dir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'golden', 'fixtures')
|
|
14
|
+
const fixtures = fs.readdirSync(dir).filter((f) => f.endsWith('.json')).map((f) => ({
|
|
15
|
+
file: f,
|
|
16
|
+
data: JSON.parse(fs.readFileSync(path.join(dir, f), 'utf8'))
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
test('golden 样本存在', () => {
|
|
20
|
+
assert.ok(fixtures.length >= 4, '至少 4 条真实视频样本')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
for (const { file, data } of fixtures) {
|
|
24
|
+
const label = `${data.bvid}(${String(data.title).slice(0, 20)})`
|
|
25
|
+
|
|
26
|
+
test(`${label}:字幕质量判定与真实样本一致`, () => {
|
|
27
|
+
const quality = assessSubtitleQuality(data.subtitleLines)
|
|
28
|
+
if (!data.hasOfficialSubs) {
|
|
29
|
+
assert.equal(data.subtitleLines.length, 0)
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
assert.equal(quality.quality, data.expectedQuality)
|
|
33
|
+
assert.ok(quality.avgEff >= 0 && quality.uniqueRatio >= 0 && quality.uniqueRatio <= 1)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test(`${label}:广告段检测与回放一致`, () => {
|
|
37
|
+
const segs = detectAdSegments(data.danmaku, data.duration)
|
|
38
|
+
assert.equal(segs.length, data.expectedAdSegments)
|
|
39
|
+
for (const s of segs) {
|
|
40
|
+
assert.ok(s.to > s.from)
|
|
41
|
+
assert.ok(s.dur > 0)
|
|
42
|
+
assert.ok(['high', 'low'].includes(s.confidence))
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test(`${label}:取帧计划覆盖完整时长`, () => {
|
|
47
|
+
const r = pickTimes(0, data.duration, 9, [], [])
|
|
48
|
+
assert.ok(r && Array.isArray(r.times))
|
|
49
|
+
assert.equal(r.times.length, 9)
|
|
50
|
+
assert.ok(r.times[0] >= 0)
|
|
51
|
+
assert.ok(r.times[r.times.length - 1] <= data.duration + 0.001)
|
|
52
|
+
for (let i = 1; i < r.times.length; i++) assert.ok(r.times[i] > r.times[i - 1])
|
|
53
|
+
})
|
|
54
|
+
}
|