feat(matrix): 「第一条视频」改成主页最早一条,后台翻页扫描 + 缓存
要的是这个博主**最早发的**那条(可能根本不在监控目标里),不是主页第一屏。 按游标翻到底才知道,所以: - 新增 monitor_creator_first_video 缓存表,按 sec_uid 存最早发布时间, 30 天内不再扫; - 调度器后台任务慢慢扫(每页 20 条、页间 0.5 秒、单次最多 50 页 / 3 分钟), 不占调度循环; - 矩阵只读缓存,读不到退回库里最早的一条作品; - 失败只锁 6 小时再试,不会把没扫到的号锁 30 天。 同时撤掉上一版「每轮采集多问一次主页最新视频」的实现(方向反了)。
This commit is contained in:
@@ -178,18 +178,13 @@ class TestNoteMode:
|
||||
「粘贴作品链接的监控」今天本来是能用的,别让它因为这一处走错而废掉。
|
||||
"""
|
||||
|
||||
async def only_by_creator_id(sec_user_id, count=20, *, cookie="", identity=None):
|
||||
# 可以为了「主页最新视频」问一次作品列表,但**只能用详情里的 sec_uid 问**,
|
||||
# 不能拿作品目标 id 去当 sec_uid —— 那必然失败,而且报错很难看懂。
|
||||
assert sec_user_id == "MS4wLjABAAAAtestsecuid"
|
||||
return []
|
||||
async def must_not_be_called(*args, **kwargs):
|
||||
raise AssertionError("作品模式不该去拉博主的作品列表")
|
||||
|
||||
async def fake_detail(aweme_id, *, cookie="", identity=None):
|
||||
record = _video(aweme_id)
|
||||
record["creator_id"] = "MS4wLjABAAAAtestsecuid"
|
||||
return record
|
||||
return _video(aweme_id)
|
||||
|
||||
monkeypatch.setattr(douyin_api, "author_videos", only_by_creator_id)
|
||||
monkeypatch.setattr(douyin_api, "author_videos", must_not_be_called)
|
||||
monkeypatch.setattr(douyin_api, "video_detail", fake_detail)
|
||||
|
||||
result = await _collect(
|
||||
@@ -263,33 +258,6 @@ class TestNoteMode:
|
||||
# 详情里没有作品总数,留 None 而不是 0。
|
||||
assert profiles[0]["works"] is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_the_latest_video_time_comes_from_the_profile(self, monkeypatch, tmp_path):
|
||||
"""主页第一条视频可能不在监控目标里 —— 单独问一次,用它的发布时间。"""
|
||||
|
||||
async def fake_detail(aweme_id, *, cookie="", identity=None):
|
||||
record = _video(aweme_id)
|
||||
record.update(
|
||||
{"creator_id": "MS4wLjABAAAAtestsecuid", "creator_fans": 10}
|
||||
)
|
||||
return record
|
||||
|
||||
async def fake_videos(sec_user_id, count=20, *, cookie="", identity=None):
|
||||
assert sec_user_id == "MS4wLjABAAAAtestsecuid"
|
||||
return [{"create_time": 1793000000}]
|
||||
|
||||
monkeypatch.setattr(douyin_api, "video_detail", fake_detail)
|
||||
monkeypatch.setattr(douyin_api, "author_videos", fake_videos)
|
||||
|
||||
await _collect(
|
||||
tmp_path, mode="note", want_comments=False, targets=[_Target("111")]
|
||||
)
|
||||
|
||||
profiles = _read(
|
||||
list((tmp_path / "douyin" / "jsonl").glob("*_profile_*.jsonl"))[0]
|
||||
)
|
||||
assert profiles[0]["latest_published_at"] == 1793000000 * 1000
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_no_stats_means_no_profile_row(self, monkeypatch, tmp_path):
|
||||
"""精简版 author(字段全缺)不该写一条全 NULL 的快照。"""
|
||||
@@ -420,10 +388,7 @@ class TestCreatorProfile:
|
||||
|
||||
await _collect(tmp_path, want_comments=False)
|
||||
|
||||
profile = self._profiles(tmp_path)[0]
|
||||
# 作品列表里的最新一条也带出来了(秒 -> 毫秒)。
|
||||
assert profile.pop("latest_published_at") == 1790574515 * 1000
|
||||
assert profile == _profile()
|
||||
assert self._profiles(tmp_path) == [_profile()]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_the_profile_is_keyed_by_the_same_hash_as_the_works(
|
||||
|
||||
Reference in New Issue
Block a user