dsh-chat-comprehension 0.2.0 → 0.3.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/NOTICE.md +20 -0
- package/README.md +20 -9
- package/client.js +41 -9
- package/lib/engines.mjs +136 -0
- package/lib/index.js +54 -4
- package/lib/qqbot-0.5.3-patches.json +75 -70
- package/lib/qqbot-patch.mjs +12 -7
- package/lib/video.mjs +11 -2
- package/package.json +7 -23
- package/vendor/dsh-agent-md/LICENSE +21 -0
- package/vendor/dsh-agent-md/cordis.patch.yml +8 -0
- package/vendor/dsh-agent-md/lib/index.js +775 -0
- package/vendor/dsh-agent-md/lib/persona.js +634 -0
- package/vendor/dsh-agent-md/lib/qq.js +527 -0
- package/vendor/dsh-agent-md/package.json +50 -0
- package/vendor/dsh-bili-scroll/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/NOTICE.md +18 -0
- package/vendor/dsh-bili-scroll/cordis.patch.yml +20 -0
- package/vendor/dsh-bili-scroll/index.js +3293 -0
- package/vendor/dsh-bili-scroll/lib/asr.py +141 -0
- package/vendor/dsh-bili-scroll/lib/diagnose.mjs +95 -0
- package/vendor/dsh-bili-scroll/lib/dm.mjs +110 -0
- package/vendor/dsh-bili-scroll/lib/favops.py +90 -0
- package/vendor/dsh-bili-scroll/lib/hostdeps.mjs +148 -0
- package/vendor/dsh-bili-scroll/lib/login.mjs +141 -0
- package/vendor/dsh-bili-scroll/lib/mcp.mjs +144 -0
- package/vendor/dsh-bili-scroll/lib/state.mjs +236 -0
- package/vendor/dsh-bili-scroll/lib/uid.mjs +61 -0
- package/vendor/dsh-bili-scroll/lib/uvfetch.mjs +217 -0
- package/vendor/dsh-bili-scroll/lib/verify.mjs +184 -0
- package/vendor/dsh-bili-scroll/package.json +84 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.patch.yml +116 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.yml +4 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/package.json +13 -0
- package/vendor/dsh-bili-scroll/prompts/duty.md +296 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/README.md +176 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/mcp_server.py +2015 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/requirements.txt +10 -0
- package/vendor/dsh-meme/.dsh/skills/dsh-meme-maintenance/SKILL.md +50 -0
- package/vendor/dsh-meme/LICENSE +21 -0
- package/vendor/dsh-meme/anim.js +588 -0
- package/vendor/dsh-meme/cordis.patch.yml +13 -0
- package/vendor/dsh-meme/icon.jpg +0 -0
- package/vendor/dsh-meme/index.js +2616 -0
- package/vendor/dsh-meme/locale/en.json +6 -0
- package/vendor/dsh-meme/locale/zh.json +6 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/index.db +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/manifest.json +13 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/angry/shengqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/baka/xianqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/color/huachi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/jiazai.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/wenhao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/cpu/jiaban.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/daily/ganfan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/fool/buyao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/givemoney/yaoqian.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/deyi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/ok.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/piaole.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/like/bixin.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/meow/maozhua.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/morning/zaoshanghao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/qiurao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/yun.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/see/zhenjing.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/haixiu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/toukan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sigh/wuyu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sleep/shuijiao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/surprised/xia.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/work/tangping.jpg +0 -0
- package/vendor/dsh-meme/memes.js +998 -0
- package/vendor/dsh-meme/package.json +67 -0
- package/vendor/dsh-meme/panel.html +210 -0
- package/vendor/dsh-video-storyboard/LICENSE +21 -0
- package/vendor/dsh-video-storyboard/NOTICE +12 -0
- package/vendor/dsh-video-storyboard/bin/_args.mjs +16 -0
- package/vendor/dsh-video-storyboard/bin/asr-check.mjs +85 -0
- package/vendor/dsh-video-storyboard/bin/scan-stats.mjs +43 -0
- package/vendor/dsh-video-storyboard/bin/scan-video.mjs +38 -0
- package/vendor/dsh-video-storyboard/bin/storyboard.mjs +195 -0
- package/vendor/dsh-video-storyboard/cordis.patch.yml +3 -0
- package/vendor/dsh-video-storyboard/dsh.plugin.json +12 -0
- package/vendor/dsh-video-storyboard/package.json +88 -0
- package/vendor/dsh-video-storyboard/scripts/check-syntax.mjs +56 -0
- package/vendor/dsh-video-storyboard/scripts/install-dev.mjs +104 -0
- package/vendor/dsh-video-storyboard/src/flicker.js +104 -0
- package/vendor/dsh-video-storyboard/src/index.js +82 -0
- package/vendor/dsh-video-storyboard/src/ocr_bridge.py +103 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr-lifecycle.js +262 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr.js +488 -0
- package/vendor/dsh-video-storyboard/src/storyboard/audio.js +168 -0
- package/vendor/dsh-video-storyboard/src/storyboard/binaries.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/board.js +121 -0
- package/vendor/dsh-video-storyboard/src/storyboard/browser-time.js +504 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cache.js +143 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cells.js +70 -0
- package/vendor/dsh-video-storyboard/src/storyboard/density.js +545 -0
- package/vendor/dsh-video-storyboard/src/storyboard/direct-url.js +130 -0
- package/vendor/dsh-video-storyboard/src/storyboard/fetch.js +373 -0
- package/vendor/dsh-video-storyboard/src/storyboard/flash.js +180 -0
- package/vendor/dsh-video-storyboard/src/storyboard/format.js +573 -0
- package/vendor/dsh-video-storyboard/src/storyboard/frames.js +212 -0
- package/vendor/dsh-video-storyboard/src/storyboard/index.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/injection.js +76 -0
- package/vendor/dsh-video-storyboard/src/storyboard/layout-order.js +176 -0
- package/vendor/dsh-video-storyboard/src/storyboard/locate.js +113 -0
- package/vendor/dsh-video-storyboard/src/storyboard/media-store.js +106 -0
- package/vendor/dsh-video-storyboard/src/storyboard/memory.js +94 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr-subs.js +107 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr.js +167 -0
- package/vendor/dsh-video-storyboard/src/storyboard/pipeline.js +853 -0
- package/vendor/dsh-video-storyboard/src/storyboard/plan.js +400 -0
- package/vendor/dsh-video-storyboard/src/storyboard/probe.js +132 -0
- package/vendor/dsh-video-storyboard/src/storyboard/provenance.js +44 -0
- package/vendor/dsh-video-storyboard/src/storyboard/python.js +84 -0
- package/vendor/dsh-video-storyboard/src/storyboard/register.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/scan.js +486 -0
- package/vendor/dsh-video-storyboard/src/storyboard/segments.js +117 -0
- package/vendor/dsh-video-storyboard/src/storyboard/sheet.js +507 -0
- package/vendor/dsh-video-storyboard/src/storyboard/storage.js +93 -0
- package/vendor/dsh-video-storyboard/src/storyboard/subtitles.js +181 -0
- package/vendor/dsh-video-storyboard/src/storyboard/tool-spec.js +544 -0
- package/vendor/dsh-video-storyboard/src/storyboard/transcript-file.js +146 -0
- package/vendor/dsh-video-storyboard/src/storyboard/url.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ytdlp.js +289 -0
- package/vendor/dsh-video-storyboard/src/tool-spec.js +17 -0
- package/vendor/dsh-video-storyboard/src/tools/locate.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/probe.js +23 -0
- package/vendor/dsh-video-storyboard/src/tools/shared.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/storyboard.js +20 -0
- package/vendor/dsh-video-storyboard/src/tools/zoom.js +56 -0
- package/vendor/dsh-world/LICENSE +21 -0
- package/vendor/dsh-world/assets/qq-card.png +0 -0
- package/vendor/dsh-world/cordis.patch.yml +6 -0
- package/vendor/dsh-world/lib/archive.d.ts +6 -0
- package/vendor/dsh-world/lib/archive.js +49 -0
- package/vendor/dsh-world/lib/archiveSelection.d.ts +8 -0
- package/vendor/dsh-world/lib/archiveSelection.js +20 -0
- package/vendor/dsh-world/lib/compaction.d.ts +124 -0
- package/vendor/dsh-world/lib/compaction.js +273 -0
- package/vendor/dsh-world/lib/compactionRegion.d.ts +42 -0
- package/vendor/dsh-world/lib/compactionRegion.js +210 -0
- package/vendor/dsh-world/lib/console/routes.d.ts +57 -0
- package/vendor/dsh-world/lib/console/routes.js +129 -0
- package/vendor/dsh-world/lib/console/snapshot.d.ts +39 -0
- package/vendor/dsh-world/lib/console/snapshot.js +51 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.d.ts +36 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.js +140 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.d.ts +9 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.js +46 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.d.ts +123 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.js +380 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.d.ts +75 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.js +187 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.d.ts +32 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.js +134 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.d.ts +57 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.js +188 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.d.ts +14 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.js +42 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.d.ts +15 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.js +36 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.d.ts +43 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.js +70 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.d.ts +16 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.js +52 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.js +62 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.d.ts +21 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.js +111 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.d.ts +5 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.js +43 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.d.ts +41 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.js +166 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.js +35 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.d.ts +30 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.js +216 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.d.ts +39 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.js +138 -0
- package/vendor/dsh-world/lib/faults.d.ts +10 -0
- package/vendor/dsh-world/lib/faults.js +13 -0
- package/vendor/dsh-world/lib/history.d.ts +16 -0
- package/vendor/dsh-world/lib/history.js +80 -0
- package/vendor/dsh-world/lib/hostContract.d.ts +19 -0
- package/vendor/dsh-world/lib/hostContract.js +1 -0
- package/vendor/dsh-world/lib/http.d.ts +18 -0
- package/vendor/dsh-world/lib/http.js +39 -0
- package/vendor/dsh-world/lib/index.d.ts +108 -0
- package/vendor/dsh-world/lib/index.js +356 -0
- package/vendor/dsh-world/lib/life/activity.d.ts +14 -0
- package/vendor/dsh-world/lib/life/activity.js +58 -0
- package/vendor/dsh-world/lib/life/alarm.d.ts +39 -0
- package/vendor/dsh-world/lib/life/alarm.js +132 -0
- package/vendor/dsh-world/lib/life/alarmTimer.d.ts +22 -0
- package/vendor/dsh-world/lib/life/alarmTimer.js +49 -0
- package/vendor/dsh-world/lib/life/diary.d.ts +4 -0
- package/vendor/dsh-world/lib/life/diary.js +9 -0
- package/vendor/dsh-world/lib/life/earlyStop.d.ts +19 -0
- package/vendor/dsh-world/lib/life/earlyStop.js +25 -0
- package/vendor/dsh-world/lib/life/home.d.ts +34 -0
- package/vendor/dsh-world/lib/life/home.js +91 -0
- package/vendor/dsh-world/lib/life/host.d.ts +22 -0
- package/vendor/dsh-world/lib/life/host.js +24 -0
- package/vendor/dsh-world/lib/life/journal.d.ts +20 -0
- package/vendor/dsh-world/lib/life/journal.js +59 -0
- package/vendor/dsh-world/lib/life/lifeStore.d.ts +16 -0
- package/vendor/dsh-world/lib/life/lifeStore.js +105 -0
- package/vendor/dsh-world/lib/life/messages.d.ts +17 -0
- package/vendor/dsh-world/lib/life/messages.js +53 -0
- package/vendor/dsh-world/lib/life/notify.d.ts +15 -0
- package/vendor/dsh-world/lib/life/notify.js +40 -0
- package/vendor/dsh-world/lib/life/pricing.d.ts +4 -0
- package/vendor/dsh-world/lib/life/pricing.js +30 -0
- package/vendor/dsh-world/lib/life/runtime.d.ts +52 -0
- package/vendor/dsh-world/lib/life/runtime.js +376 -0
- package/vendor/dsh-world/lib/life/toolRegistry.d.ts +22 -0
- package/vendor/dsh-world/lib/life/toolRegistry.js +64 -0
- package/vendor/dsh-world/lib/life/tools.d.ts +24 -0
- package/vendor/dsh-world/lib/life/tools.js +47 -0
- package/vendor/dsh-world/lib/life/types.d.ts +67 -0
- package/vendor/dsh-world/lib/life/types.js +1 -0
- package/vendor/dsh-world/lib/persona.d.ts +10 -0
- package/vendor/dsh-world/lib/persona.js +29 -0
- package/vendor/dsh-world/lib/promptSection.d.ts +30 -0
- package/vendor/dsh-world/lib/promptSection.js +81 -0
- package/vendor/dsh-world/lib/qqScope.d.ts +11 -0
- package/vendor/dsh-world/lib/qqScope.js +39 -0
- package/vendor/dsh-world/lib/runtime.d.ts +23 -0
- package/vendor/dsh-world/lib/runtime.js +206 -0
- package/vendor/dsh-world/lib/self.d.ts +10 -0
- package/vendor/dsh-world/lib/self.js +36 -0
- package/vendor/dsh-world/lib/sourceArchive.d.ts +28 -0
- package/vendor/dsh-world/lib/sourceArchive.js +156 -0
- package/vendor/dsh-world/lib/store.d.ts +30 -0
- package/vendor/dsh-world/lib/store.js +191 -0
- package/vendor/dsh-world/lib/timeContext.d.ts +3 -0
- package/vendor/dsh-world/lib/timeContext.js +13 -0
- package/vendor/dsh-world/lib/types.d.ts +118 -0
- package/vendor/dsh-world/lib/types.js +1 -0
- package/vendor/dsh-world/lib/worldPrompt.d.ts +47 -0
- package/vendor/dsh-world/lib/worldPrompt.js +49 -0
- package/vendor/dsh-world/lib/worldSwitch.d.ts +44 -0
- package/vendor/dsh-world/lib/worldSwitch.js +78 -0
- package/vendor/dsh-world/package-lock.json +1088 -0
- package/vendor/dsh-world/package.json +88 -0
- package/vendor/dsh-world/scripts/enable-tool-free-compaction.ps1 +33 -0
- package/vendor/dsh-world/src/archive.ts +45 -0
- package/vendor/dsh-world/src/archiveSelection.ts +27 -0
- package/vendor/dsh-world/src/compaction.ts +260 -0
- package/vendor/dsh-world/src/compactionRegion.ts +172 -0
- package/vendor/dsh-world/src/console/routes.ts +125 -0
- package/vendor/dsh-world/src/console/snapshot.ts +84 -0
- package/vendor/dsh-world/src/ecosystem/README.md +14 -0
- package/vendor/dsh-world/src/ecosystem/bridge/bridge.ts +121 -0
- package/vendor/dsh-world/src/ecosystem/bridge/route.ts +35 -0
- package/vendor/dsh-world/src/ecosystem/qq/bridge.ts +456 -0
- package/vendor/dsh-world/src/ecosystem/qq/panel.ts +178 -0
- package/vendor/dsh-world/src/ecosystem/qq/route.ts +130 -0
- package/vendor/dsh-world/src/ecosystem/qq/supervisor.ts +262 -0
- package/vendor/dsh-world/src/ecosystem/shared/context.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/shared/identity.ts +42 -0
- package/vendor/dsh-world/src/ecosystem/shared/outlets.ts +75 -0
- package/vendor/dsh-world/src/ecosystem/shared/sessions.ts +47 -0
- package/vendor/dsh-world/src/ecosystem/wechat/archive.ts +66 -0
- package/vendor/dsh-world/src/ecosystem/wechat/home.ts +94 -0
- package/vendor/dsh-world/src/ecosystem/wechat/images.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/wechat/index.ts +101 -0
- package/vendor/dsh-world/src/ecosystem/wechat/messages.ts +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/sending.ts +177 -0
- package/vendor/dsh-world/src/ecosystem/wechat/supervisor.ts +116 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/README.md +117 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/adapter.py +572 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/binding.py +52 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/LICENSE +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/NOTICE.md +10 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/bridge.cpp +229 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/build.ps1 +19 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/profile.json +28 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/groups.py +42 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/incoming.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/native.py +168 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/outgoing.py +95 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/requirements.txt +1 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/sender.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/snapshot.py +32 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/stickers.py +60 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/wechat.ps1 +75 -0
- package/vendor/dsh-world/src/faults.ts +12 -0
- package/vendor/dsh-world/src/history.ts +77 -0
- package/vendor/dsh-world/src/hostContract.ts +9 -0
- package/vendor/dsh-world/src/http.ts +34 -0
- package/vendor/dsh-world/src/index.ts +286 -0
- package/vendor/dsh-world/src/life/activity.ts +48 -0
- package/vendor/dsh-world/src/life/alarm.ts +119 -0
- package/vendor/dsh-world/src/life/alarmTimer.ts +45 -0
- package/vendor/dsh-world/src/life/diary.ts +10 -0
- package/vendor/dsh-world/src/life/earlyStop.ts +27 -0
- package/vendor/dsh-world/src/life/home.ts +85 -0
- package/vendor/dsh-world/src/life/host.ts +50 -0
- package/vendor/dsh-world/src/life/journal.ts +44 -0
- package/vendor/dsh-world/src/life/lifeStore.ts +70 -0
- package/vendor/dsh-world/src/life/messages.ts +44 -0
- package/vendor/dsh-world/src/life/notify.ts +47 -0
- package/vendor/dsh-world/src/life/pricing.ts +37 -0
- package/vendor/dsh-world/src/life/runtime.ts +318 -0
- package/vendor/dsh-world/src/life/toolRegistry.ts +48 -0
- package/vendor/dsh-world/src/life/tools.ts +61 -0
- package/vendor/dsh-world/src/life/types.ts +19 -0
- package/vendor/dsh-world/src/persona.ts +26 -0
- package/vendor/dsh-world/src/promptSection.ts +71 -0
- package/vendor/dsh-world/src/qqScope.ts +51 -0
- package/vendor/dsh-world/src/runtime.ts +172 -0
- package/vendor/dsh-world/src/self.ts +32 -0
- package/vendor/dsh-world/src/sourceArchive.ts +132 -0
- package/vendor/dsh-world/src/store.ts +170 -0
- package/vendor/dsh-world/src/timeContext.ts +13 -0
- package/vendor/dsh-world/src/types.ts +112 -0
- package/vendor/dsh-world/src/worldPrompt.ts +64 -0
- package/vendor/dsh-world/src/worldSwitch.ts +82 -0
- package/vendor/dsh-world/templates/alarm.md +49 -0
- package/vendor/dsh-world/templates/world-prompt.md +7 -0
- package/vendor/dsh-world/tests/archive.test.ts +57 -0
- package/vendor/dsh-world/tests/archiveScope.test.ts +86 -0
- package/vendor/dsh-world/tests/bridge.test.ts +211 -0
- package/vendor/dsh-world/tests/channelSessions.test.ts +79 -0
- package/vendor/dsh-world/tests/clientHooks.test.ts +103 -0
- package/vendor/dsh-world/tests/compaction.test.ts +141 -0
- package/vendor/dsh-world/tests/console.test.ts +202 -0
- package/vendor/dsh-world/tests/consoleClient.test.ts +101 -0
- package/vendor/dsh-world/tests/enableCompaction.test.ts +19 -0
- package/vendor/dsh-world/tests/fixtures.ts +6 -0
- package/vendor/dsh-world/tests/history.test.ts +100 -0
- package/vendor/dsh-world/tests/hostFixture.ts +46 -0
- package/vendor/dsh-world/tests/lifeActivity.test.ts +70 -0
- package/vendor/dsh-world/tests/lifeAlarm.test.ts +87 -0
- package/vendor/dsh-world/tests/lifeDiary.test.ts +33 -0
- package/vendor/dsh-world/tests/lifeMessages.test.ts +61 -0
- package/vendor/dsh-world/tests/lifeNotify.test.ts +46 -0
- package/vendor/dsh-world/tests/lifeParts.test.ts +45 -0
- package/vendor/dsh-world/tests/lifeRuntime.test.ts +660 -0
- package/vendor/dsh-world/tests/lifeStore.test.ts +90 -0
- package/vendor/dsh-world/tests/lifeTools.test.ts +53 -0
- package/vendor/dsh-world/tests/outlets.test.ts +85 -0
- package/vendor/dsh-world/tests/panel.test.ts +85 -0
- package/vendor/dsh-world/tests/plugin.test.ts +614 -0
- package/vendor/dsh-world/tests/pricing.test.ts +21 -0
- package/vendor/dsh-world/tests/qq.test.ts +121 -0
- package/vendor/dsh-world/tests/qqSessionMode.test.ts +97 -0
- package/vendor/dsh-world/tests/qqSupervisor.test.ts +149 -0
- package/vendor/dsh-world/tests/sourceArchive.test.ts +58 -0
- package/vendor/dsh-world/tests/store.test.ts +82 -0
- package/vendor/dsh-world/tests/storeWriter.ts +5 -0
- package/vendor/dsh-world/tests/timeContext.test.ts +15 -0
- package/vendor/dsh-world/tests/wechat.test.ts +254 -0
- package/vendor/dsh-world/tests/wechatImages.test.ts +130 -0
- package/vendor/dsh-world/tests/wechatSending.test.ts +142 -0
- package/vendor/dsh-world/tests/wechatSupervisor.test.ts +91 -0
- package/vendor/dsh-world/tests/worldPrompt.test.ts +201 -0
- package/vendor/dsh-world/tsconfig.build.json +5 -0
- package/vendor/dsh-world/tsconfig.json +8 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* direct-url.js — 高清直链:只给 zoom 取几帧用,不落盘、不留档。
|
|
3
|
+
*
|
|
4
|
+
* 从 fetch.js 拆出来的。它和 fetchMedia 是**两条完全不同的路**:
|
|
5
|
+
* fetchMedia 要一份完整的本地低清片(几十 MB、可缓存、可重读);
|
|
6
|
+
* 这里只要一个带签名的临时 URI(2–6 帧、几次 HTTP seek 就作废)。
|
|
7
|
+
*
|
|
8
|
+
* 直链**只存在进程内存里**:落盘的凭证比多花 2.4 秒危险得多。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
DEFAULT_UA, discoverYtdlp, explainYtdlpError, formatSelector, resolveAuth, runProcess,
|
|
13
|
+
summariseInfo, unwrapSingle,
|
|
14
|
+
} from './ytdlp.js';
|
|
15
|
+
import { assertFetchableUrl, normalizeUrl } from './url.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 直链是有签名的临时凭证,只在进程内存里留一会儿。
|
|
19
|
+
* 为什么值得记:storyboard 已经跑过一次 `-J`(2.4 s),zoom 紧接着再来一次纯属浪费;
|
|
20
|
+
* 而且 zoom 之后往往还有第二个 zoom。
|
|
21
|
+
* 过期就丢——**绝不落盘**,落盘的凭证比多花 2.4 秒危险得多。
|
|
22
|
+
*/
|
|
23
|
+
const directCache = new Map();
|
|
24
|
+
|
|
25
|
+
export function rememberDirect(normalizedUrl, height, info) {
|
|
26
|
+
directCache.set(`${normalizedUrl}|${height}`, { ...info, storedAt: Date.now() });
|
|
27
|
+
// 顺手清掉过期的,避免长会话里无限膨胀
|
|
28
|
+
if (directCache.size > 64) {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
for (const [key, value] of directCache) {
|
|
31
|
+
if (value.expiresAt && value.expiresAt - now < 10 * 60 * 1000) directCache.delete(key);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function recallDirect(normalizedUrl, height, { marginMs = 10 * 60 * 1000 } = {}) {
|
|
37
|
+
const hit = directCache.get(`${normalizedUrl}|${height}`);
|
|
38
|
+
if (!hit) return null;
|
|
39
|
+
if (hit.expiresAt && hit.expiresAt - Date.now() < marginMs) {
|
|
40
|
+
directCache.delete(`${normalizedUrl}|${height}`);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return hit;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function __clearDirectCache() {
|
|
47
|
+
directCache.clear();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 从 yt-dlp 的 formats 里挑一条不超过 height 的最好画面轨 */
|
|
51
|
+
export function pickVideoFormat(formats, height) {
|
|
52
|
+
const video = formats.filter((f) => f.vcodec && f.vcodec !== 'none');
|
|
53
|
+
if (video.length === 0) return null;
|
|
54
|
+
// **按短边比,不按 height**:竖屏视频的 height 是长边(1080x1920),用 height<=1080 会把
|
|
55
|
+
// 1080x1920 排除、退到 480x852 —— 清单写着 1080p,实际给的是 852(issue #9)。
|
|
56
|
+
const short = (f) => Math.min(f.height ?? 0, f.width ?? 0) || (f.height ?? 0);
|
|
57
|
+
const below = video
|
|
58
|
+
.filter((f) => !f.height || short(f) <= height)
|
|
59
|
+
.sort((a, b) => short(b) - short(a) || (b.tbr ?? 0) - (a.tbr ?? 0));
|
|
60
|
+
return below[0] ?? [...video].sort((a, b) => short(a) - short(b))[0];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 从 `-J` 的结果里直接挑出 zoom 要用的那一档直链(不下载任何东西)。 */
|
|
64
|
+
export function directFromSummary(summary, height) {
|
|
65
|
+
return directFromFormat(pickVideoFormat(summary?.formats, height));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function directFromFormat(chosen) {
|
|
69
|
+
if (!chosen?.url) return null;
|
|
70
|
+
const deadline = Number(chosen.url.match(/[?&]deadline=(\d+)/)?.[1]);
|
|
71
|
+
return {
|
|
72
|
+
url: chosen.url,
|
|
73
|
+
height: chosen.height ?? null,
|
|
74
|
+
userAgent: chosen.http_headers?.['User-Agent'] || DEFAULT_UA,
|
|
75
|
+
referer: chosen.http_headers?.Referer || null,
|
|
76
|
+
// B 站直链带 deadline(约 2 小时);拿不到就按 90 分钟算,宁可早重解析
|
|
77
|
+
expiresAt: Number.isFinite(deadline) && deadline > 0 ? deadline * 1000 : Date.now() + 90 * 60 * 1000,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 拿一条**只含画面**的高清直链(zoom 用),不落盘。
|
|
83
|
+
* 先查进程内缓存(storyboard 那次 `-J` 已经顺手记下了),miss 才真解析。
|
|
84
|
+
*
|
|
85
|
+
* @returns {Promise<{url:string, height:number, userAgent:string, referer:string|null, expiresAt:number}>}
|
|
86
|
+
*/
|
|
87
|
+
export async function resolveDirectUrl(input, opts = {}) {
|
|
88
|
+
const {
|
|
89
|
+
height = 1080,
|
|
90
|
+
cookies,
|
|
91
|
+
allowAnonymous = false,
|
|
92
|
+
env = process.env,
|
|
93
|
+
ytdlp,
|
|
94
|
+
run = runProcess,
|
|
95
|
+
useCache = true,
|
|
96
|
+
} = opts;
|
|
97
|
+
|
|
98
|
+
const url = assertFetchableUrl(input);
|
|
99
|
+
const normalized = normalizeUrl(url);
|
|
100
|
+
if (useCache) {
|
|
101
|
+
const hit = recallDirect(normalized, height);
|
|
102
|
+
if (hit) return hit;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const auth = await resolveAuth({ cookies, allowAnonymous, env });
|
|
106
|
+
const tool = ytdlp || await discoverYtdlp({ env, run });
|
|
107
|
+
|
|
108
|
+
const args = ['-J', '--no-warnings', '--no-playlist'];
|
|
109
|
+
if (auth.cookiesPath) args.push('--cookies', auth.cookiesPath);
|
|
110
|
+
args.push(url);
|
|
111
|
+
|
|
112
|
+
const probed = await run(tool, args, { timeoutMs: 90_000 });
|
|
113
|
+
if (probed.code !== 0) throw new Error(explainYtdlpError(probed.stderr, probed.code));
|
|
114
|
+
|
|
115
|
+
let info;
|
|
116
|
+
try {
|
|
117
|
+
info = JSON.parse(probed.stdout);
|
|
118
|
+
} catch {
|
|
119
|
+
throw new Error('yt-dlp returned unparsable JSON while resolving a direct URL');
|
|
120
|
+
}
|
|
121
|
+
const summary = summariseInfo(unwrapSingle(info, url));
|
|
122
|
+
if (!summary.formats.length) throw new Error('no video formats available for this link');
|
|
123
|
+
|
|
124
|
+
const chosen = pickVideoFormat(summary.formats, height);
|
|
125
|
+
const direct = directFromFormat(chosen);
|
|
126
|
+
if (!direct) throw new Error('the selected format has no direct URL');
|
|
127
|
+
|
|
128
|
+
rememberDirect(normalized, height, direct);
|
|
129
|
+
return direct;
|
|
130
|
+
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fetch.js — 「URL → 本地文件」的那一层,以及 zoom 用的高清直链。
|
|
3
|
+
*
|
|
4
|
+
* 设计前提(都在真机上量过,不是推测):
|
|
5
|
+
*
|
|
6
|
+
* 1. **必须落盘一份低清全片**。`pick:'sharp'` 每段要 3 个候选帧,9 段就是 27 次随机 seek。
|
|
7
|
+
* 实测同一条视频:本地 27 次 9.6s,HTTP 直链 51.8s。那 7MB 是"后面随便跳"的入场费。
|
|
8
|
+
* 2. **高清只在 zoom 时取帧**,一次 2–6 帧,不落盘。
|
|
9
|
+
* 3. **必须登录**。同一条视频匿名只有 480P、登录有 1080P,而且**那一档根本不在列表里**——
|
|
10
|
+
* 模型不会收到任何信号,只会以为自己看的是高清。所以默认拒绝无 cookie 调用。
|
|
11
|
+
* 4. 插件**不打包 yt-dlp**,只调用用户自己装的那个(`docs/设计 §9.5` 已拍板)。
|
|
12
|
+
*
|
|
13
|
+
* 这一层只负责"把东西弄到本地"和"记下能拿到什么",不碰扫描/取帧。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
access, mkdir, readdir, rename, rm, stat, writeFile,
|
|
18
|
+
} from 'node:fs/promises';
|
|
19
|
+
import { isAbsolute, join } from 'node:path';
|
|
20
|
+
|
|
21
|
+
import { DEFAULT_FFMPEG, probeVideo } from './probe.js';
|
|
22
|
+
import {
|
|
23
|
+
DEFAULT_UA, discoverYtdlp, explainYtdlpError, formatSelector, resolveAuth, runProcess,
|
|
24
|
+
summariseInfo, unwrapSingle,
|
|
25
|
+
} from './ytdlp.js';
|
|
26
|
+
import {
|
|
27
|
+
fileExists, freeBytes, mediaDir, mediaKey, mediaMaxBytes, pruneMedia,
|
|
28
|
+
} from './media-store.js';
|
|
29
|
+
import { assertFetchableUrl, isHttpUrl, normalizeUrl } from './url.js';
|
|
30
|
+
import { directFromSummary, recallDirect, rememberDirect } from './direct-url.js';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 下载目录里出现 `video.*` 的不一定是画面轨:B 站的 DASH 源会给出 `video.f30280.m4a`
|
|
34
|
+
* 这种纯音频轨。文件名不能当容器证据(PR #8 的教训),但**扩展名足以判断"这是不是音频"**——
|
|
35
|
+
* 把 m4a 改名成 video.mp4 才是真正的静默坏数据,宁可在这里报错。
|
|
36
|
+
*/
|
|
37
|
+
const AUDIO_EXTS = new Set(['.m4a', '.m4b', '.mp3', '.aac', '.opus', '.ogg', '.oga', '.wav', '.flac', '.weba']);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 把 URL 变成一份可以喂给现有管线的本地文件,并把"这条链接能拿到什么"记下来。
|
|
41
|
+
*
|
|
42
|
+
* @param {string} input http(s) 链接
|
|
43
|
+
* @param {object} opts
|
|
44
|
+
* @param {number} [opts.scanHeight=360] 落盘用的清晰度上限
|
|
45
|
+
* @param {number} [opts.zoomHeight=1080] 只记录,供 zoom 用
|
|
46
|
+
* @param {string} [opts.cookies]
|
|
47
|
+
* @param {boolean} [opts.allowAnonymous=false]
|
|
48
|
+
* @param {string} [opts.ffmpegPath] 传给 yt-dlp 的 ffmpeg 路径(合流用)
|
|
49
|
+
* @param {{bin:string,prefix:string[]}} [opts.ytdlp] 测试注入,正常走发现逻辑
|
|
50
|
+
* @param {(p:object)=>void} [opts.onProgress]
|
|
51
|
+
* @returns {Promise<{path:string, source:object}>}
|
|
52
|
+
*/
|
|
53
|
+
export async function fetchMedia(input, opts = {}) {
|
|
54
|
+
const {
|
|
55
|
+
scanHeight = 360,
|
|
56
|
+
zoomHeight = 1080,
|
|
57
|
+
cookies,
|
|
58
|
+
allowAnonymous = false,
|
|
59
|
+
// yt-dlp 自己不会去 DSH 的 bin 目录找 ffmpeg;不告诉它路径时,DASH 的 `+ba` 合流
|
|
60
|
+
// 会静默失败,只留下 video.<id>.mp4 和 audio.<id>.m4a 两个文件。见 issue #18。
|
|
61
|
+
ffmpegPath = DEFAULT_FFMPEG,
|
|
62
|
+
env = process.env,
|
|
63
|
+
ytdlp,
|
|
64
|
+
onProgress,
|
|
65
|
+
run = runProcess,
|
|
66
|
+
} = opts;
|
|
67
|
+
|
|
68
|
+
const url = assertFetchableUrl(input);
|
|
69
|
+
const normalized = normalizeUrl(url);
|
|
70
|
+
const auth = await resolveAuth({ cookies, allowAnonymous, env });
|
|
71
|
+
const tool = ytdlp || await discoverYtdlp({ env, run });
|
|
72
|
+
|
|
73
|
+
const key = mediaKey(normalized, scanHeight);
|
|
74
|
+
const dir = join(mediaDir(env), key);
|
|
75
|
+
const target = join(dir, 'video.mp4');
|
|
76
|
+
|
|
77
|
+
// ---- 命中:连 meta.json 一起读回来,否则 source 会缺 maxAvailable/zoomTarget
|
|
78
|
+
if (await fileExists(target)) {
|
|
79
|
+
const st = await stat(target);
|
|
80
|
+
if (st.size > 0) {
|
|
81
|
+
let meta = null;
|
|
82
|
+
try {
|
|
83
|
+
meta = JSON.parse(await readFile(join(dir, 'meta.json'), 'utf8'));
|
|
84
|
+
} catch { /* 老缓存没有 meta,退回最小信息 */ }
|
|
85
|
+
// 旧版本(或无 ffmpeg 的环境)可能把 video-only 的 mp4 缓存下来。
|
|
86
|
+
// 只修下载参数还不够:同一条链接再跑一次会直接命中这份坏缓存,用户按清单提示
|
|
87
|
+
// "装好 ffmpeg 再试"也仍然是无声的。用当时可用的 ffmpeg 路径做一次失效重试;
|
|
88
|
+
// 如果同一个 ffmpeg 仍然合不上,就把 audioMergeRetry 记进 meta,避免每次重下。
|
|
89
|
+
const staleMerge = Boolean(
|
|
90
|
+
meta?.audioMissing && isAbsolute(ffmpegPath) && meta.audioMergeRetry !== ffmpegPath,
|
|
91
|
+
);
|
|
92
|
+
if (staleMerge) {
|
|
93
|
+
onProgress?.({ phase: 'cache-invalid', path: target, reason: 'audio-missing' });
|
|
94
|
+
await rm(target, { force: true }).catch(() => {});
|
|
95
|
+
await rm(join(dir, 'meta.json'), { force: true }).catch(() => {});
|
|
96
|
+
} else {
|
|
97
|
+
const cachedDirect = recallDirect(normalized, zoomHeight);
|
|
98
|
+
onProgress?.({ phase: 'cache-hit', path: target });
|
|
99
|
+
return {
|
|
100
|
+
path: target,
|
|
101
|
+
frameSource: cachedDirect
|
|
102
|
+
? { uri: cachedDirect.url, userAgent: cachedDirect.userAgent, referer: cachedDirect.referer, height: cachedDirect.height, expiresAt: cachedDirect.expiresAt }
|
|
103
|
+
: null,
|
|
104
|
+
source: {
|
|
105
|
+
kind: 'url',
|
|
106
|
+
url,
|
|
107
|
+
bytes: st.size,
|
|
108
|
+
scanHeight,
|
|
109
|
+
...(meta ?? {}),
|
|
110
|
+
// `cached` 必须排在展开之后:meta.json 里存的是写入那一刻的 false,会把这里覆盖掉
|
|
111
|
+
cached: true,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ---- 解析
|
|
119
|
+
onProgress?.({ phase: 'resolve', url });
|
|
120
|
+
const { summary, authKind, warning: authNote, raw: info } = await probeSummary({ url, auth, tool, env, run });
|
|
121
|
+
|
|
122
|
+
// 顺手把 zoom 要用的高清直链挑出来并记住 —— formats 已经在手里了,这一步零成本。
|
|
123
|
+
// 否则 zoom 会再跑一次 `-J`(2.4 s),而它每次都紧跟在这个调用后面。
|
|
124
|
+
const zoomDirect = directFromSummary(summary, zoomHeight);
|
|
125
|
+
if (zoomDirect) rememberDirect(normalized, zoomHeight, zoomDirect);
|
|
126
|
+
|
|
127
|
+
// ---- 空间检查(下载前,按估算大小拒绝,不静默降质)
|
|
128
|
+
const wantHeight = summary.heights.length > 0
|
|
129
|
+
? summary.heights.filter((h) => h <= scanHeight).at(-1) ?? summary.heights[0]
|
|
130
|
+
: null;
|
|
131
|
+
const wanted = Number.isFinite(Number(info?.filesize_approx))
|
|
132
|
+
? Number(info.filesize_approx)
|
|
133
|
+
: null;
|
|
134
|
+
if (wanted) {
|
|
135
|
+
const free = await freeBytes();
|
|
136
|
+
if (free !== null && wanted * 1.5 > free) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`not enough disk space: need about ${(wanted / 1048576).toFixed(0)} MB ` +
|
|
139
|
+
`(+50% headroom), only ${(free / 1048576).toFixed(0)} MB free`,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ---- 下载
|
|
145
|
+
await mkdir(dir, { recursive: true });
|
|
146
|
+
onProgress?.({ phase: 'download', height: wantHeight });
|
|
147
|
+
const dlArgs = [
|
|
148
|
+
'-f', formatSelector(scanHeight),
|
|
149
|
+
// 按"短边"就近取:竖屏视频的 res 是宽(360/480/720),不是 height。
|
|
150
|
+
...(Number.isFinite(scanHeight) && scanHeight > 0 ? ['-S', `res:${Math.round(scanHeight)}`] : []),
|
|
151
|
+
// DSH 桌面版常把 ffmpeg 放在 $DSH_HOME/bin 而不进 PATH;yt-dlp 只认 PATH 或这个参数。
|
|
152
|
+
...(isAbsolute(ffmpegPath) ? ['--ffmpeg-location', ffmpegPath] : []),
|
|
153
|
+
'--no-warnings', '--no-playlist', '--no-progress',
|
|
154
|
+
// 断点续传:网络抖了下次接着下,而不是从头再来
|
|
155
|
+
'--continue',
|
|
156
|
+
// CDN 抖动很常见(B 站尤其),默认只重试 10 次整包,分片不重试
|
|
157
|
+
'--retries', '3', '--fragment-retries', '5',
|
|
158
|
+
'--merge-output-format', 'mp4',
|
|
159
|
+
'-o', join(dir, 'video.%(ext)s'),
|
|
160
|
+
];
|
|
161
|
+
if (auth.cookiesPath) dlArgs.push('--cookies', auth.cookiesPath);
|
|
162
|
+
dlArgs.push(url);
|
|
163
|
+
|
|
164
|
+
let downloaded = await run(tool, dlArgs, { timeoutMs: 600_000 });
|
|
165
|
+
|
|
166
|
+
// B 站风控(567)/ 限流(412):带浏览器头 + Referer 再试一次。
|
|
167
|
+
// 不去猜它的风控算法,只给它一眼看得出是"浏览器在看网页"的请求。
|
|
168
|
+
if (downloaded.code !== 0 && /HTTP Error (?:567|412)/i.test(downloaded.stderr ?? '')) {
|
|
169
|
+
const retryArgs = dlArgs.slice(0, -1).concat([
|
|
170
|
+
'--add-header', 'Referer:https://www.bilibili.com/',
|
|
171
|
+
'--user-agent',
|
|
172
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' +
|
|
173
|
+
'Chrome/124.0.0.0 Safari/537.36',
|
|
174
|
+
'--sleep-requests', '1',
|
|
175
|
+
dlArgs[dlArgs.length - 1],
|
|
176
|
+
]);
|
|
177
|
+
downloaded = await run(tool, retryArgs, { timeoutMs: 600_000 });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (downloaded.code !== 0) {
|
|
181
|
+
// **不要删目录**:yt-dlp 的 .part 是断点续传的本钱。
|
|
182
|
+
// 原来这里 `rm -rf` 掉整个缓存目录,于是网络一抖就"下到一半清零、从头再来"——
|
|
183
|
+
// 用户实测表现为"越下越慢"(繁星-夏夜反馈)。残留的 .part 由 pruneMedia 按时间清。
|
|
184
|
+
throw new Error(explainYtdlpError(downloaded.stderr, downloaded.code));
|
|
185
|
+
}
|
|
186
|
+
// yt-dlp 有时会把 DASH 流写成 video.f100022.mp4(格式 id 进了文件名),
|
|
187
|
+
// 而不是 --merge-output-format 期望的 video.mp4。文件名不是容器判定的依据:
|
|
188
|
+
// 取目录里实际产出、最大的那个视频文件,收敛到稳定的 video.mp4 再交给管线。
|
|
189
|
+
let st = await stat(target).catch(() => null);
|
|
190
|
+
if (!st || st.size === 0) {
|
|
191
|
+
const candidates = [];
|
|
192
|
+
const audioOnly = [];
|
|
193
|
+
for (const name of await readdir(dir).catch(() => [])) {
|
|
194
|
+
if (!name.startsWith('video.') || /\.(part|ytdl|temp)$/i.test(name)) continue;
|
|
195
|
+
const ext = name.slice(name.lastIndexOf('.')).toLowerCase();
|
|
196
|
+
try {
|
|
197
|
+
const info = await stat(join(dir, name));
|
|
198
|
+
if (!info.isFile() || info.size === 0) continue;
|
|
199
|
+
if (AUDIO_EXTS.has(ext)) { audioOnly.push(name); continue; }
|
|
200
|
+
candidates.push({ path: join(dir, name), size: info.size, ext });
|
|
201
|
+
} catch { /* 半成品被并发删除 */ }
|
|
202
|
+
}
|
|
203
|
+
if (candidates.length === 0) {
|
|
204
|
+
if (audioOnly.length > 0) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`yt-dlp produced audio only (${audioOnly.join(', ')}): ` +
|
|
207
|
+
'this link gave no video stream to scan. Try again without --allow-anonymous, ' +
|
|
208
|
+
'or pass a local file path.',
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
throw new Error('yt-dlp reported success but produced no file');
|
|
212
|
+
}
|
|
213
|
+
candidates.sort((a, b) => {
|
|
214
|
+
const amp = a.ext === '.mp4' ? 1 : 0;
|
|
215
|
+
const bmp = b.ext === '.mp4' ? 1 : 0;
|
|
216
|
+
return bmp - amp || b.size - a.size;
|
|
217
|
+
});
|
|
218
|
+
await rm(target, { force: true });
|
|
219
|
+
await rename(candidates[0].path, target);
|
|
220
|
+
st = await stat(target);
|
|
221
|
+
}
|
|
222
|
+
// 目标清晰度:请求的和实际能给的取小 —— 这正是"片源判断"要留在清单里的东西
|
|
223
|
+
const zoomTarget = summary.heights.length > 0
|
|
224
|
+
? Math.min(zoomHeight, summary.maxHeight ?? zoomHeight)
|
|
225
|
+
: zoomHeight;
|
|
226
|
+
|
|
227
|
+
// 匿名/低档位拿到的副本可能**没有音轨**(B 站最低档只有画面),
|
|
228
|
+
// 于是整条音频链沉默(transcript=no-audio、meanLufs=null),用户以为是插件坏了。
|
|
229
|
+
// 这里明确区分"源本来就没声音"和"这次下载的副本没声音"(xingyueDanYang 报的观察)。
|
|
230
|
+
const sourceHasAudio = (summary.formats ?? []).some((f) => f.acodec && f.acodec !== 'none');
|
|
231
|
+
const localInfo = await probeVideo(target).catch(() => null);
|
|
232
|
+
const audioMissing = Boolean(localInfo && !localInfo.hasAudio && sourceHasAudio);
|
|
233
|
+
// 合流失败时 yt-dlp 会留下 video.<id>.mp4 + video.<id>.m4a 两个文件,而这里选了 mp4。
|
|
234
|
+
// 把原因记下来,清单才能说"装 ffmpeg",而不是误导用户再去换 cookies。
|
|
235
|
+
const companionAudio = audioMissing
|
|
236
|
+
? (await readdir(dir).catch(() => [])).filter((name) => {
|
|
237
|
+
if (!name.startsWith('video.') || /\.(part|ytdl|temp)$/i.test(name)) return false;
|
|
238
|
+
const ext = name.slice(name.lastIndexOf('.')).toLowerCase();
|
|
239
|
+
return AUDIO_EXTS.has(ext);
|
|
240
|
+
})
|
|
241
|
+
: [];
|
|
242
|
+
|
|
243
|
+
const source = {
|
|
244
|
+
kind: 'url',
|
|
245
|
+
...(audioMissing ? { audioMissing: true } : {}),
|
|
246
|
+
...(audioMissing && companionAudio.length > 0 ? { audioMissingReason: 'unmerged-dash' } : {}),
|
|
247
|
+
// 让下一次命中知道"这份坏缓存已经用哪个 ffmpeg 重试过";换了 ffmpeg 才值得再试。
|
|
248
|
+
...(audioMissing && isAbsolute(ffmpegPath) ? { audioMergeRetry: ffmpegPath } : {}),
|
|
249
|
+
url,
|
|
250
|
+
cached: false,
|
|
251
|
+
bytes: st.size,
|
|
252
|
+
scanHeight,
|
|
253
|
+
scanActual: wantHeight,
|
|
254
|
+
maxAvailable: summary.maxHeight,
|
|
255
|
+
availableHeights: summary.heights,
|
|
256
|
+
zoomTarget,
|
|
257
|
+
title: summary.title,
|
|
258
|
+
duration: summary.duration,
|
|
259
|
+
auth: authKind,
|
|
260
|
+
// 站点自己声明的登录门槛(subtitle / paywalled)—— 清单据此要求用户提供 cookies
|
|
261
|
+
...(Array.isArray(summary.loginGates) && summary.loginGates.length > 0
|
|
262
|
+
? { needLogin: summary.loginGates } : {}),
|
|
263
|
+
// 只有"匿名 + 确实拿不到目标档"才说一句。匿名但够高清时闭嘴 ——
|
|
264
|
+
// 早期版本无条件报错,实测把"匿名本来就有 1080P"的视频也拦了,纯属帮倒忙。
|
|
265
|
+
...((authKind === 'anonymous' && zoomTarget < zoomHeight) || authNote
|
|
266
|
+
? { authWarning: authNote ?? auth.warning } : {}),
|
|
267
|
+
...(zoomTarget < zoomHeight ? { degraded: [`source-max-${summary.maxHeight ?? '?'}p`] } : {}),
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// 落一份元信息,让"第二次看同一条链接"不用再解析(-J 要 2.4 s)。
|
|
271
|
+
// 里面**没有直链**:那是带签名的凭证,只活在进程内存里。
|
|
272
|
+
await writeFile(join(dir, 'meta.json'), JSON.stringify(source, null, 0), 'utf8').catch(() => {});
|
|
273
|
+
|
|
274
|
+
await pruneMedia({ dir: mediaDir(env), maxBytes: mediaMaxBytes(env) });
|
|
275
|
+
onProgress?.({ phase: 'done', bytes: st.size });
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
path: target,
|
|
279
|
+
// frameSource 只进管线,**不进 manifest** —— 直链是带签名的临时凭证
|
|
280
|
+
frameSource: zoomDirect
|
|
281
|
+
? { uri: zoomDirect.url, userAgent: zoomDirect.userAgent, referer: zoomDirect.referer, height: zoomDirect.height, expiresAt: zoomDirect.expiresAt }
|
|
282
|
+
: null,
|
|
283
|
+
source,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/* ------------------------------------------------------------------ 只探测不下载 */
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* 链接版的 probe:只跑 `-J`,**不下载**。
|
|
291
|
+
* 让模型在花掉 7 MB 和 10 秒之前,先知道"这条多长、最高能到多少"。
|
|
292
|
+
* @returns {Promise<{url:string, title:string|null, duration:number|null,
|
|
293
|
+
* heights:number[], maxHeight:number|null, auth:string}>}
|
|
294
|
+
*/
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 带 cookies 探测,并处理"有 cookies 反而更少"的真实事故:
|
|
298
|
+
* 过期/低权限的 SESSDATA 会让 B 站降级,实测同一支视频带 cookies 只有 480p、匿名却有 1080p。
|
|
299
|
+
* 只在 maxHeight ≤ 720 时多探一次(可疑才付这 3–5 秒)。
|
|
300
|
+
*
|
|
301
|
+
* @returns {{summary:object, authKind:string, warning?:string}}
|
|
302
|
+
*/
|
|
303
|
+
async function probeSummary({ url, auth, tool, env, run }) {
|
|
304
|
+
const args = ['-J', '--no-warnings', '--no-playlist'];
|
|
305
|
+
const out = {};
|
|
306
|
+
if (auth.cookiesPath) args.push('--cookies', auth.cookiesPath);
|
|
307
|
+
args.push(url);
|
|
308
|
+
const probed = await run(tool, args, { timeoutMs: 90_000 });
|
|
309
|
+
if (probed.code !== 0) throw new Error(explainYtdlpError(probed.stderr, probed.code));
|
|
310
|
+
let info;
|
|
311
|
+
try {
|
|
312
|
+
info = JSON.parse(probed.stdout);
|
|
313
|
+
} catch {
|
|
314
|
+
throw new Error('yt-dlp returned unparsable JSON while probing this link');
|
|
315
|
+
}
|
|
316
|
+
const summary = summariseInfo(unwrapSingle(info, url));
|
|
317
|
+
const raw = unwrapSingle(info, url);
|
|
318
|
+
if (!auth.cookiesPath || !(summary.maxHeight > 0 && summary.maxHeight <= 720)) {
|
|
319
|
+
return { summary, authKind: auth.kind, raw };
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
const anon = await run(tool, ['-J', '--no-warnings', '--no-playlist', url], { timeoutMs: 90_000 });
|
|
323
|
+
if (anon.code !== 0) return { summary, authKind: auth.kind, raw };
|
|
324
|
+
const anonInfo = unwrapSingle(JSON.parse(anon.stdout), url);
|
|
325
|
+
const a = summariseInfo(anonInfo);
|
|
326
|
+
if (a.maxHeight <= summary.maxHeight) return { summary, authKind: auth.kind, raw };
|
|
327
|
+
return {
|
|
328
|
+
summary: { ...a, title: a.title || summary.title },
|
|
329
|
+
raw: anonInfo,
|
|
330
|
+
authKind: 'anonymous',
|
|
331
|
+
warning: 'cookies 只允许 ' + summary.maxHeight + 'p,匿名反而能拿到 ' + a.maxHeight + 'p' +
|
|
332
|
+
' —— SESSDATA 可能过期或权限不足,建议重新导出 cookies.txt',
|
|
333
|
+
};
|
|
334
|
+
} catch {
|
|
335
|
+
return { summary, authKind: auth.kind, raw }; // 匿名探失败不影响主结果
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export async function probeUrl(input, opts = {}) {
|
|
340
|
+
const {
|
|
341
|
+
cookies, allowAnonymous = false, env = process.env, ytdlp, run = runProcess,
|
|
342
|
+
} = opts;
|
|
343
|
+
|
|
344
|
+
const url = assertFetchableUrl(input);
|
|
345
|
+
const auth = await resolveAuth({ cookies, allowAnonymous, env });
|
|
346
|
+
const tool = ytdlp || await discoverYtdlp({ env, run });
|
|
347
|
+
|
|
348
|
+
const { summary, authKind, warning } = await probeSummary({ url, auth, tool, env, run });
|
|
349
|
+
return {
|
|
350
|
+
url,
|
|
351
|
+
title: summary.title,
|
|
352
|
+
duration: summary.duration,
|
|
353
|
+
heights: summary.heights,
|
|
354
|
+
maxHeight: summary.maxHeight,
|
|
355
|
+
auth: authKind,
|
|
356
|
+
...(Array.isArray(summary.loginGates) && summary.loginGates.length > 0
|
|
357
|
+
? { needLogin: summary.loginGates } : {}),
|
|
358
|
+
...(warning ? { authWarning: warning } : {}),
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/* ------------------------------------------------------------------ 统一入口 */
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* pipeline 唯一要调的函数:本地路径原样返回,链接则换成本地文件。
|
|
366
|
+
* @returns {Promise<{path:string, source:object|null, frameSource:object|null}>}
|
|
367
|
+
*/
|
|
368
|
+
export async function resolveInput(input, opts = {}) {
|
|
369
|
+
if (!isHttpUrl(input)) return { path: input, source: null, frameSource: null };
|
|
370
|
+
const { path, source, frameSource } = await fetchMedia(input, opts);
|
|
371
|
+
return { path, source, frameSource };
|
|
372
|
+
}
|
|
373
|
+
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* flash.js — 给每个切点**打标签**,不删除任何一个。
|
|
3
|
+
*
|
|
4
|
+
* 为什么是"打标签"不是"过滤":删掉误检会让这段在插件眼里变成"完全静止的连续镜头",
|
|
5
|
+
* 反而丢了「这里一直在动」的信息。实测三个一镜到底的素材(体积雾/瀑布/手持),
|
|
6
|
+
* 误报的切点删不删对分格影响很小,但**留着它们**能让密度曲线知道"这附近有变化"。
|
|
7
|
+
*
|
|
8
|
+
* 所以这里的产出是 `{...cut, type, evidence}`:
|
|
9
|
+
* flash 亮度脉冲(闪电、闪白)—— 画面没换,只是亮了一下
|
|
10
|
+
* white 白闪**转场** —— 闪完画面换了,这是真剪辑
|
|
11
|
+
* black 黑场转场
|
|
12
|
+
* hardcut 硬切 —— 一帧完成
|
|
13
|
+
* dissolve 溶解 —— 摊在好几帧
|
|
14
|
+
* motion 疑似运动 —— 前后都不安静,这个"切点"可能压根不是切点
|
|
15
|
+
*
|
|
16
|
+
* 判据(三条 AND,缺一不可,理由见 docs/看视频插件-闪光误判-方案.md):
|
|
17
|
+
* pulse > PULSE_MIN 整帧亮度确实冲高过
|
|
18
|
+
* nv < NV_MAX 冲高之后**回到了原样**(净位移极小)
|
|
19
|
+
* corr > CORR_MIN 而且**结构没变**(只是变亮,不是换了画面)
|
|
20
|
+
*
|
|
21
|
+
* 真实素材实测:闪电 pulse=151/nv=3.9/corr=0.996;真切点 pulse=36/nv=72.7/corr=0.49。
|
|
22
|
+
* 白闪转场 nv 大(画面换了)所以不会被误判成 flash。
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { FP_W, FP_H } from './scan.js';
|
|
26
|
+
|
|
27
|
+
/** 亮度脉冲下限:真实弱闪电实测 30,真切点最高 36(靠 nv 挡住,不靠这条) */
|
|
28
|
+
export const PULSE_MIN = 20;
|
|
29
|
+
/** 净位移上限:闪电 1.3–3.9(真实素材),真切点 72.7–74.8。阈值 8 落在中间,余量 20 倍 */
|
|
30
|
+
export const NV_MAX = 8;
|
|
31
|
+
/** 结构相关度下限:闪电 0.996–0.999,真切 0.49–0.50 */
|
|
32
|
+
export const CORR_MIN = 0.85;
|
|
33
|
+
/** 窗口半宽(秒)。不写死帧数:6fps 素材上 6 帧是 1 秒,早就不是"闪一下"了 */
|
|
34
|
+
export const DELTA_SEC = 0.24;
|
|
35
|
+
/** 全局平移补偿的搜索半径(16×9 指纹上的格数) */
|
|
36
|
+
export const DX_RANGE = 8;
|
|
37
|
+
|
|
38
|
+
const mean = (arr, from = 0, to = arr.length) => {
|
|
39
|
+
let s = 0;
|
|
40
|
+
for (let i = from; i < to; i++) s += arr[i];
|
|
41
|
+
return to > from ? s / (to - from) : 0;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const fpDiff = (a, b) => {
|
|
45
|
+
let s = 0;
|
|
46
|
+
for (let i = 0; i < a.length; i++) s += Math.abs(a[i] - b[i]);
|
|
47
|
+
return s / a.length;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function shiftFp(a, dx) {
|
|
51
|
+
const out = new Uint8Array(a.length);
|
|
52
|
+
const d = ((Math.round(dx) % FP_W) + FP_W) % FP_W;
|
|
53
|
+
for (let y = 0; y < FP_H; y++) {
|
|
54
|
+
const row = y * FP_W;
|
|
55
|
+
for (let x = 0; x < FP_W; x++) out[row + x] = a[row + ((x - d + FP_W) % FP_W)];
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 结构相关度:各自去均值、除以标准差后的余弦相似度(对整帧提亮免疫) */
|
|
61
|
+
function structCorr(a, b) {
|
|
62
|
+
const ma = mean(a);
|
|
63
|
+
const mb = mean(b);
|
|
64
|
+
let sa = 0;
|
|
65
|
+
let sb = 0;
|
|
66
|
+
let dot = 0;
|
|
67
|
+
for (let i = 0; i < a.length; i++) {
|
|
68
|
+
const x = a[i] - ma;
|
|
69
|
+
const y = b[i] - mb;
|
|
70
|
+
sa += x * x;
|
|
71
|
+
sb += y * y;
|
|
72
|
+
dot += x * y;
|
|
73
|
+
}
|
|
74
|
+
const d = Math.sqrt(sa) * Math.sqrt(sb);
|
|
75
|
+
return d < 1e-9 ? 0 : dot / d;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 单个切点处的证据。
|
|
80
|
+
*
|
|
81
|
+
* @param {{prints:Uint8Array[], means:number[], t:number, fps:number, deltaSec?:number}} opts
|
|
82
|
+
* t:切点时刻(秒);prints/means 的下标是帧号
|
|
83
|
+
*/
|
|
84
|
+
export function flashEvidence({ prints, means, t, fps, deltaSec = DELTA_SEC, scores }) {
|
|
85
|
+
const delta = Math.max(1, Math.round(deltaSec * fps));
|
|
86
|
+
const center = Math.round(t * fps);
|
|
87
|
+
const lo = Math.max(0, center - delta);
|
|
88
|
+
const hi = Math.min(prints.length - 1, center + delta);
|
|
89
|
+
if (hi <= lo) return null;
|
|
90
|
+
|
|
91
|
+
// ① 亮度脉冲:相对两端基线的最大正向偏离
|
|
92
|
+
const base = (means[lo] + means[hi]) / 2;
|
|
93
|
+
let pulse = 0;
|
|
94
|
+
let minV = 255;
|
|
95
|
+
let maxV = 0;
|
|
96
|
+
for (let i = lo; i <= hi; i++) {
|
|
97
|
+
pulse = Math.max(pulse, means[i] - base);
|
|
98
|
+
minV = Math.min(minV, means[i]);
|
|
99
|
+
maxV = Math.max(maxV, means[i]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ② 净位移:先做全局平移补偿,再取残差(挡快速甩镜)
|
|
103
|
+
let nv = Infinity;
|
|
104
|
+
let dx = 0;
|
|
105
|
+
let shifted = prints[lo];
|
|
106
|
+
for (let k = -DX_RANGE; k <= DX_RANGE; k++) {
|
|
107
|
+
const s = shiftFp(prints[lo], k);
|
|
108
|
+
const v = fpDiff(s, prints[hi]);
|
|
109
|
+
if (v < nv) { nv = v; dx = k; shifted = s; }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ③ 结构相关度(用补偿后的那一对帧,和 nv 同一个对齐点)
|
|
113
|
+
const corr = structCorr(shifted, prints[hi]);
|
|
114
|
+
|
|
115
|
+
// ④ 过渡集中度:窗口内的分数是不是集中在少数几帧(硬切高、溶解低)
|
|
116
|
+
let conc = 0;
|
|
117
|
+
if (Array.isArray(scores) && scores.length) {
|
|
118
|
+
const seg = [];
|
|
119
|
+
// scores 的第 i 项是「第 i 帧相对第 i-1 帧」的分数,所以下标要减一
|
|
120
|
+
for (let i = lo; i <= hi; i++) {
|
|
121
|
+
const s = scores[i - 1];
|
|
122
|
+
if (Number.isFinite(s)) seg.push(s);
|
|
123
|
+
}
|
|
124
|
+
if (seg.length >= 2) {
|
|
125
|
+
const sorted = [...seg].sort((x, y) => x - y);
|
|
126
|
+
const med = sorted[Math.floor(sorted.length / 2)];
|
|
127
|
+
const sum = seg.reduce((x, y) => x + y, 0);
|
|
128
|
+
const mx = sorted[sorted.length - 1];
|
|
129
|
+
const den = sum - med * seg.length;
|
|
130
|
+
conc = den > 0.5 ? (mx - med) / den : 0;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
pulse: +pulse.toFixed(1), nv: +nv.toFixed(1), corr: +corr.toFixed(3), dx,
|
|
136
|
+
minV: +minV.toFixed(0), maxV: +maxV.toFixed(0), conc: +conc.toFixed(2),
|
|
137
|
+
isFlash: pulse > PULSE_MIN && nv < NV_MAX && corr > CORR_MIN,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 给一批切点打标签。**不删除任何一个**,只补 `type` 和 `evidence`。
|
|
143
|
+
*
|
|
144
|
+
* 护栏(防止把一镜到底的素材全判成 flash):只有"前后 2δ 内没有真切锚点"的切点
|
|
145
|
+
* 才允许判 flash —— 一段连续闪光里每一刀都会满足判据,但那不是"误检",是这段本身在闪。
|
|
146
|
+
* 反过来,如果附近有真切锚点(nv 大),说明画面真的换了,这一刀不该被压成 flash。
|
|
147
|
+
*
|
|
148
|
+
* @param {Array<{t:number}>} cuts
|
|
149
|
+
* @param {{prints?:Uint8Array[], means?:number[], fps?:number, scores?:number[]}} data
|
|
150
|
+
* @returns {Array<object>} 新数组,元素是 {...cut, type, evidence}
|
|
151
|
+
*/
|
|
152
|
+
export function tagCuts(cuts, { prints, means, fps = 25, scores } = {}) {
|
|
153
|
+
if (!Array.isArray(cuts)) return [];
|
|
154
|
+
if (!Array.isArray(prints) || !Array.isArray(means) || prints.length === 0) {
|
|
155
|
+
// 没有逐帧数据(例如复用缓存):保持原样,只补一个中性标签
|
|
156
|
+
return cuts.map((c) => ({ ...c, type: null, evidence: null }));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const rows = cuts.map((c) => ({
|
|
160
|
+
...c,
|
|
161
|
+
evidence: flashEvidence({ prints, means, t: c.t, fps, scores }),
|
|
162
|
+
type: null,
|
|
163
|
+
}));
|
|
164
|
+
|
|
165
|
+
for (const r of rows) {
|
|
166
|
+
const ev = r.evidence;
|
|
167
|
+
if (!ev) { r.type = 'unknown'; continue; }
|
|
168
|
+
// **不再加"附近有没有真切锚点"的护栏**:早先的版本要求「前后 2δ 内没有真切点」
|
|
169
|
+
// 才允许判 flash,实测会把"闪一下紧接着真剪辑"这种正常素材也挡掉(两个切点隔 0.4s,
|
|
170
|
+
// 比 2δ=0.48s 还近)。既然现在只打标签、不删切点,标签错的代价只是表述不准,
|
|
171
|
+
// 而漏标会让模型误以为"这里没有闪"。所以直接按证据说话。
|
|
172
|
+
if (ev.isFlash) r.type = 'flash';
|
|
173
|
+
else if (ev.minV < 12) r.type = 'black';
|
|
174
|
+
else if (ev.maxV > 245 && ev.nv > 10) r.type = 'white';
|
|
175
|
+
else if (ev.nv >= NV_MAX) r.type = ev.conc >= 0.45 ? 'hardcut' : 'dissolve';
|
|
176
|
+
else r.type = 'motion';
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return rows;
|
|
180
|
+
}
|