feat(snapshot): refresh API video metadata; keep removed visible

入库 / 小时近新片 / 全量快照成功时以 view_detail 覆盖 title、duration、
pages、cover、bvid、up_*、pubdate 等接口字段,并照旧写七项快照。
原站失效仅标 removed,不删行、不空写元数据;列表与详情继续展示,
快照队列仍跳过 removed。
This commit is contained in:
bot-ci committed 2026-11-03 23:01:15 +08:00
1 parent 99b71c037c
commit 6c73904b25
8 files changed
+329 -34

No files matched your search

+68
View File
@@ -408,6 +408,72 @@ def test_up_follower_snapshot_and_backfill():
db.close()
def test_refresh_video_metadata_overwrites_api_fields_keeps_nulls():
with tempfile.TemporaryDirectory() as tmp:
db, repo = setup(tmp)
try:
repo.upsert_from_fav(resource(9, pages=1), F1.media_id, was_added=True)
ok = repo.refresh_video_metadata(
aid=9,
bvid="BVnew9",
title="刷新后",
up_mid=200,
up_name="新名",
pubdate=1_710_000_000,
duration=999,
pages=5,
cover="http://example/new.png",
up_face="http://example/face.png",
now=1_800_000_100,
)
assert ok is True
video = repo.get_video(9)
assert video["title"] == "刷新后"
assert video["duration"] == 999
assert video["pages"] == 5
assert video["bvid"] == "BVnew9"
assert video["up_mid"] == 200
assert video["cover"] == "http://example/new.png"
assert video["status"] == "active"
# 空值不冲掉
ok = repo.refresh_video_metadata(
aid=9,
bvid=None,
title="",
up_mid=None,
up_name=None,
pubdate=0,
duration=None,
pages=None,
cover=None,
up_face=None,
now=1_800_000_200,
)
assert ok is True
video = repo.get_video(9)
assert video["title"] == "刷新后"
assert video["duration"] == 999
assert video["pages"] == 5
assert video["bvid"] == "BVnew9"
# 不存在的 aid
assert repo.refresh_video_metadata(
aid=404,
bvid=None, title="x", up_mid=None, up_name=None, pubdate=1,
) is False
# removed 后 refresh 也不改 status
repo.set_video_status(9, "removed")
repo.refresh_video_metadata(
aid=9, bvid="BVkeep", title="仍在", up_mid=200, up_name="新名",
pubdate=1_710_000_000, duration=1000, pages=6,
)
video = repo.get_video(9)
assert video["status"] == "removed"
assert video["title"] == "仍在"
assert video["pages"] == 6
finally:
db.close()
def main():
test_upsert_and_folder_resource()
test_invalid_attr_and_missing()
@@ -422,8 +488,10 @@ def main():
test_pending_snapshot_aids()
test_upsert_snapshot_preserves_view_open()
test_up_follower_snapshot_and_backfill()
test_refresh_video_metadata_overwrites_api_fields_keeps_nulls()
print("OK: 收藏夹/视频状态机与黑名单测试全部通过")
if __name__ == "__main__":
main()