@cloud411716/fancy-webnovel 1.0.46 → 3.0.0
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/client.js +369 -0
- package/cordis.patch.yml +4 -13
- package/docs/douyin-plugin.md +118 -0
- package/docs/material-library/README.md +404 -0
- package/docs/material-library/import.js +437 -0
- package/docs/material-library/prompt.md +370 -0
- package/docs/material-library/queries.surql +94 -0
- package/docs/material-library/sample.jsonl +14 -0
- package/docs/material-library/schema.surql +46 -0
- package/docs/mcp-profile.example.yml +24 -0
- package/docs/story-graph-design.md +602 -0
- package/docs/story-graph-validation.md +81 -0
- package/docs/workspace-mcp.md +284 -0
- package/index.js +26 -38
- package/lib/atomic-write.js +109 -0
- package/lib/chapter-order.js +100 -0
- package/lib/chinese-num.js +111 -0
- package/lib/confirmation.js +80 -0
- package/lib/db-init.js +123 -0
- package/lib/deployed-state.js +141 -0
- package/lib/direction-labels.js +265 -0
- package/lib/error-codes.js +104 -0
- package/lib/infra.js +594 -0
- package/lib/llm-wiki.js +109 -0
- package/lib/material-db.js +149 -0
- package/lib/path-guard.js +150 -0
- package/lib/projects.js +400 -0
- package/lib/scraper-utils.js +305 -0
- package/lib/surreal-server.js +338 -0
- package/lib/topic-decision.js +860 -0
- package/lib/topic-fields.js +251 -0
- package/lib/topic-schema.js +225 -0
- package/lib/workspace.js +501 -0
- package/package.json +62 -5
- package/plugins/fancy-analyze/analyze-definitions.md +519 -0
- package/plugins/fancy-analyze/command-input.js +65 -0
- package/plugins/fancy-analyze/index.js +2024 -0
- package/plugins/fancy-analyze/ingest-coverage.js +107 -0
- package/plugins/fancy-analyze/schema-analyze.md +627 -0
- package/plugins/fancy-analyze/schema-write.md +178 -0
- package/plugins/fancy-analyze/scripts/append-summary-chapter.js +612 -0
- package/plugins/fancy-analyze/scripts/split_source.js +292 -0
- package/plugins/fancy-analyze/summary-progress.js +495 -0
- package/plugins/fancy-analyze/templates.js +1179 -0
- package/plugins/fancy-bootstrap/index.js +313 -0
- package/plugins/fancy-bootstrap/scripts/init.js +177 -0
- package/plugins/fancy-bootstrap/scripts/path-utils.js +21 -0
- package/plugins/fancy-bootstrap/templates.js +71 -0
- package/plugins/fancy-db/index.js +172 -0
- package/plugins/fancy-douyin/deploy.js +134 -0
- package/plugins/fancy-douyin/index.js +551 -0
- package/plugins/fancy-douyin/prompts/01-analysis-prompt.md +84 -0
- package/plugins/fancy-douyin/scripts/crawl-note.cjs +194 -0
- package/plugins/fancy-douyin/scripts/lib.cjs +197 -0
- package/plugins/fancy-douyin/scripts/scan-account.cjs +128 -0
- package/plugins/fancy-douyin/scripts/start-chrome.cjs +203 -0
- package/plugins/fancy-douyin/state.js +197 -0
- package/plugins/fancy-douyin/templates.js +127 -0
- package/plugins/fancy-export/exporter.js +805 -0
- package/plugins/fancy-export/index.js +63 -0
- package/plugins/fancy-import/import-core.js +1118 -0
- package/plugins/fancy-import/import-driver.js +604 -0
- package/plugins/fancy-import/index.js +738 -0
- package/plugins/fancy-import/prompts/01-import-prompt.md +131 -0
- package/plugins/fancy-import/templates.js +58 -0
- package/plugins/fancy-material/exporter.js +153 -0
- package/plugins/fancy-material/genres.js +256 -0
- package/plugins/fancy-material/index.js +835 -0
- package/plugins/fancy-material/inventory.js +143 -0
- package/plugins/fancy-material/kinds.js +313 -0
- package/plugins/fancy-material/queue.js +55 -0
- package/plugins/fancy-material/scripts/query.js +254 -0
- package/plugins/fancy-material/templates.js +258 -0
- package/plugins/fancy-material/tool-deploy.js +138 -0
- package/plugins/fancy-material/validate.js +149 -0
- package/plugins/fancy-project/index.js +133 -0
- package/plugins/fancy-scan/existing-block.js +100 -0
- package/plugins/fancy-scan/index.js +708 -0
- package/plugins/fancy-scan/prompts/01-analysis-prompt.md +302 -0
- package/plugins/fancy-scan/scripts/append-block.js +725 -0
- package/plugins/fancy-scan/scripts/report-validate.js +824 -0
- package/plugins/fancy-scan/scripts/run-scan.js +667 -0
- package/plugins/fancy-scan/scripts/scrapers/fanqie-rank-scraper.js +923 -0
- package/plugins/fancy-scan/scripts/scrapers/jjwxc-rank-scraper.js +469 -0
- package/plugins/fancy-scan/scripts/scrapers/qimao-rank-scraper.js +629 -0
- package/plugins/fancy-scan/templates/blocks.js +155 -0
- package/plugins/fancy-scan/templates/platforms.js +372 -0
- package/plugins/fancy-scan/templates/report-schema.js +90 -0
- package/plugins/fancy-scan/templates.js +694 -0
- package/plugins/fancy-scan/tool-deploy.js +335 -0
- package/plugins/fancy-scan/wait-turn.js +46 -0
- package/plugins/fancy-story-builder/db/README.md +106 -0
- package/plugins/fancy-story-builder/db/client.js +228 -0
- package/plugins/fancy-story-builder/db/commands.js +145 -0
- package/plugins/fancy-story-builder/db/ids.js +39 -0
- package/plugins/fancy-story-builder/db/import.js +798 -0
- package/plugins/fancy-story-builder/db/project.js +299 -0
- package/plugins/fancy-story-builder/db/query.js +361 -0
- package/plugins/fancy-story-builder/db/schema.js +417 -0
- package/plugins/fancy-story-builder/db/stage-sync.js +238 -0
- package/plugins/fancy-story-builder/deploy-manifest.js +239 -0
- package/plugins/fancy-story-builder/deslop-driver.js +821 -0
- package/plugins/fancy-story-builder/flesh-output.js +168 -0
- package/plugins/fancy-story-builder/index.js +6861 -0
- package/plugins/fancy-story-builder/patch-driver.js +390 -0
- package/plugins/fancy-story-builder/prompts/01-skeleton-prompt.md +563 -0
- package/plugins/fancy-story-builder/prompts/02-flesh-prompt.md +602 -0
- package/plugins/fancy-story-builder/prompts/03-rhythm-prompt.md +539 -0
- package/plugins/fancy-story-builder/prompts/04-writing-prompt.md +225 -0
- package/plugins/fancy-story-builder/prompts/05-deslop-prompt.md +96 -0
- package/plugins/fancy-story-builder/purpose-template.md +83 -0
- package/plugins/fancy-story-builder/references/formulas-rhythm.json +302 -0
- package/plugins/fancy-story-builder/references/formulas-skeleton.json +402 -0
- package/plugins/fancy-story-builder/references/genre-profiles.json +3514 -0
- package/plugins/fancy-story-builder/references/glossary.md +594 -0
- package/plugins/fancy-story-builder/references/index.md +581 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/00-index.md +174 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/01-scene.md +150 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/02-chapter-workflow.md +99 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/03-opening-chapter.md +104 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/04-dialogue-mastery.md +274 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/05-genre-formulas.md +432 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/06-tone-ensemble.md +259 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/07-ledger-audit.md +222 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/08-diagnosis-revision.md +205 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/09-reading-power.md +135 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/10-deslop.md +129 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/00-index.md +98 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/01-upgrade-rhythm.md +300 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/02-arc-rhythm.md +168 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/03-highpoint-hooks.md +189 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/04-satisfaction.md +226 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/05-foreshadow-density.md +195 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/06-chapter-outline.md +226 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/07-audit.md +181 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/00-index.md +100 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/01-character.md +243 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/02-worldbuilding.md +245 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/03-relations.md +185 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/04-emotion-methods.md +286 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/05-audit.md +187 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/00-index.md +91 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/01-positioning.md +209 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/02-packaging.md +135 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/03-entities.md +305 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/04-conflict.md +328 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/05-quota.md +187 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/06-audit.md +160 -0
- package/plugins/fancy-story-builder/rhythm-output.js +140 -0
- package/plugins/fancy-story-builder/schema-setting.json +1100 -0
- package/plugins/fancy-story-builder/schema-setting.md +232 -0
- package/plugins/fancy-story-builder/scripts/ai-patterns.js +619 -0
- package/plugins/fancy-story-builder/scripts/brief-validate.js +164 -0
- package/plugins/fancy-story-builder/scripts/check-guide-compliance.js +289 -0
- package/plugins/fancy-story-builder/scripts/content-quality.js +416 -0
- package/plugins/fancy-story-builder/scripts/deslop-validate.js +143 -0
- package/plugins/fancy-story-builder/scripts/error-classes.js +112 -0
- package/plugins/fancy-story-builder/scripts/flesh-validate.js +1312 -0
- package/plugins/fancy-story-builder/scripts/formula-engine.js +112 -0
- package/plugins/fancy-story-builder/scripts/graph-utils.js +1484 -0
- package/plugins/fancy-story-builder/scripts/label-coverage.js +171 -0
- package/plugins/fancy-story-builder/scripts/prompt-drift-check.js +441 -0
- package/plugins/fancy-story-builder/scripts/reading-power.js +298 -0
- package/plugins/fancy-story-builder/scripts/reference-log.js +110 -0
- package/plugins/fancy-story-builder/scripts/rhythm-validate.js +1312 -0
- package/plugins/fancy-story-builder/scripts/schema-pages.js +2668 -0
- package/plugins/fancy-story-builder/scripts/semantic-lint.js +381 -0
- package/plugins/fancy-story-builder/scripts/skeleton-quota.js +145 -0
- package/plugins/fancy-story-builder/scripts/skeleton-validate.js +1973 -0
- package/plugins/fancy-story-builder/scripts/stage-batches.js +1405 -0
- package/plugins/fancy-story-builder/scripts/stage-contract.js +429 -0
- package/plugins/fancy-story-builder/scripts/story-artifacts.js +933 -0
- package/plugins/fancy-story-builder/scripts/upstream-query.js +198 -0
- package/plugins/fancy-story-builder/scripts/v2/baseline.js +112 -0
- package/plugins/fancy-story-builder/scripts/v2/cast.js +517 -0
- package/plugins/fancy-story-builder/scripts/v2/context.js +434 -0
- package/plugins/fancy-story-builder/scripts/v2/contracts.js +493 -0
- package/plugins/fancy-story-builder/scripts/v2/core.js +419 -0
- package/plugins/fancy-story-builder/scripts/v2/engine.js +1068 -0
- package/plugins/fancy-story-builder/scripts/v2/export-markdown.js +794 -0
- package/plugins/fancy-story-builder/scripts/v2/genre.js +195 -0
- package/plugins/fancy-story-builder/scripts/v2/knowledge.js +321 -0
- package/plugins/fancy-story-builder/scripts/v2/macro.js +409 -0
- package/plugins/fancy-story-builder/scripts/v2/manifest.js +538 -0
- package/plugins/fancy-story-builder/scripts/v2/migrate.js +137 -0
- package/plugins/fancy-story-builder/scripts/v2/prompts.js +1335 -0
- package/plugins/fancy-story-builder/scripts/v2/rhythm.js +618 -0
- package/plugins/fancy-story-builder/scripts/v2/scale.js +843 -0
- package/plugins/fancy-story-builder/scripts/v2/snapshot.js +121 -0
- package/plugins/fancy-story-builder/scripts/v2/stages.js +273 -0
- package/plugins/fancy-story-builder/scripts/v2/writing.js +216 -0
- package/plugins/fancy-story-builder/scripts/writing-rules.js +167 -0
- package/plugins/fancy-story-builder/scripts/writing-validate.js +682 -0
- package/plugins/fancy-story-builder/skeleton-output.js +199 -0
- package/plugins/fancy-story-builder/stage-driver.js +1049 -0
- package/plugins/fancy-story-builder/storydb/README.md +271 -0
- package/plugins/fancy-story-builder/storydb/cli.js +458 -0
- package/plugins/fancy-story-builder/storydb/client.js +351 -0
- package/plugins/fancy-story-builder/storydb/compile.js +452 -0
- package/plugins/fancy-story-builder/storydb/context.js +288 -0
- package/plugins/fancy-story-builder/storydb/definitions.js +699 -0
- package/plugins/fancy-story-builder/storydb/driver.js +106 -0
- package/plugins/fancy-story-builder/storydb/dsh-tools.js +313 -0
- package/plugins/fancy-story-builder/storydb/export.js +175 -0
- package/plugins/fancy-story-builder/storydb/ids.js +31 -0
- package/plugins/fancy-story-builder/storydb/impact.js +170 -0
- package/plugins/fancy-story-builder/storydb/import.js +559 -0
- package/plugins/fancy-story-builder/storydb/mcp.js +99 -0
- package/plugins/fancy-story-builder/storydb/prompts.js +952 -0
- package/plugins/fancy-story-builder/storydb/stage-command.js +379 -0
- package/plugins/fancy-story-builder/storydb/stage.js +426 -0
- package/plugins/fancy-story-builder/storydb/store.js +891 -0
- package/plugins/fancy-story-builder/storydb/tools.js +592 -0
- package/plugins/fancy-story-builder/storydb/validation.js +183 -0
- package/plugins/fancy-story-builder/templates/v2/10-scale/scale-template.json +144 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/emotion-template.json +15 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/endings-template.json +16 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/lines-template.json +28 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/roles-template.json +10 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/story-template.json +19 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/volumes-template.json +24 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/world-template.json +24 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/characters-template.json +49 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/climaxes-template.json +14 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/conflicts-template.json +30 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/factions-template.json +18 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/foreshadows-template.json +29 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/information-template.json +29 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/items-template.json +13 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/locations-template.json +12 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/payoffs-template.json +16 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/relations-template.json +44 -0
- package/plugins/fancy-story-builder/templates/v2/40-rhythm/chapter-map-template.json +81 -0
- package/plugins/fancy-story-builder/templates/v2/40-rhythm/outline-template.json +162 -0
- package/plugins/fancy-story-builder/templates/v2/50-writing/ledger-template.json +46 -0
- package/plugins/fancy-story-builder/templates/v2/60-deslop/report-template.json +10 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//346/227/266/345/272/217/346/230/240/345/260/204/346/250/241/346/235/277.json +427 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//347/253/240/350/212/202/347/273/206/347/272/262/346/250/241/346/235/277.json +34 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//347/253/240/350/212/202/350/247/204/345/210/222/346/250/241/346/235/277.json +24 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//350/212/202/345/245/217/345/217/202/346/225/260/346/250/241/346/235/277.json +27 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//344/270/226/347/225/214/350/247/202/350/247/204/345/210/231/346/250/241/346/235/277.json +168 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/205/263/351/224/256/351/201/223/345/205/267/346/250/241/346/235/277.json +184 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/205/266/344/273/226/345/256/236/344/275/223/346/250/241/346/235/277.json +62 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/206/262/347/252/201/346/250/241/346/235/277.json +131 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/211/247/346/203/205/346/250/241/346/235/277.json +85 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/212/277/345/212/233/346/250/241/346/235/277.json +103 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/234/260/347/202/271/346/250/241/346/235/277.json +68 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//347/273/223/345/261/200/346/250/241/346/235/277.json +142 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//350/247/222/350/211/262/346/250/241/346/235/277.json +292 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/205/263/347/263/273/346/250/241/346/235/277.json +266 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/256/236/344/275/223/346/250/241/346/235/277.json +336 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/261/202/347/272/247/346/250/241/346/235/277.json +65 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//346/241/206/346/236/266/346/250/241/346/235/277.json +308 -0
- package/plugins/fancy-story-builder/templates.js +1446 -0
- package/plugins/fancy-story-builder/wiki-references.js +540 -0
- package/plugins/fancy-story-builder/writing-driver.js +1388 -0
- package/plugins/fancy-topic/index.js +1057 -0
- package/plugins/fancy-topic/prompts/01-exploration-prompt.md +115 -0
- package/plugins/fancy-topic/scripts/save-suggestion.js +219 -0
- package/plugins/fancy-topic/scripts/select-topic.js +317 -0
- package/plugins/fancy-topic/templates.js +476 -0
- package/plugins/fancy-topic/tool-deploy.js +200 -0
- package/commands/bootstrap/index.js +0 -164
- package/commands/bootstrap/init-project.js +0 -121
- package/commands/scan/index.js +0 -283
- package/commands/scan/platforms/fanqie.js +0 -146
- package/commands/scan/platforms/jinjiang.js +0 -143
- package/commands/scan/platforms/qidian.js +0 -102
- package/commands/scan/platforms/qimao.js +0 -127
- package/commands/scan/scraper.js +0 -195
- package/infra.js +0 -160
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* fanqie.js — 番茄小说排行榜采集
|
|
3
|
-
*
|
|
4
|
-
* 策略(优先级递减):
|
|
5
|
-
* 1. 移动端页面(__INITIAL_STATE__ 内嵌数据)— 无需字体解密
|
|
6
|
-
* 2. Playwright 浏览器 — 仅作为 fallback
|
|
7
|
-
*
|
|
8
|
-
* Playwright 通过 ctx.effect() 注册生命周期,Ctrl+C 时自动清理。
|
|
9
|
-
* 使用 browserContext({ signal }) 确保 page.evaluate 也能响应中止信号。
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export const platform = 'fanqie';
|
|
13
|
-
export const label = '番茄';
|
|
14
|
-
|
|
15
|
-
export const rankList = [
|
|
16
|
-
{ id: '1_2', label: '男频阅读榜', channel: '1', type: '2' },
|
|
17
|
-
{ id: '1_1', label: '男频新书榜', channel: '1', type: '1' },
|
|
18
|
-
{ id: '0_2', label: '女频阅读榜', channel: '0', type: '2' },
|
|
19
|
-
{ id: '0_1', label: '女频新书榜', channel: '0', type: '1' },
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
// 移动端页面(__INITIAL_STATE__ 内嵌数据)
|
|
23
|
-
const MOBILE_BASE = 'https://m.reader.qq.com';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {object} ctx
|
|
27
|
-
* @param {string} channel
|
|
28
|
-
* @param {string} type
|
|
29
|
-
* @param {AbortSignal} signal
|
|
30
|
-
*/
|
|
31
|
-
async function mobileFetch(ctx, channel, type, signal) {
|
|
32
|
-
const url = `${MOBILE_BASE}/rank/${channel}_${type}.html`;
|
|
33
|
-
let timerDispose;
|
|
34
|
-
const timeout = new Promise((_, reject) => {
|
|
35
|
-
timerDispose = ctx.timeout(() => reject(new Error('timeout')), 15000);
|
|
36
|
-
});
|
|
37
|
-
try {
|
|
38
|
-
const res = await Promise.race([
|
|
39
|
-
fetch(url, {
|
|
40
|
-
headers: {
|
|
41
|
-
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)',
|
|
42
|
-
'Accept': 'text/html',
|
|
43
|
-
},
|
|
44
|
-
signal,
|
|
45
|
-
}),
|
|
46
|
-
timeout,
|
|
47
|
-
]);
|
|
48
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
49
|
-
const html = await res.text();
|
|
50
|
-
const m = html.match(/window\.__INITIAL_STATE__\s*=\s*(\{[\s\S]*?\});/);
|
|
51
|
-
if (!m) throw new Error('__INITIAL_STATE__ not found');
|
|
52
|
-
try {
|
|
53
|
-
return JSON.parse(m[1]);
|
|
54
|
-
} catch (_) {
|
|
55
|
-
throw new Error('__INITIAL_STATE__ JSON parse failed');
|
|
56
|
-
}
|
|
57
|
-
} finally {
|
|
58
|
-
try { timerDispose?.(); } catch (_) {}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Scrape one rank list. Tries mobile → Playwright.
|
|
64
|
-
* @param {string} rankId - e.g. '1_2'
|
|
65
|
-
* @param {object} ctx - Cordis plugin context
|
|
66
|
-
* @param {AbortSignal} signal
|
|
67
|
-
* @returns {Promise<{ ok: boolean, books: object[], error?: string }>}
|
|
68
|
-
*/
|
|
69
|
-
export async function scrapeRank(rankId, ctx, signal) {
|
|
70
|
-
const [channel, type] = rankId.split('_');
|
|
71
|
-
|
|
72
|
-
// 策略1: 移动端页面
|
|
73
|
-
try {
|
|
74
|
-
const data = await mobileFetch(ctx, channel, type, signal);
|
|
75
|
-
const books = parseMobileData(data);
|
|
76
|
-
if (books.length > 0) return { ok: true, books };
|
|
77
|
-
} catch (_) { /* try next strategy */ }
|
|
78
|
-
|
|
79
|
-
// 策略2: Playwright(通过 ctx.effect 注册生命周期,Ctrl+C 自动清理)
|
|
80
|
-
let browser;
|
|
81
|
-
const disposeEffect = ctx.effect(() => {
|
|
82
|
-
return () => { browser?.close(); };
|
|
83
|
-
}, 'fanqie: browser cleanup');
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
const { chromium } = await import('playwright-core');
|
|
87
|
-
browser = await chromium.launch({ headless: true });
|
|
88
|
-
const context = await browser.newContext({ signal });
|
|
89
|
-
const page = await context.newPage();
|
|
90
|
-
const url = `https://www.fanqie.com/rank/${channel}_${type}/`;
|
|
91
|
-
|
|
92
|
-
await page.goto(url, { waitUntil: 'networkidle', signal });
|
|
93
|
-
|
|
94
|
-
const books = await page.evaluate(() => {
|
|
95
|
-
const s = window.__INITIAL_STATE__ || {};
|
|
96
|
-
let list = null;
|
|
97
|
-
for (const c of [s.rank, s.rankData, s.page]) {
|
|
98
|
-
if (c?.book_list) { list = c.book_list; break; }
|
|
99
|
-
if (c?.bookList) { list = c.bookList; break; }
|
|
100
|
-
if (c?.rankList) { list = c.rankList; break; }
|
|
101
|
-
}
|
|
102
|
-
if (!list || !Array.isArray(list)) return null;
|
|
103
|
-
return list.map((b, i) => ({
|
|
104
|
-
rank: b.rank ?? (i + 1),
|
|
105
|
-
title: b.title ?? b.bookName ?? '',
|
|
106
|
-
author: b.author ?? '',
|
|
107
|
-
category: '',
|
|
108
|
-
words: b.wordCount ?? 0,
|
|
109
|
-
intro: (b.description ?? '').slice(0, 150),
|
|
110
|
-
cover: b.coverUrl ?? '',
|
|
111
|
-
bookId: b.bookId ?? '',
|
|
112
|
-
}));
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// 嵌套 try-finally:context.close() 失败不影响 disposeEffect 执行
|
|
116
|
-
try {
|
|
117
|
-
await context.close();
|
|
118
|
-
} finally {
|
|
119
|
-
disposeEffect();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (books && books.length > 0) return { ok: true, books };
|
|
123
|
-
} catch (_) { /* exhausted */ }
|
|
124
|
-
|
|
125
|
-
return { ok: false, books: [], error: 'all strategies exhausted' };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function parseMobileData(data) {
|
|
129
|
-
if (!data || typeof data !== 'object') return [];
|
|
130
|
-
let list = null;
|
|
131
|
-
const cands = [data.rank?.book_list, data.rank?.bookList, data.page?.bookList, data];
|
|
132
|
-
for (const c of cands) {
|
|
133
|
-
if (Array.isArray(c) && c.length > 0) { list = c; break; }
|
|
134
|
-
}
|
|
135
|
-
if (!list) return [];
|
|
136
|
-
return list.map((b, i) => ({
|
|
137
|
-
rank: b.rank ?? (i + 1),
|
|
138
|
-
title: b.title ?? b.name ?? '',
|
|
139
|
-
author: b.author ?? '',
|
|
140
|
-
category: '',
|
|
141
|
-
words: b.wordCount ?? 0,
|
|
142
|
-
intro: (b.description ?? '').slice(0, 150),
|
|
143
|
-
cover: b.cover ?? '',
|
|
144
|
-
bookId: b.bookId ?? '',
|
|
145
|
-
}));
|
|
146
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* jinjiang.js — 晋江文学城排行榜采集
|
|
3
|
-
*
|
|
4
|
-
* 策略:纯 HTTP + gb18030 解码。
|
|
5
|
-
* 详情页使用 fetch + arrayBuffer + TextDecoder('gb18030')。
|
|
6
|
-
* 无需 Playwright。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const platform = 'jinjiang';
|
|
10
|
-
export const label = '晋江';
|
|
11
|
-
|
|
12
|
-
export const rankList = [
|
|
13
|
-
{ id: '5', label: '月榜', channel: 'all', type: '5' },
|
|
14
|
-
{ id: '7', label: '总分榜', channel: 'all', type: '7' },
|
|
15
|
-
{ id: '4', label: '季度榜', channel: 'all', type: '4' },
|
|
16
|
-
{ id: '12', label: '收入金榜', channel: 'all', type: '12' },
|
|
17
|
-
{ id: '16', label: '完结金榜', channel: 'all', type: '16' },
|
|
18
|
-
{ id: '17', label: '新手金榜', channel: 'all', type: '17' },
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
const BASE_URL = 'https://www.jjwxc.net/topten.php';
|
|
22
|
-
const DETAIL_BASE = 'https://www.jjwxc.net/onebook.php';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Scrape one rank list.
|
|
26
|
-
* @param {string} rankId - orderstr, e.g. '5'
|
|
27
|
-
* @param {object} ctx - Cordis plugin context
|
|
28
|
-
* @param {AbortSignal} signal
|
|
29
|
-
* @returns {Promise<{ ok: boolean, books: object[], error?: string }>}
|
|
30
|
-
*/
|
|
31
|
-
export async function scrapeRank(rankId, ctx, signal) {
|
|
32
|
-
const url = `${BASE_URL}?orderstr=${rankId}`;
|
|
33
|
-
|
|
34
|
-
// 1. 抓列表页
|
|
35
|
-
const { ok: listOk, status, body, error: listError } = await httpGet(ctx, url, signal);
|
|
36
|
-
if (!listOk) return { ok: false, books: [], error: listError ?? `HTTP ${status}` };
|
|
37
|
-
|
|
38
|
-
// 2. 解析书籍 ID 列表
|
|
39
|
-
const bookIds = extractBookIds(body);
|
|
40
|
-
if (!bookIds.length) return { ok: false, books: [], error: 'no book ids found' };
|
|
41
|
-
|
|
42
|
-
// 3. 批量补采详情(每批 6 本)
|
|
43
|
-
const CHUNK = 6;
|
|
44
|
-
const books = [];
|
|
45
|
-
for (let i = 0; i < bookIds.length; i += CHUNK) {
|
|
46
|
-
if (signal?.aborted) break;
|
|
47
|
-
const chunk = bookIds.slice(i, i + CHUNK);
|
|
48
|
-
const details = await Promise.all(chunk.map(id => fetchDetail(ctx, id, signal)));
|
|
49
|
-
for (const d of details) {
|
|
50
|
-
if (d) books.push(d);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return books.length > 0
|
|
55
|
-
? { ok: true, books }
|
|
56
|
-
: { ok: false, books: [], error: 'no books collected' };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function httpGet(ctx, url, signal) {
|
|
60
|
-
let timerDispose;
|
|
61
|
-
const timeout = new Promise((_, reject) => {
|
|
62
|
-
timerDispose = ctx.timeout(() => reject(new Error('timeout')), 15000);
|
|
63
|
-
});
|
|
64
|
-
try {
|
|
65
|
-
const res = await Promise.race([
|
|
66
|
-
fetch(url, {
|
|
67
|
-
headers: {
|
|
68
|
-
'User-Agent': 'Mozilla/5.0 (compatible; fancy-webnovel/1.0)',
|
|
69
|
-
'Accept': 'text/html',
|
|
70
|
-
'Accept-Language': 'zh-CN',
|
|
71
|
-
},
|
|
72
|
-
signal,
|
|
73
|
-
}),
|
|
74
|
-
timeout,
|
|
75
|
-
]);
|
|
76
|
-
if (!res.ok) return { ok: false, status: res.status, body: '', error: `HTTP ${res.status}` };
|
|
77
|
-
const body = await res.text();
|
|
78
|
-
return { ok: true, status: res.status, body };
|
|
79
|
-
} catch (err) {
|
|
80
|
-
return { ok: false, status: 0, body: '', error: err.message };
|
|
81
|
-
} finally {
|
|
82
|
-
try { timerDispose?.(); } catch (_) {}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function extractBookIds(html) {
|
|
87
|
-
const ids = [];
|
|
88
|
-
// 两种布局:表格行和交替行
|
|
89
|
-
const tableRows = html.match(/<tr[^>]*>[\s\S]*?<\/tr>/gi) ?? [];
|
|
90
|
-
for (const row of tableRows) {
|
|
91
|
-
const m = row.match(/onebook\.php\?novelid=(\d+)/);
|
|
92
|
-
if (m) ids.push(m[1]);
|
|
93
|
-
}
|
|
94
|
-
// 交替行布局: 书名 / 作者 交替
|
|
95
|
-
if (!ids.length) {
|
|
96
|
-
const novelLinks = html.match(/novelid=(\d+)/g) ?? [];
|
|
97
|
-
for (const link of novelLinks) {
|
|
98
|
-
const id = link.match(/(\d+)/)?.[1];
|
|
99
|
-
if (id && !ids.includes(id)) ids.push(id);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return [...new Set(ids)].slice(0, 60); // 最多 60 本
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function fetchDetail(ctx, novelid, signal) {
|
|
106
|
-
let timerDispose;
|
|
107
|
-
const timeout = new Promise((_, reject) => {
|
|
108
|
-
timerDispose = ctx.timeout(() => reject(new Error('timeout')), 10000);
|
|
109
|
-
});
|
|
110
|
-
try {
|
|
111
|
-
const res = await Promise.race([
|
|
112
|
-
fetch(`${DETAIL_BASE}?novelid=${novelid}`, { signal }),
|
|
113
|
-
timeout,
|
|
114
|
-
]);
|
|
115
|
-
if (!res.ok) return null;
|
|
116
|
-
const buf = await res.arrayBuffer();
|
|
117
|
-
const h = new TextDecoder('gb18030').decode(new Uint8Array(buf));
|
|
118
|
-
|
|
119
|
-
const prop = (/** @type {string} */ name) => {
|
|
120
|
-
const m = h.match(new RegExp(`itemprop="${name}"[^>]*>([^<]*)<`));
|
|
121
|
-
return m ? m[1].trim() : '';
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
rank: 0,
|
|
126
|
-
title: prop('title') || prop('novelname') || '',
|
|
127
|
-
author: prop('author') || '',
|
|
128
|
-
category: '',
|
|
129
|
-
words: parseInt(prop('wordCount').replace(/[^\d]/g, ''), 10) || 0,
|
|
130
|
-
collect: prop('collectedCount') || '',
|
|
131
|
-
nutrition: prop('nutritionCount') || '',
|
|
132
|
-
score: prop('scoreCount') || '',
|
|
133
|
-
status: (h.match(/(连载中|已完结|完结)/) || [, ''])[1],
|
|
134
|
-
intro: (h.match(/<meta[^>]+name="description"[^>]+content="([^"]*)"/i)?.[1] ?? '').slice(0, 150),
|
|
135
|
-
cover: '',
|
|
136
|
-
bookId: novelid,
|
|
137
|
-
};
|
|
138
|
-
} catch (_) {
|
|
139
|
-
return null;
|
|
140
|
-
} finally {
|
|
141
|
-
try { timerDispose?.(); } catch (_) {}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* qidian.js — 起点排行榜采集
|
|
3
|
-
*
|
|
4
|
-
* 策略:纯 HTTP mobile SSR。移动端页面在 script 标签里内嵌完整的
|
|
5
|
-
* pageContext JSON,绕过了服务端渲染的加密,直接提取书籍数据。
|
|
6
|
-
* 无需 Playwright。
|
|
7
|
-
*
|
|
8
|
-
* Rank paths (mobile, slug-based):
|
|
9
|
-
* /rank/hotsales/ 畅销榜
|
|
10
|
-
* /rank/yuepiao/ 月票榜
|
|
11
|
-
* /rank/newbook/ 新书榜
|
|
12
|
-
* /rank/newauthor/ 新人作者榜
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const MOBILE_BASE = 'https://m.qidian.com';
|
|
16
|
-
|
|
17
|
-
// rank.id → URL slug, matches RANK_PATHS keys used by scrapeRank()
|
|
18
|
-
const RANK_PATHS = {
|
|
19
|
-
hotsales: '/rank/hotsales/',
|
|
20
|
-
yuepiao: '/rank/yuepiao/',
|
|
21
|
-
newbook: '/rank/newbook/',
|
|
22
|
-
newauthor: '/rank/newauthor/',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const platform = 'qidian';
|
|
26
|
-
export const label = '起点';
|
|
27
|
-
|
|
28
|
-
export const rankList = [
|
|
29
|
-
{ id: 'hotsales', label: '畅销榜', channel: '1', type: 'hotsales' },
|
|
30
|
-
{ id: 'yuepiao', label: '月票榜', channel: '1', type: 'yuepiao' },
|
|
31
|
-
{ id: 'newbook', label: '新书榜', channel: '1', type: 'newbook' },
|
|
32
|
-
{ id: 'newauthor', label: '新人作者榜', channel: '1', type: 'newauthor' },
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const HEADERS = {
|
|
36
|
-
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1',
|
|
37
|
-
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
38
|
-
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
39
|
-
'Accept-Encoding': 'identity',
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Scrape one rank list.
|
|
44
|
-
* @param {string} rankId - rank id (e.g. 'hotsales')
|
|
45
|
-
* @param {object} ctx - Cordis plugin context
|
|
46
|
-
* @param {AbortSignal} signal
|
|
47
|
-
* @returns {Promise<{ ok: boolean, books: object[], error?: string }>}
|
|
48
|
-
*/
|
|
49
|
-
export async function scrapeRank(rankId, ctx, signal) {
|
|
50
|
-
const path = RANK_PATHS[rankId];
|
|
51
|
-
if (!path) return { ok: false, books: [], error: `unknown rank: ${rankId}` };
|
|
52
|
-
|
|
53
|
-
const url = MOBILE_BASE + path;
|
|
54
|
-
|
|
55
|
-
const { ok, status, body, error } = await httpGet(ctx, url, signal);
|
|
56
|
-
if (!ok) return { ok: false, books: [], error: error ?? `HTTP ${status}` };
|
|
57
|
-
|
|
58
|
-
// Extract pageContext from <script id="vite-plugin-ssr_pageContext">
|
|
59
|
-
const m = body.match(/<script[^>]+id=["']vite-plugin-ssr_pageContext["'][^>]*>([\s\S]*?)<\/script>/i);
|
|
60
|
-
if (!m) return { ok: false, books: [], error: 'pageContext not found' };
|
|
61
|
-
|
|
62
|
-
let pageContext;
|
|
63
|
-
try {
|
|
64
|
-
pageContext = JSON.parse(m[1]);
|
|
65
|
-
} catch {
|
|
66
|
-
return { ok: false, books: [], error: 'pageContext JSON parse failed' };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const records = pageContext?.pageContext?.pageProps?.pageData?.records ?? [];
|
|
70
|
-
if (!records.length) return { ok: false, books: [], error: 'no book records found' };
|
|
71
|
-
|
|
72
|
-
const books = records.map((r) => ({
|
|
73
|
-
rank: r.rankNum ?? 0,
|
|
74
|
-
title: r.bName ?? '',
|
|
75
|
-
author: r.bAuth ?? '',
|
|
76
|
-
category: r.cat ?? '',
|
|
77
|
-
words: r.cnt ?? '0',
|
|
78
|
-
intro: (r.desc ?? '').slice(0, 150),
|
|
79
|
-
bookId: r.bid ?? '',
|
|
80
|
-
}));
|
|
81
|
-
|
|
82
|
-
return { ok: true, books };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async function httpGet(ctx, url, signal) {
|
|
86
|
-
let timerDispose;
|
|
87
|
-
const timeout = new Promise((_, reject) => {
|
|
88
|
-
timerDispose = ctx.timeout(() => reject(new Error('timeout')), 15000);
|
|
89
|
-
});
|
|
90
|
-
try {
|
|
91
|
-
const res = await Promise.race([
|
|
92
|
-
fetch(url, { headers: HEADERS, signal }),
|
|
93
|
-
timeout,
|
|
94
|
-
]);
|
|
95
|
-
const body = await res.text();
|
|
96
|
-
return { ok: res.ok, status: res.status, body };
|
|
97
|
-
} catch (err) {
|
|
98
|
-
return { ok: false, status: 0, body: '', error: err.message };
|
|
99
|
-
} finally {
|
|
100
|
-
try { timerDispose?.(); } catch (_) {}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* qimao.js — 七猫小说排行榜采集
|
|
3
|
-
*
|
|
4
|
-
* 策略:纯 HTTP。榜单页通过 XHR 加载 JSON 数据。
|
|
5
|
-
* 无需 Playwright。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export const platform = 'qimao';
|
|
9
|
-
export const label = '七猫';
|
|
10
|
-
|
|
11
|
-
export const rankList = [
|
|
12
|
-
{ id: 'male_hot', label: '男生大热榜', channel: 'male', type: 'hot' },
|
|
13
|
-
{ id: 'male_new', label: '男生新书榜', channel: 'male', type: 'new' },
|
|
14
|
-
{ id: 'female_hot', label: '女生大热榜', channel: 'female', type: 'hot' },
|
|
15
|
-
{ id: 'female_new', label: '女生新书榜', channel: 'female', type: 'new' },
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
const RANK_URL = 'https://www.qimao.com/paihang';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Scrape one rank list.
|
|
22
|
-
* @param {string} rankId - e.g. 'male_hot'
|
|
23
|
-
* @param {object} ctx - Cordis plugin context
|
|
24
|
-
* @param {AbortSignal} signal
|
|
25
|
-
* @returns {Promise<{ ok: boolean, books: object[], error?: string }>}
|
|
26
|
-
*/
|
|
27
|
-
export async function scrapeRank(rankId, ctx, signal) {
|
|
28
|
-
const [channelId, rankTypeId] = rankId.split('_');
|
|
29
|
-
|
|
30
|
-
const channelMap = { male: 'boy', female: 'girl' };
|
|
31
|
-
const rankTypeMap = { hot: 'hot', new: 'new' };
|
|
32
|
-
const channel = channelMap[channelId] ?? channelId;
|
|
33
|
-
const rankType = rankTypeMap[rankTypeId] ?? rankTypeId;
|
|
34
|
-
|
|
35
|
-
const url = `${RANK_URL}/${channel}/${rankType}/date/`;
|
|
36
|
-
|
|
37
|
-
const { ok, status, body, error } = await httpGet(ctx, url, signal);
|
|
38
|
-
if (!ok) return { ok: false, books: [], error: error ?? `HTTP ${status}` };
|
|
39
|
-
|
|
40
|
-
const books = parseBooks(body, channelId, rankTypeId);
|
|
41
|
-
return books.length > 0
|
|
42
|
-
? { ok: true, books }
|
|
43
|
-
: { ok: false, books: [], error: 'no books found in page' };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function httpGet(ctx, url, signal) {
|
|
47
|
-
let timerDispose;
|
|
48
|
-
const timeout = new Promise((_, reject) => {
|
|
49
|
-
timerDispose = ctx.timeout(() => reject(new Error('timeout')), 15000);
|
|
50
|
-
});
|
|
51
|
-
try {
|
|
52
|
-
const res = await Promise.race([
|
|
53
|
-
fetch(url, {
|
|
54
|
-
headers: {
|
|
55
|
-
'User-Agent': 'Mozilla/5.0 (compatible; fancy-webnovel/1.0)',
|
|
56
|
-
'Accept': 'text/html,application/xhtml+xml',
|
|
57
|
-
'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
58
|
-
},
|
|
59
|
-
signal,
|
|
60
|
-
}),
|
|
61
|
-
timeout,
|
|
62
|
-
]);
|
|
63
|
-
const body = await res.text();
|
|
64
|
-
return { ok: res.ok, status: res.status, body };
|
|
65
|
-
} catch (err) {
|
|
66
|
-
return { ok: false, status: 0, body: '', error: err.message };
|
|
67
|
-
} finally {
|
|
68
|
-
try { timerDispose?.(); } catch (_) {}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function parseBooks(html, channelId, rankTypeId) {
|
|
73
|
-
const books = [];
|
|
74
|
-
|
|
75
|
-
// 尝试从 JSON 数据块提取
|
|
76
|
-
const jsonMatch = html.match(/var\s+RANK_DATA\s*=\s*(\{.*?\});/s)
|
|
77
|
-
?? html.match(/window\.__INITIAL_STATE__\s*=\s*(\{.*?\});/s);
|
|
78
|
-
|
|
79
|
-
if (jsonMatch) {
|
|
80
|
-
try {
|
|
81
|
-
const data = JSON.parse(jsonMatch[1]);
|
|
82
|
-
const list = data?.rankList ?? data?.bookList ?? data?.books ?? [];
|
|
83
|
-
return normalizeBooks(list, channelId, rankTypeId);
|
|
84
|
-
} catch (_) { /* fall through */ }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// DOM 解析: 从页面 HTML 提取书籍信息
|
|
88
|
-
// 匹配模式: <a class="book-title">书名</a> ... <span class="author">作者</span>
|
|
89
|
-
const titleMatches = [...html.matchAll(/class="(?:book-)?title[^"]*"[^>]*>([^<]+)<\/a>/g)];
|
|
90
|
-
const authorMatches = [...html.matchAll(/class="author[^"]*"[^>]*>([^<]+)<\/a>/g)];
|
|
91
|
-
const rankMatches = [...html.matchAll(/class="(?:rank|num)[^"]*"[^>]*>(\d+)<\/span>/g)];
|
|
92
|
-
|
|
93
|
-
const count = Math.min(titleMatches.length, authorMatches.length);
|
|
94
|
-
for (let i = 0; i < count; i++) {
|
|
95
|
-
const title = (titleMatches[i][1] ?? '').trim();
|
|
96
|
-
const author = (authorMatches[i][1] ?? '').trim();
|
|
97
|
-
if (!title || /^(上一页|下一页|跳转)$/.test(title)) continue;
|
|
98
|
-
if (!author || /^(上一页|下一页|跳转|友情链接)$/.test(author)) continue;
|
|
99
|
-
|
|
100
|
-
books.push({
|
|
101
|
-
rank: rankMatches[i] ? parseInt(rankMatches[i][1], 10) : (i + 1),
|
|
102
|
-
title,
|
|
103
|
-
author,
|
|
104
|
-
category: '',
|
|
105
|
-
words: 0,
|
|
106
|
-
intro: '',
|
|
107
|
-
cover: '',
|
|
108
|
-
bookId: '',
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return books;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function normalizeBooks(list, channelId, rankTypeId) {
|
|
116
|
-
if (!Array.isArray(list)) return [];
|
|
117
|
-
return list.map((b, i) => ({
|
|
118
|
-
rank: b.rank ?? (i + 1),
|
|
119
|
-
title: b.title ?? b.bookTitle ?? '',
|
|
120
|
-
author: b.author ?? '',
|
|
121
|
-
category: b.categoryName ?? b.typeName ?? '',
|
|
122
|
-
words: b.wordCount ?? b.words ?? 0,
|
|
123
|
-
intro: (b.description ?? '').slice(0, 150),
|
|
124
|
-
cover: b.cover ?? b.thumbnail ?? '',
|
|
125
|
-
bookId: b.bookId ?? b.id ?? '',
|
|
126
|
-
}));
|
|
127
|
-
}
|