Skip to content

Commit 806395c

Browse files
HarryXin0919claude
andcommitted
Fix external-review issues: dedup OFF_MARKERS, paginate Bilibili, validate creators, version cap, retire bidao pilot, add tests + CI
Robustness / bugs: - shared_markers.py: single source for OFF_MARKERS (FULL for features, COMPARE for compare_form -- the deliberate livestream / 联名 divergence preserved, behavior unchanged), ending the silent drift between the two copies. - fetch_bilibili.py: paginate up to num (was first-page-only -> missed data past 50); add BilibiliError mirroring YouTubeError; factor out _to_record / _get_page. - creators.py: validate_creators() lists ALL config problems (typo'd keys, missing alias/zone, duplicate alias, youtube missing channel) instead of a KeyError at fetch time; called at the start of fetch_multi. - Cap bilibili-api-python <18.0.0 (requirements.txt + pyproject.toml). - schema.py: VideoRecord TypedDict documenting the standard video record. Cleanup -- retire the single-creator pilot cluster (bidao-hardcoded, mutually coupled via classified.json, superseded by the generalized features/scan_signals pipeline, and absent from every pipeline / README command list): - delete classify_and_stats.py, fetch_videos.py, and the orphaned consumers comments.py + subtitle.py (they read the now-gone classified.json); drop all four from the PyInstaller spec hiddenimports; add shared_markers + schema. - anonymize remaining bidao / real-BV references in analyze_video.py + diagnose.py docstrings; reword the README L2-text line to the surviving compare_meme.py. Tests + CI (the project had zero tests): - conftest.py + tests/ (23 tests): features.extract, off_tag, OFF_MARKERS divergence, validate_creators, spearman, build_report formatters, runtime paths, and fetch_bilibili parse/record/error + pagination (incl. the >50-video multi-page path). - pyproject dev extra + pytest config; CI now runs pytest. Deliberately skipped (with reasons): scripts/ -> subpackage restructure (would break the released PyInstaller packaging), web CSRF/rate-limit (localhost-only app), scipy for spearman (intentional zero-dep). Two report claims were verified already-fine and left alone: scan_signals already degrades on missing data; requirements/pyproject are already aligned. Verified: 23 tests pass, compileall clean, viralens --help ok, frozen build succeeds and --vl-exec compare_form / fetch_multi / build_report all work (new modules bundled, BilibiliError surfaces correctly). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3c4cf43 commit 806395c

22 files changed

Lines changed: 401 additions & 618 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ jobs:
1515
uses: actions/setup-python@v5
1616
with:
1717
python-version: "3.11"
18-
- name: Install (editable, deps from pyproject)
19-
run: pip install -e .
18+
- name: Install (editable + dev deps from pyproject)
19+
run: pip install -e ".[dev]"
2020
- name: Syntax check (compile all scripts)
2121
run: python -m compileall scripts
2222
- name: Smoke test (console entry point)
2323
run: viralens --help
24+
- name: Unit tests
25+
run: pytest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ creators.py ──▶ fetch_multi.py ──▶ data/<alias>_videos.json (
239239
- **Signal scanner** (`scan_signals`): turns each video into a universal feature vector, then auto-tests
240240
every dimension (title patterns, length buckets, daypart, cover metrics…) for high/low-play separation,
241241
ranks by effect size, and reports which levers are *universal* vs *creator-specific*.
242-
- **L2 — text** (`subtitle`, `comments`): subtitles + hot comments → `jieba` keyword analysis.
242+
- **L2 — text**: subtitles + hot comments → `jieba` keyword analysis (cross-creator comment-engagement test: `compare_meme.py`).
243243
- **Cross-creator / cross-zone gate**: a pattern earns a ✅ only if it survives the *same test* on
244244
multiple independent creators **and** more than one zone.
245245

conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Let pytest import the flat scripts/ modules without installing the package."""
2+
import sys
3+
from pathlib import Path
4+
5+
sys.path.insert(0, str(Path(__file__).parent / "scripts"))

packaging/viralens.spec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ hiddenimports += [
5050
"fetch_multi", "fetch_bilibili", "fetch_youtube",
5151
"compare_form", "creator_profile", "scan_signals", "charts", "export_data", "build_report",
5252
"diagnose", "analyze_video", "import_private",
53-
"creators", "features", "benchmarks",
54-
"classify_and_stats", "comments", "compare_meme", "fetch_covers",
55-
"fetch_videos", "resolve_creators", "subtitle",
53+
"creators", "features", "benchmarks", "shared_markers", "schema",
54+
"compare_meme", "fetch_covers",
55+
"resolve_creators",
5656
]
5757

5858
# —— 只读资源:网页界面 + 配置模板 —— 放进打包根目录,app.py 用 runtime.ASSET_DIR 找它们 ——

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ classifiers = [
1919
"Topic :: Scientific/Engineering :: Information Analysis",
2020
]
2121
dependencies = [
22-
"bilibili-api-python>=17.0.0",
22+
"bilibili-api-python>=17.0.0,<18.0.0",
2323
"jieba>=0.42.1",
2424
"matplotlib>=3.7.0",
2525
"Pillow>=9.0.0",
2626
"numpy>=1.23.0",
2727
]
2828

29-
# 仅在「打包成桌面 app」时需要:原生窗口后端。源码 CLI / 网页界面都不依赖它
29+
# gui = 打包成桌面 app 时的原生窗口后端;dev = 跑测试。源码 CLI / 网页界面都不依赖它们
3030
[project.optional-dependencies]
3131
gui = ["pywebview>=5.0"]
32+
dev = ["pytest>=7.0"]
3233

3334
[project.urls]
3435
Homepage = "https://github.com/HarryXin0919/viralens"
@@ -45,3 +46,6 @@ py-modules = ["viralens"]
4546

4647
[tool.setuptools.package-dir]
4748
"" = "scripts"
49+
50+
[tool.pytest.ini_options]
51+
testpaths = ["tests"]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# viralens — runtime dependencies
22
# Install: pip install -r requirements.txt
3-
bilibili-api-python>=17.0.0 # async Bilibili public-data access
3+
bilibili-api-python>=17.0.0,<18.0.0 # async Bilibili public-data access (cap: 18.x may break API)
44
jieba>=0.42.1 # Chinese word segmentation (comment keyword analysis)
55
matplotlib>=3.7.0 # static README charts (PNG)
66
Pillow>=9.0.0 # cover-image analysis (optional step: fetch_covers.py)

scripts/analyze_video.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
按需调用:用户在诊断页点「分析开头+配乐」才下这一条,不批量下 700 条。
1717
1818
命令行单测:
19-
python analyze_video.py bidao BV1mT421Y7mE
20-
python analyze_video.py mrbeast 0BjlBnfHcHM
21-
python analyze_video.py bidao BV1mT421Y7mE --force # 忽略缓存重算
19+
python analyze_video.py <alias> <vid> # 如 demo_b1 BVxxxxxxxxxx
20+
python analyze_video.py <alias> <youtube_vid> # YouTube 视频 id
21+
python analyze_video.py <alias> <vid> --force # 忽略缓存重算
2222
"""
2323
import base64
2424
import json

scripts/classify_and_stats.py

Lines changed: 0 additions & 119 deletions
This file was deleted.

scripts/comments.py

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)