@aswless_854771076/ai_short_studio_cli 0.1.156 → 0.1.158
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/README.md +1 -1
- package/dist/commands/canvas/document/get.js +3 -3
- package/dist/commands/canvas/document/save.js +8 -2
- package/dist/commands/canvas/documents.js +1 -1
- package/dist/commands/canvas/workflow/status.js +1 -1
- package/dist/domain/canvas-schema-key.d.ts +2 -0
- package/dist/domain/canvas-schema-key.js +21 -0
- package/dist/domain/vvicat-api.js +1 -1
- package/package.json +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/SKILL.md +24 -24
- package/skills/using-vvicat-ai-short-studio-cli/references/agent-recovery.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/assets-and-storyboard.md +11 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/commands/canvas.md +25 -5
- package/skills/using-vvicat-ai-short-studio-cli/references/humanizer/SOURCE.md +9 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/humanizer/humanizer.md +408 -5
- package/skills/using-vvicat-ai-short-studio-cli/references/project-and-canvas.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/SKILL.md +17 -31
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/generate-character-images.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/generate-character-profiles.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/generate-drama-art-style.md +3 -3
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/generate-prop-assets.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/generate-scene-assets.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/manage-drama-art-styles.md +3 -3
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/manage-drama-assets.md +4 -4
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/modules/ideate-drama-from-market/prompts/market_inspiration.en.txt +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/modules/ideate-drama-from-market/prompts/market_inspiration.zh.txt +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/modules/plan-drama-production/prompts/production_plan.en.txt +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/assets/plan-drama-assets.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/codex-contracts.md +3 -3
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/creation/analyze-drama-source.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/creation/define-drama-brief.md +1 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/creation/design-drama-bible.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/creation/humanizer.md +4 -4
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/creation/outline-drama-series.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/creation/short-drama.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/creation/write-drama-director-book.md +1 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/creation/write-drama-episode.md +1 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/editing/edit-deliver-drama.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/editing/edit-drama-timeline.md +4 -5
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/editing/remotion-best-practices.md +4 -5
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/editing-workflow.md +8 -8
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/feature-completeness.md +25 -25
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/configure-generation-providers.md +5 -11
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/design-drama-audio.md +4 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/drama-generation-service.md +6 -6
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/generate-drama-videos.md +4 -4
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/generate-storyboard-images.md +3 -3
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/monitor-drama-tasks.md +9 -7
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/transform-drama-media.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/write-drama-video-prompts.md +9 -8
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/analyze-drama-market.md +8 -8
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/ideate-drama-from-market/market-inspiration.schema.json +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/ideate-drama-from-market.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/README.md +59 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/analyze.mjs +517 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/analyze.test.mjs +354 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/juchacha-client.mjs +188 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/juchacha-client.test.mjs +218 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/normalize.mjs +458 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/normalize.test.mjs +236 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/report.mjs +69 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/store.mjs +341 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/store.test.mjs +302 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/module-map.json +43 -133
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/music-catalog-providers.md +3 -3
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/operations/manage-drama-projects.md +5 -5
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/operations/orchestrate-short-drama.md +7 -8
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/operations/recover-drama-pipeline.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/operations/short-drama-skill-index.md +7 -7
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/operations/use-short-drama-studio.md +4 -6
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/pipeline.md +40 -65
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/project-spec-v1.md +91 -131
- package/skills/using-vvicat-ai-short-studio-cli/references/{hypit/playbooks/craft → short-drama/prompt}/h3-prompt-writing.md +4 -4
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/prompt/prompt-craft.md +186 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/prompt/seedance-prompting.md +64 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/prompt-skill-index.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/recreation/recreation-qa.md +87 -0
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/review/review-drama-script.md +2 -2
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/review/review-drama-shots.md +6 -6
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/storyboard/build-drama-storyboard.md +1 -3
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/storyboard/design-fight-video.md +0 -4
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/storyboard/direct-blender-previz/direction-contract.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/storyboard/direct-blender-previz.md +1 -1
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/storyboard/generate-blender-previz.md +5 -10
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/storyboard/plan-drama-production.md +2 -6
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/storyboard/plan-shot-continuity.md +4 -4
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/usage-guide.md +28 -70
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/SKILL.md +0 -447
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/creation/brief.md +0 -93
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/creation/project-files.md +0 -246
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/creation/reference-video.md +0 -266
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/creation/script-and-time.md +0 -253
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/creation/transformations.md +0 -141
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/environment/distribution.md +0 -176
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/environment/local-tools.md +0 -411
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/environment/model-and-provider.md +0 -275
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/environment/profile.md +0 -286
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/asset-and-shot-preproduction.md +0 -193
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/b-roll.md +0 -94
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/caption-tracking.md +0 -125
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/captions.md +0 -252
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/examples/conversation-images.md +0 -218
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/examples/image-direction.md +0 -123
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/generated-dependencies.md +0 -38
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/graphic-compositions.md +0 -85
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/image-direction.md +0 -95
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/motion-graphics.md +0 -68
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/recreation-policy.md +0 -51
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/screen-demonstrations.md +0 -51
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/shot-production-contracts.md +0 -161
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/sound-mix.md +0 -76
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/video-direction.md +0 -433
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/voice-and-performance.md +0 -224
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/craft/voice-direction.md +0 -99
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/narration-led-demo.md +0 -87
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/presenter-led-explainer.md +0 -160
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/ranking-listicle.md +0 -71
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/reference-recreation-canvas.md +0 -19
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/short-drama-workflow.md +0 -165
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/short-drama.md +0 -88
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/street-interview.md +0 -92
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/talking-head.md +0 -82
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/formats/two-person-podcast.md +0 -101
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/playbooks/index.md +0 -77
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/audio-presentation.md +0 -49
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/authoring.md +0 -228
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/browser-capture.md +0 -112
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/builds.md +0 -330
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/caption-authoring.md +0 -156
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/caption-presentation.md +0 -66
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/component-design.md +0 -217
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/component-sharing.md +0 -150
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/component-visuals.md +0 -152
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/examples/detail.svrun +0 -8
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/examples/direction.svs +0 -14
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/examples/look.svs +0 -6
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/examples/material.svrun +0 -5
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/examples/production.svml +0 -73
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/examples/production.svrun +0 -5
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/examples/visuals.ts +0 -62
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/fonts-and-text.md +0 -138
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/image-operations.md +0 -102
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/index.md +0 -73
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/media-presentation.md +0 -111
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/media.md +0 -246
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/performance.md +0 -114
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/prompt-kits.md +0 -165
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/rendering.md +0 -141
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/review.md +0 -211
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/runs.md +0 -151
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/script-syntax.md +0 -236
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/snapshots.md +0 -90
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/sound.md +0 -75
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/source-syntax.md +0 -163
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/spatial.md +0 -189
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/studio-companions.md +0 -186
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/studio.md +0 -249
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/system.md +0 -169
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/timeline.md +0 -74
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/timing.md +0 -96
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/track-authoring.md +0 -215
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/tracks.md +0 -67
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/video-downloads.md +0 -47
- package/skills/using-vvicat-ai-short-studio-cli/references/hypit/production/vocabulary.md +0 -119
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/README.md +0 -11
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/comfly-provider.md +0 -12
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/generation/seedance-community-skills.md +0 -23
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/recreation/publish-drama-references/litterbox.md +0 -5
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/runninghub-provider.md +0 -33
- package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/starrouter-provider.md +0 -53
- package/skills/using-vvicat-ai-short-studio-cli/references/video-model-routing.md +0 -10
- package/skills/using-vvicat-ai-short-studio-cli/references/video-prompt-spec.md +0 -32
- /package/skills/using-vvicat-ai-short-studio-cli/references/{short-drama/assets/modules/humanizer → humanizer}/LICENSE +0 -0
- /package/skills/using-vvicat-ai-short-studio-cli/references/{hypit/playbooks/craft → short-drama/prompt}/examples/h3-base-prompt-writing.md +0 -0
- /package/skills/using-vvicat-ai-short-studio-cli/references/{hypit/playbooks/craft → short-drama/prompt}/examples/h3-reference-prompt-writing.md +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { createJuchachaClient, dateSignature, rankingDefinitions } from './juchacha-client.mjs'
|
|
4
|
+
|
|
5
|
+
test('上海日期固定样本生成已验证签名', () => {
|
|
6
|
+
assert.equal(dateSignature(new Date('2026-09-16T08:00:00Z')), '0cdf73ff2b30ed7aa6206fde112bee77')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('上海跨午夜日期使用 Asia/Shanghai 而非 UTC 日期', () => {
|
|
10
|
+
assert.equal(dateSignature(new Date('2026-09-16T16:00:00Z')), '6c2a675559f7caa08b73359ccb75a22d')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('热力榜先解析最新日期再请求 Top 30', async () => {
|
|
14
|
+
const calls = []
|
|
15
|
+
const fetchImpl = async (url, options) => {
|
|
16
|
+
calls.push({ url: String(url), options })
|
|
17
|
+
return Response.json(calls.length === 1
|
|
18
|
+
? { statusCode: 200, content: { day: '2026-09-14' }, page: null, message: null }
|
|
19
|
+
: { statusCode: 200, content: [{ ranking: 1, playletName: '样例剧' }], page: { pageId: 1, pageSize: 30 }, message: null })
|
|
20
|
+
}
|
|
21
|
+
const client = createJuchachaClient({ fetchImpl, now: () => new Date('2026-09-16T08:00:00Z') })
|
|
22
|
+
const result = await client.fetchRanking('hot')
|
|
23
|
+
assert.equal(result.content[0].playletName, '样例剧')
|
|
24
|
+
assert.match(calls[1].url, /day=2026-09-14/)
|
|
25
|
+
assert.equal(calls[1].options.headers.S, '0cdf73ff2b30ed7aa6206fde112bee77')
|
|
26
|
+
assert.equal(calls[1].options.headers.authentication, '')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('8 类榜单定义完整且收入榜不请求日期接口', () => {
|
|
30
|
+
assert.deepEqual(Object.keys(rankingDefinitions), ['hot', 'motion', 'motion-ai', 'motion-comedy', 'douyin', 'kuaishou', 'hongguo', 'income'])
|
|
31
|
+
assert.equal(rankingDefinitions.income.dateEndpoint, null)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
function response(payload, init = {}) {
|
|
35
|
+
return new Response(JSON.stringify(payload), {
|
|
36
|
+
status: 200,
|
|
37
|
+
headers: { 'content-type': 'application/json' },
|
|
38
|
+
...init,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
test('收入榜直接请求榜单且固定分页', async () => {
|
|
43
|
+
const calls = []
|
|
44
|
+
const client = createJuchachaClient({
|
|
45
|
+
fetchImpl: async (url, options) => {
|
|
46
|
+
calls.push({ url: String(url), options })
|
|
47
|
+
return response({ statusCode: 200, content: [], page: { pageId: 1, pageSize: 30 }, message: null })
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
await client.fetchRanking('income')
|
|
51
|
+
assert.equal(calls.length, 1)
|
|
52
|
+
assert.match(calls[0].url, /pageId=1/)
|
|
53
|
+
assert.match(calls[0].url, /pageSize=30/)
|
|
54
|
+
assert.equal(calls[0].options.headers.authentication, '')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('动态漫三个日期端点分别带正确 rankType 且不带分页', async () => {
|
|
58
|
+
for (const [type, rankType] of [['motion', 1], ['motion-ai', 2], ['motion-comedy', 3]]) {
|
|
59
|
+
const calls = []
|
|
60
|
+
const client = createJuchachaClient({
|
|
61
|
+
fetchImpl: async (url) => {
|
|
62
|
+
calls.push(String(url))
|
|
63
|
+
return calls.length === 1
|
|
64
|
+
? response({ statusCode: 200, content: { day: '2026-09-14' } })
|
|
65
|
+
: response({ statusCode: 200, content: [] })
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
await client.fetchRanking(type)
|
|
69
|
+
const dateUrl = new URL(calls[0])
|
|
70
|
+
assert.equal(dateUrl.searchParams.get('rankType'), String(rankType))
|
|
71
|
+
assert.equal(dateUrl.searchParams.has('pageId'), false)
|
|
72
|
+
assert.equal(dateUrl.searchParams.has('pageSize'), false)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('榜单定义及参数逐层冻结,客户端之间不会共享可变配置', async () => {
|
|
77
|
+
assert.equal(Object.isFrozen(rankingDefinitions), true)
|
|
78
|
+
assert.equal(Object.isFrozen(rankingDefinitions.motion), true)
|
|
79
|
+
assert.equal(Object.isFrozen(rankingDefinitions.motion.params), true)
|
|
80
|
+
assert.throws(() => { rankingDefinitions.motion.listEndpoint = '/tampered' }, TypeError)
|
|
81
|
+
assert.throws(() => { rankingDefinitions.motion.params.rankType = 99 }, TypeError)
|
|
82
|
+
|
|
83
|
+
const urls = []
|
|
84
|
+
const fetchImpl = async (url) => {
|
|
85
|
+
urls.push(String(url))
|
|
86
|
+
return response({ statusCode: 200, content: [] })
|
|
87
|
+
}
|
|
88
|
+
const first = createJuchachaClient({ fetchImpl })
|
|
89
|
+
const second = createJuchachaClient({ fetchImpl })
|
|
90
|
+
await first.fetchRanking('motion', { day: '2026-09-14' })
|
|
91
|
+
await second.fetchRanking('motion', { day: '2026-09-14' })
|
|
92
|
+
assert.equal(new URL(urls[0]).searchParams.get('rankType'), '1')
|
|
93
|
+
assert.equal(new URL(urls[1]).searchParams.get('rankType'), '1')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('周期参数只能选择 day、week、month 之一', async () => {
|
|
97
|
+
const client = createJuchachaClient({ fetchImpl: async () => response({ statusCode: 200, content: [] }) })
|
|
98
|
+
await assert.rejects(
|
|
99
|
+
client.fetchRanking('income', { day: '2026-09-14', week: '2026-09-08' }),
|
|
100
|
+
(error) => error.code === 'JUCHACHA_INVALID_RESPONSE' && error.endpoint === null,
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('合法 week 和 month 周期准确传入榜单请求', async () => {
|
|
105
|
+
const calls = []
|
|
106
|
+
const client = createJuchachaClient({
|
|
107
|
+
fetchImpl: async (url) => {
|
|
108
|
+
calls.push(String(url))
|
|
109
|
+
return response({ statusCode: 200, content: [] })
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
await client.fetchRanking('income', { week: '2026-09-14' })
|
|
113
|
+
await client.fetchRanking('income', { month: '2026-09' })
|
|
114
|
+
const weekUrl = new URL(calls[0])
|
|
115
|
+
const monthUrl = new URL(calls[1])
|
|
116
|
+
assert.equal(weekUrl.searchParams.get('week'), '2026-09-14')
|
|
117
|
+
assert.equal(weekUrl.searchParams.has('month'), false)
|
|
118
|
+
assert.equal(monthUrl.searchParams.get('month'), '2026-09')
|
|
119
|
+
assert.equal(monthUrl.searchParams.has('week'), false)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('超时错误不暴露请求头', async () => {
|
|
123
|
+
const client = createJuchachaClient({
|
|
124
|
+
fetchImpl: async () => { throw new DOMException('timed out', 'TimeoutError') },
|
|
125
|
+
})
|
|
126
|
+
await assert.rejects(client.fetchRanking('income'), (error) => {
|
|
127
|
+
assert.equal(error.code, 'JUCHACHA_TIMEOUT')
|
|
128
|
+
assert.equal(error.endpoint, '/playlet/getPlayletRevenueRankData')
|
|
129
|
+
assert.equal(error.headers, undefined)
|
|
130
|
+
assert.doesNotMatch(JSON.stringify(error), /authentication|0cdf|Bearer/i)
|
|
131
|
+
return true
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('AbortSignal.timeout 实际触发 options.signal 中止并映射超时', async () => {
|
|
136
|
+
const client = createJuchachaClient({
|
|
137
|
+
timeoutMs: 5,
|
|
138
|
+
fetchImpl: async (_url, options) => new Promise((resolve, reject) => {
|
|
139
|
+
const abort = () => reject(new DOMException('request timed out', 'TimeoutError'))
|
|
140
|
+
if (options.signal.aborted) abort()
|
|
141
|
+
else options.signal.addEventListener('abort', abort, { once: true })
|
|
142
|
+
}),
|
|
143
|
+
})
|
|
144
|
+
await assert.rejects(client.fetchRanking('income'), (error) => error.code === 'JUCHACHA_TIMEOUT')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('response.json 阶段被中止时仍返回超时错误', async (t) => {
|
|
148
|
+
for (const name of ['AbortError', 'TimeoutError']) {
|
|
149
|
+
await t.test(name, async () => {
|
|
150
|
+
const client = createJuchachaClient({
|
|
151
|
+
fetchImpl: async () => ({
|
|
152
|
+
ok: true,
|
|
153
|
+
status: 200,
|
|
154
|
+
json: async () => { throw new DOMException('request aborted', name) },
|
|
155
|
+
}),
|
|
156
|
+
})
|
|
157
|
+
await assert.rejects(client.fetchRanking('income'), (error) => {
|
|
158
|
+
assert.equal(error.code, 'JUCHACHA_TIMEOUT')
|
|
159
|
+
assert.equal(error.endpoint, '/playlet/getPlayletRevenueRankData')
|
|
160
|
+
return true
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('HTTP 错误、业务错误和脏 JSON 使用不同错误码', async (t) => {
|
|
167
|
+
await t.test('HTTP 错误', async () => {
|
|
168
|
+
const client = createJuchachaClient({ fetchImpl: async () => new Response('bad gateway', { status: 502 }) })
|
|
169
|
+
await assert.rejects(client.fetchRanking('income'), (error) => error.code === 'JUCHACHA_HTTP_ERROR')
|
|
170
|
+
})
|
|
171
|
+
await t.test('业务错误', async () => {
|
|
172
|
+
const client = createJuchachaClient({ fetchImpl: async () => response({ statusCode: 400, message: '参数错误' }) })
|
|
173
|
+
await assert.rejects(client.fetchRanking('income'), (error) => error.code === 'JUCHACHA_API_ERROR' && error.message === '参数错误')
|
|
174
|
+
})
|
|
175
|
+
await t.test('脏 JSON', async () => {
|
|
176
|
+
const client = createJuchachaClient({ fetchImpl: async () => new Response('{not-json', { status: 200 }) })
|
|
177
|
+
await assert.rejects(client.fetchRanking('income'), (error) => error.code === 'JUCHACHA_INVALID_RESPONSE')
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
test('未知榜单类型只接受 rankingDefinitions 自有属性', async () => {
|
|
182
|
+
let calls = 0
|
|
183
|
+
const client = createJuchachaClient({
|
|
184
|
+
fetchImpl: async () => {
|
|
185
|
+
calls += 1
|
|
186
|
+
return response({ statusCode: 200, content: [] })
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
for (const type of ['not-a-ranking', 'constructor', 'toString', '__proto__']) {
|
|
190
|
+
await assert.rejects(client.fetchRanking(type), (error) => {
|
|
191
|
+
assert.equal(error.code, 'JUCHACHA_INVALID_RESPONSE')
|
|
192
|
+
assert.equal(error.endpoint, null)
|
|
193
|
+
return true
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
assert.equal(calls, 0)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('fetchAllRankings 保留成功榜单并记录失败榜单', async () => {
|
|
200
|
+
const calls = []
|
|
201
|
+
const client = createJuchachaClient({
|
|
202
|
+
fetchImpl: async (url) => {
|
|
203
|
+
calls.push(String(url))
|
|
204
|
+
if (String(url).includes('/playlet/listHotRanking')) throw new Error('network down')
|
|
205
|
+
return response({ statusCode: 200, content: [{ ranking: 1 }], page: { pageId: 1, pageSize: 30 } })
|
|
206
|
+
},
|
|
207
|
+
})
|
|
208
|
+
const result = await client.fetchAllRankings({ day: '2026-09-14' })
|
|
209
|
+
assert.equal(calls.length, 8)
|
|
210
|
+
assert.deepEqual(result.rankings.income.content, [{ ranking: 1 }])
|
|
211
|
+
assert.equal(result.failures.length, 1)
|
|
212
|
+
assert.deepEqual(result.failures[0], {
|
|
213
|
+
type: 'hot',
|
|
214
|
+
code: 'JUCHACHA_HTTP_ERROR',
|
|
215
|
+
endpoint: '/playlet/listHotRanking',
|
|
216
|
+
message: '剧查查请求失败',
|
|
217
|
+
})
|
|
218
|
+
})
|
package/skills/using-vvicat-ai-short-studio-cli/references/short-drama/market/scripts/normalize.mjs
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
|
|
3
|
+
const TITLE_ROOTS = Object.freeze([
|
|
4
|
+
[['都市日常'], ['都市情感', '都市']],
|
|
5
|
+
[['总裁'], ['霸道总裁', '霸总', '总裁']],
|
|
6
|
+
[['甜宠'], ['甜宠']],
|
|
7
|
+
[['末日重生'], ['末日重生']],
|
|
8
|
+
[['重生', '穿越'], ['重生穿越']],
|
|
9
|
+
[['重生'], ['重生']],
|
|
10
|
+
[['穿越'], ['穿越']],
|
|
11
|
+
[['战神归来'], ['战神归来', '战神']],
|
|
12
|
+
[['古装宫廷'], ['古装宫廷', '宫廷', '宫斗']],
|
|
13
|
+
[['逆袭'], ['励志逆袭', '逆袭']],
|
|
14
|
+
[['家庭伦理'], ['家庭伦理']],
|
|
15
|
+
[['萌宝'], ['萌宝']],
|
|
16
|
+
[['悬疑推理'], ['悬疑探案', '悬疑', '探案', '推理']],
|
|
17
|
+
[['软科幻'], ['软科幻', '科幻']],
|
|
18
|
+
[['喜剧'], ['喜剧']],
|
|
19
|
+
])
|
|
20
|
+
|
|
21
|
+
const TOPIC_TAXONOMY = Object.freeze([
|
|
22
|
+
[['重生', '穿越'], ['重生穿越']],
|
|
23
|
+
[['古装宫廷'], ['古装宫廷', '宫廷', '宫斗', '古装']],
|
|
24
|
+
[['都市日常'], ['都市情感', '都市', '职场', '爱情', '情感', '日常']],
|
|
25
|
+
[['总裁'], ['霸道总裁', '霸总', '总裁']],
|
|
26
|
+
[['悬疑推理'], ['悬疑探案', '悬疑', '探案', '推理']],
|
|
27
|
+
[['逆袭'], ['励志逆袭', '逆袭']],
|
|
28
|
+
[['家庭伦理'], ['家庭伦理', '婆媳', '伦理', '家庭']],
|
|
29
|
+
[['末日重生'], ['末日重生', '末日', '丧尸']],
|
|
30
|
+
[['重生'], ['重生']],
|
|
31
|
+
[['穿越'], ['穿越']],
|
|
32
|
+
[['战神归来'], ['战神归来', '战神']],
|
|
33
|
+
[['软科幻'], ['软科幻', '科幻']],
|
|
34
|
+
[['萌宝'], ['萌宝']],
|
|
35
|
+
[['喜剧'], ['喜剧', '搞笑']],
|
|
36
|
+
])
|
|
37
|
+
|
|
38
|
+
const NON_TOPIC_TAGS = new Set([
|
|
39
|
+
'真人', '短剧', '微短剧', '短视频', '已完结', '完结', '连载中', '连载', '热播', '新剧', '上新', '独播',
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
const AUDIENCE_LABELS = new Map([
|
|
43
|
+
['男频', '男频'],
|
|
44
|
+
['女频', '女频'],
|
|
45
|
+
['男女通吃', '男女通吃'],
|
|
46
|
+
['全年龄', '全年龄'],
|
|
47
|
+
])
|
|
48
|
+
|
|
49
|
+
const ERA_LABELS = new Map([
|
|
50
|
+
['现代', '现代'],
|
|
51
|
+
['当代', '当代'],
|
|
52
|
+
['近现代', '近现代'],
|
|
53
|
+
['古代', '古代'],
|
|
54
|
+
['古装', '古装'],
|
|
55
|
+
['民国', '民国'],
|
|
56
|
+
['未来', '未来'],
|
|
57
|
+
['末世', '末世'],
|
|
58
|
+
])
|
|
59
|
+
|
|
60
|
+
const FIELD_ALIASES = Object.freeze({
|
|
61
|
+
id: ['playletId', 'playletID', 'id', 'shortDramaId'],
|
|
62
|
+
title: ['playletName', 'name', 'title'],
|
|
63
|
+
ranking: ['ranking', 'rank', 'topNum'],
|
|
64
|
+
heatValue: ['consumeNum', 'hotValue', 'heatValue', 'playCount', 'playCountRaw', 'viewCount'],
|
|
65
|
+
growthValue: ['playCountAddRaw', 'growthValue', 'growth', 'increase', 'increaseValue', 'playCountAdd'],
|
|
66
|
+
isNew: ['newFlag', 'isNew', 'new'],
|
|
67
|
+
persistenceDays: ['persistenceDays', 'listDays', 'topDays'],
|
|
68
|
+
companies: ['relatedPartyCompany', 'companyNames', 'company'],
|
|
69
|
+
tags: ['playletTags', 'tags', 'genres', 'genre', 'topics', 'topic', 'subjectTags'],
|
|
70
|
+
audience: ['audience', 'targetAudience'],
|
|
71
|
+
era: ['era', 'period', 'timeType'],
|
|
72
|
+
format: ['format', 'contentFormat', 'playletFormat'],
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const COMPANY_ROLE_ALIASES = Object.freeze({
|
|
76
|
+
platform: ['platformList', 'relatedPartyCompany', 'playletUserList', 'playletUser'],
|
|
77
|
+
contractor: ['contractorList', 'contractorCompany'],
|
|
78
|
+
copyrightHolder: ['copyrightHolderList', 'copyrightHolderCompany'],
|
|
79
|
+
producer: ['producerList', 'manufacturer', 'companyNames', 'company'],
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
function isRecord(value) {
|
|
83
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function normalizedText(value) {
|
|
87
|
+
if (typeof value !== 'string') return ''
|
|
88
|
+
return value.normalize('NFKC').trim().replace(/\s+/gu, ' ')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function compactText(value) {
|
|
92
|
+
return normalizedText(value).replace(/\s+/gu, '')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function compactLabel(value) {
|
|
96
|
+
if (typeof value !== 'string') return ''
|
|
97
|
+
return value.normalize('NFKC').trim().replace(/\s+/gu, '')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function sourceValue(item, aliases, accept = (value) => value !== undefined && value !== null && value !== '') {
|
|
101
|
+
for (const alias of aliases) {
|
|
102
|
+
if (Object.hasOwn(item, alias) && accept(item[alias])) return { value: item[alias], source: alias }
|
|
103
|
+
}
|
|
104
|
+
return { value: undefined, source: undefined }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function sourceValues(item, aliases) {
|
|
108
|
+
const values = []
|
|
109
|
+
const sources = []
|
|
110
|
+
for (const alias of aliases) {
|
|
111
|
+
if (!Object.hasOwn(item, alias)) continue
|
|
112
|
+
const value = item[alias]
|
|
113
|
+
if (value === undefined || value === null || value === '') continue
|
|
114
|
+
values.push(value)
|
|
115
|
+
sources.push(alias)
|
|
116
|
+
}
|
|
117
|
+
return { values, sources }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function safeNumber(value) {
|
|
121
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : undefined
|
|
122
|
+
if (typeof value !== 'string') return undefined
|
|
123
|
+
const text = value.replaceAll(',', '').trim()
|
|
124
|
+
if (!text) return undefined
|
|
125
|
+
const number = Number(text)
|
|
126
|
+
return Number.isFinite(number) ? number : undefined
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function firstSafeNumber(item, aliases, validate = () => true) {
|
|
130
|
+
for (const alias of aliases) {
|
|
131
|
+
if (!Object.hasOwn(item, alias)) continue
|
|
132
|
+
const value = safeNumber(item[alias])
|
|
133
|
+
if (value !== undefined && validate(value)) return { value, source: alias }
|
|
134
|
+
}
|
|
135
|
+
return { value: null, source: undefined }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function normalizeBoolean(value) {
|
|
139
|
+
if (typeof value === 'boolean') return value
|
|
140
|
+
if (typeof value === 'number' && (value === 0 || value === 1)) return value === 1
|
|
141
|
+
if (typeof value !== 'string') return undefined
|
|
142
|
+
const normalized = compactText(value).toLowerCase()
|
|
143
|
+
if (['1', 'true', 'yes', 'y', '是', '新'].includes(normalized)) return true
|
|
144
|
+
if (['0', 'false', 'no', 'n', '否', '旧'].includes(normalized)) return false
|
|
145
|
+
return undefined
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function firstBoolean(item, aliases) {
|
|
149
|
+
for (const alias of aliases) {
|
|
150
|
+
if (!Object.hasOwn(item, alias)) continue
|
|
151
|
+
const value = normalizeBoolean(item[alias])
|
|
152
|
+
if (value !== undefined) return { value, source: alias }
|
|
153
|
+
}
|
|
154
|
+
return { value: null, source: undefined }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function flattenListValue(value, result) {
|
|
158
|
+
if (Array.isArray(value)) {
|
|
159
|
+
for (const entry of value) flattenListValue(entry, result)
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
if (value === null || value === undefined) return
|
|
163
|
+
if (typeof value !== 'string' && typeof value !== 'number') return
|
|
164
|
+
const text = cleanListToken(value)
|
|
165
|
+
if (text) result.push(text)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function cleanListToken(value) {
|
|
169
|
+
let text = String(value).trim()
|
|
170
|
+
text = text.replace(/^[\[\]"'“”]+/u, '').replace(/[\[\]"'“”]+$/u, '').trim()
|
|
171
|
+
if (!text || /^(?:null|undefined)$/iu.test(text)) return null
|
|
172
|
+
return text
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function isSourceTopicTag(tag) {
|
|
176
|
+
const label = compactLabel(tag)
|
|
177
|
+
if (!label) return false
|
|
178
|
+
if (/(?:非|不|无|不是|拒绝|榜|第\d|推荐|热播|用户|运营|热门|官方|投票|点击|播放|指数|数据|排序)/u.test(label)) return false
|
|
179
|
+
return true
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function parseList(value) {
|
|
183
|
+
if (value === null || value === undefined) return []
|
|
184
|
+
if (typeof value === 'string') {
|
|
185
|
+
const text = value.trim()
|
|
186
|
+
if (!text) return []
|
|
187
|
+
try {
|
|
188
|
+
const parsed = JSON.parse(text)
|
|
189
|
+
return Array.isArray(parsed) ? parseList(parsed) : []
|
|
190
|
+
} catch {
|
|
191
|
+
// 非法 JSON 按普通标签字符串处理,避免一条脏数据中断整榜归一化。
|
|
192
|
+
}
|
|
193
|
+
const result = []
|
|
194
|
+
flattenListValue(text.split(/[,,;;|/、]/u), result)
|
|
195
|
+
return [...new Set(result)]
|
|
196
|
+
}
|
|
197
|
+
const result = []
|
|
198
|
+
flattenListValue(value, result)
|
|
199
|
+
return [...new Set(result)]
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function companyNames(value) {
|
|
203
|
+
if (Array.isArray(value)) return [...new Set(value.flatMap((entry) => companyNames(entry)))]
|
|
204
|
+
if (isRecord(value)) {
|
|
205
|
+
for (const key of ['publisherName', 'companyName', 'manufacturerName', 'name']) {
|
|
206
|
+
const name = normalizedText(value[key])
|
|
207
|
+
if (name) return [name]
|
|
208
|
+
}
|
|
209
|
+
return []
|
|
210
|
+
}
|
|
211
|
+
return parseList(value)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function normalizeCompanies(source) {
|
|
215
|
+
return Object.fromEntries(Object.entries(COMPANY_ROLE_ALIASES).map(([role, aliases]) => [
|
|
216
|
+
role,
|
|
217
|
+
[...new Set(aliases.flatMap((alias) => Object.hasOwn(source, alias) ? companyNames(source[alias]) : []))],
|
|
218
|
+
]))
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function labelValue(values, labels) {
|
|
222
|
+
for (const value of values) {
|
|
223
|
+
const label = labels.get(compactText(value))
|
|
224
|
+
if (label) return label
|
|
225
|
+
}
|
|
226
|
+
return null
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function titleTopics(title) {
|
|
230
|
+
const compactTitle = compactText(title)
|
|
231
|
+
if (!compactTitle) return []
|
|
232
|
+
const result = []
|
|
233
|
+
for (const [topics, roots] of TITLE_ROOTS) {
|
|
234
|
+
if (roots.some((root) => compactTitle.includes(compactText(root)))) result.push(...topics)
|
|
235
|
+
}
|
|
236
|
+
return [...new Set(result)]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function canonicalTopics(rawTopic) {
|
|
240
|
+
const label = compactLabel(rawTopic)
|
|
241
|
+
const matched = TOPIC_TAXONOMY.find(([, aliases]) => aliases.some((alias) => label.includes(compactLabel(alias))))
|
|
242
|
+
return matched?.[0] ?? [rawTopic]
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function mapTopics(rawTopics, source) {
|
|
246
|
+
const mappings = rawTopics.flatMap((rawTopic) => canonicalTopics(rawTopic).map((canonicalTopic) => ({ rawTopic, canonicalTopic, source })))
|
|
247
|
+
return {
|
|
248
|
+
topics: [...new Set(mappings.map(({ canonicalTopic: topic }) => topic))],
|
|
249
|
+
mappings,
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function detectFormat(values, rankingType) {
|
|
254
|
+
for (const entry of values) {
|
|
255
|
+
const text = compactText(entry.value)
|
|
256
|
+
if (text.includes('真人AI') || text.includes('AI真人')) return { value: '真人AI', source: entry.source }
|
|
257
|
+
if (text.includes('沙雕漫')) return { value: '沙雕漫', source: entry.source }
|
|
258
|
+
if (text.includes('动态漫') || text.includes('动态漫画')) return { value: '动态漫', source: entry.source }
|
|
259
|
+
}
|
|
260
|
+
if (rankingType === 'motion-ai') return { value: '真人AI', source: 'rankingType' }
|
|
261
|
+
if (rankingType === 'motion-comedy') return { value: '沙雕漫', source: 'rankingType' }
|
|
262
|
+
if (rankingType === 'motion') return { value: '动态漫', source: 'rankingType' }
|
|
263
|
+
return { value: null, source: undefined }
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function titleHash(title) {
|
|
267
|
+
return createHash('sha256').update(compactText(title)).digest('hex')
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function normalizedId(value) {
|
|
271
|
+
if (value === undefined || value === null || typeof value === 'object' || typeof value === 'boolean') return null
|
|
272
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value
|
|
273
|
+
if (typeof value !== 'string') return null
|
|
274
|
+
const text = value.trim()
|
|
275
|
+
return text || null
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function firstValidSource(item, aliases, validate) {
|
|
279
|
+
for (const alias of aliases) {
|
|
280
|
+
if (!Object.hasOwn(item, alias)) continue
|
|
281
|
+
const value = validate(item[alias])
|
|
282
|
+
if (value !== null && value !== undefined) return { value, source: alias }
|
|
283
|
+
}
|
|
284
|
+
return { value: null, source: undefined }
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function rankingItems(value) {
|
|
288
|
+
if (Array.isArray(value)) return value
|
|
289
|
+
if (!isRecord(value)) return []
|
|
290
|
+
for (const key of ['content', 'data', 'list', 'rows', 'items']) {
|
|
291
|
+
if (Array.isArray(value[key])) return value[key]
|
|
292
|
+
}
|
|
293
|
+
return []
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function normalizeRankingItem(rankingType, item, context = {}) {
|
|
297
|
+
const source = isRecord(item) ? item : {}
|
|
298
|
+
const observedAt = context?.observedAt ?? source.observedAt ?? null
|
|
299
|
+
const idSource = firstValidSource(source, FIELD_ALIASES.id, normalizedId)
|
|
300
|
+
const titleSource = firstValidSource(source, FIELD_ALIASES.title, (value) => {
|
|
301
|
+
if (typeof value !== 'string' || !value.trim()) return null
|
|
302
|
+
return normalizedText(value)
|
|
303
|
+
})
|
|
304
|
+
const title = titleSource.value ?? ''
|
|
305
|
+
const playletId = idSource.value
|
|
306
|
+
if (playletId === null && title === '') return null
|
|
307
|
+
const tagSource = sourceValues(source, FIELD_ALIASES.tags)
|
|
308
|
+
const tagEntries = tagSource.values.flatMap((value, index) => parseList(value).map((tag) => ({ value: tag, source: tagSource.sources[index] })))
|
|
309
|
+
const uniqueTagEntries = [...new Map(tagEntries.map((entry) => [entry.value, entry])).values()]
|
|
310
|
+
const uniqueTags = uniqueTagEntries.map(({ value }) => value)
|
|
311
|
+
const sourceTopics = uniqueTags.filter((tag) => {
|
|
312
|
+
const label = compactLabel(tag)
|
|
313
|
+
return isSourceTopicTag(tag)
|
|
314
|
+
&& !AUDIENCE_LABELS.has(label)
|
|
315
|
+
&& !ERA_LABELS.has(label)
|
|
316
|
+
&& !NON_TOPIC_TAGS.has(label)
|
|
317
|
+
&& detectFormat([{ value: tag, source: '' }], '').value === null
|
|
318
|
+
})
|
|
319
|
+
const formatSource = sourceValue(source, FIELD_ALIASES.format)
|
|
320
|
+
const formatEntries = [
|
|
321
|
+
...(formatSource.value === undefined ? [] : parseList(formatSource.value).map((value) => ({ value, source: formatSource.source }))),
|
|
322
|
+
...uniqueTagEntries,
|
|
323
|
+
]
|
|
324
|
+
const format = detectFormat(formatEntries, rankingType)
|
|
325
|
+
const audienceSource = sourceValue(source, FIELD_ALIASES.audience)
|
|
326
|
+
const explicitAudience = audienceSource.value === undefined ? null : labelValue(parseList(audienceSource.value), AUDIENCE_LABELS)
|
|
327
|
+
const audience = explicitAudience || labelValue(uniqueTags, AUDIENCE_LABELS)
|
|
328
|
+
const eraSource = sourceValue(source, FIELD_ALIASES.era)
|
|
329
|
+
const explicitEra = eraSource.value === undefined ? null : labelValue(parseList(eraSource.value), ERA_LABELS)
|
|
330
|
+
const era = explicitEra || labelValue(uniqueTags, ERA_LABELS)
|
|
331
|
+
const inferredTopics = titleTopics(title)
|
|
332
|
+
const rawTopics = sourceTopics.length > 0 ? sourceTopics : inferredTopics
|
|
333
|
+
const topicSource = sourceTopics.length > 0 ? 'source-tag' : (inferredTopics.length > 0 ? 'title-keyword' : 'unclassified')
|
|
334
|
+
const mappedTopics = mapTopics(rawTopics, topicSource)
|
|
335
|
+
const topics = mappedTopics.topics.length > 0 ? mappedTopics.topics : ['未分类']
|
|
336
|
+
const ranking = firstSafeNumber(source, FIELD_ALIASES.ranking, (value) => Number.isInteger(value) && value >= 1)
|
|
337
|
+
const heatValue = firstSafeNumber(source, FIELD_ALIASES.heatValue)
|
|
338
|
+
const growthValue = firstSafeNumber(source, FIELD_ALIASES.growthValue)
|
|
339
|
+
const persistenceDays = firstSafeNumber(source, FIELD_ALIASES.persistenceDays, (value) => Number.isInteger(value) && value >= 0)
|
|
340
|
+
const isNew = firstBoolean(source, FIELD_ALIASES.isNew)
|
|
341
|
+
const companySource = sourceValues(source, [...new Set([...FIELD_ALIASES.companies, ...Object.values(COMPANY_ROLE_ALIASES).flat()])])
|
|
342
|
+
const companies = normalizeCompanies(source)
|
|
343
|
+
const key = playletId === null ? `title-hash:${titleHash(title)}` : `playlet-id:${playletId}`
|
|
344
|
+
|
|
345
|
+
const sourceFields = {}
|
|
346
|
+
for (const [name, value] of Object.entries({
|
|
347
|
+
playletId: idSource.source,
|
|
348
|
+
title: titleSource.source,
|
|
349
|
+
ranking: ranking.source,
|
|
350
|
+
heatValue: heatValue.source,
|
|
351
|
+
growthValue: growthValue.source,
|
|
352
|
+
isNew: isNew.source,
|
|
353
|
+
persistenceDays: persistenceDays.source,
|
|
354
|
+
companies: companySource.sources.length ? companySource.sources : undefined,
|
|
355
|
+
tags: tagSource.sources.length ? tagSource.sources : undefined,
|
|
356
|
+
audience: explicitAudience ? audienceSource.source : (audience ? 'tags' : undefined),
|
|
357
|
+
era: explicitEra ? eraSource.source : (era ? 'tags' : undefined),
|
|
358
|
+
format: format.source,
|
|
359
|
+
})) {
|
|
360
|
+
if (value !== undefined) sourceFields[name] = value
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
key,
|
|
365
|
+
playletId,
|
|
366
|
+
title,
|
|
367
|
+
rankingType: String(rankingType ?? ''),
|
|
368
|
+
ranking: ranking.value,
|
|
369
|
+
observedAt,
|
|
370
|
+
topics,
|
|
371
|
+
rawTopics,
|
|
372
|
+
audience,
|
|
373
|
+
era,
|
|
374
|
+
format: format.value,
|
|
375
|
+
heatValue: heatValue.value,
|
|
376
|
+
growthValue: growthValue.value,
|
|
377
|
+
isNew: isNew.value,
|
|
378
|
+
persistenceDays: persistenceDays.value,
|
|
379
|
+
companies,
|
|
380
|
+
provenance: {
|
|
381
|
+
rankingType: String(rankingType ?? ''),
|
|
382
|
+
topicSource,
|
|
383
|
+
topicMappings: mappedTopics.mappings,
|
|
384
|
+
rawRef: {
|
|
385
|
+
snapshotId: context?.snapshotId ?? null,
|
|
386
|
+
rankingType: String(rankingType ?? ''),
|
|
387
|
+
playletId,
|
|
388
|
+
},
|
|
389
|
+
sourceFields,
|
|
390
|
+
evidence: {
|
|
391
|
+
rawTags: uniqueTags,
|
|
392
|
+
sourceTags: uniqueTags,
|
|
393
|
+
titleKeywords: inferredTopics,
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export function normalizeRankings(rankings, context = {}) {
|
|
400
|
+
if (Array.isArray(rankings)) {
|
|
401
|
+
return rankings.map((item) => normalizeRankingItem(item?.rankingType ?? context?.rankingType ?? '', item, context)).filter(Boolean)
|
|
402
|
+
}
|
|
403
|
+
if (!isRecord(rankings)) return []
|
|
404
|
+
const result = []
|
|
405
|
+
for (const [rankingType, value] of Object.entries(rankings)) {
|
|
406
|
+
for (const item of rankingItems(value)) {
|
|
407
|
+
const observation = normalizeRankingItem(rankingType, item, context)
|
|
408
|
+
if (observation) result.push(observation)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return result
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function firstNonEmpty(values) {
|
|
415
|
+
return values.find((value) => value !== null && value !== undefined && value !== '') ?? null
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function cloneValue(value) {
|
|
419
|
+
if (Array.isArray(value)) return value.map((entry) => cloneValue(entry))
|
|
420
|
+
if (isRecord(value)) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cloneValue(entry)]))
|
|
421
|
+
return value
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export function mergePlayletObservations(items) {
|
|
425
|
+
const groups = new Map()
|
|
426
|
+
for (const item of Array.isArray(items) ? items : []) {
|
|
427
|
+
if (!isRecord(item)) continue
|
|
428
|
+
const key = item.key ?? `title-hash:${titleHash(item.title ?? '')}`
|
|
429
|
+
if (!groups.has(key)) groups.set(key, [])
|
|
430
|
+
groups.get(key).push(item)
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return [...groups.entries()].map(([key, observations]) => {
|
|
434
|
+
const topics = [...new Set(observations.flatMap((item) => item.topics || []))]
|
|
435
|
+
const usefulTopics = topics.filter((topic) => topic !== '未分类')
|
|
436
|
+
return {
|
|
437
|
+
key,
|
|
438
|
+
playletId: firstNonEmpty(observations.map((item) => item.playletId)),
|
|
439
|
+
title: firstNonEmpty(observations.map((item) => item.title)),
|
|
440
|
+
topics: usefulTopics.length > 0 ? usefulTopics : ['未分类'],
|
|
441
|
+
audience: firstNonEmpty(observations.map((item) => item.audience)),
|
|
442
|
+
era: firstNonEmpty(observations.map((item) => item.era)),
|
|
443
|
+
format: firstNonEmpty(observations.map((item) => item.format)),
|
|
444
|
+
companies: Object.fromEntries(Object.keys(COMPANY_ROLE_ALIASES).map((role) => [role, [...new Set(observations.flatMap((item) => item.companies?.[role] || []))]])),
|
|
445
|
+
rankingTypes: [...new Set(observations.map((item) => item.rankingType))],
|
|
446
|
+
rankings: observations.map((item) => ({
|
|
447
|
+
rankingType: item.rankingType,
|
|
448
|
+
ranking: item.ranking,
|
|
449
|
+
heatValue: item.heatValue,
|
|
450
|
+
growthValue: item.growthValue,
|
|
451
|
+
isNew: item.isNew,
|
|
452
|
+
persistenceDays: item.persistenceDays,
|
|
453
|
+
provenance: cloneValue(item.provenance),
|
|
454
|
+
})),
|
|
455
|
+
observations: observations.map((item) => cloneValue(item)),
|
|
456
|
+
}
|
|
457
|
+
})
|
|
458
|
+
}
|