feat(subscribe): 新增订阅总集数刷新与完成检查链式事件#5860
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces two new event types, SubscribeEpisodesRefresh and SubscribeCompletionCheck, along with their corresponding event data schemas. These events allow external plugins to override the default total episode count (calculated via TMDB) and to veto or cancel the automatic completion of a subscription. In app/chain/subscribe.py, these events are integrated into the subscription creation, refresh, precheck, and completion flows. The review feedback points out a potential issue where overriding the total episode count to a smaller value could result in a negative lack_episode count, and suggests using max(..., 0) to prevent this.
| tmdbid=subscribe.tmdbid, doubanid=subscribe.doubanid, | ||
| subscribe_id=subscribe.id, scene="refresh") | ||
| # 总集数增长按 delta 同步抬升 lack | ||
| lack_episode = (subscribe.lack_episode or 0) + (total_episode - (subscribe.total_episode or 0)) |
There was a problem hiding this comment.
当外部插件或事件将 total_episode 覆盖为比当前值更小的值时(例如,修正集数口径),计算得到的 lack_episode 可能会变成负数。建议使用 max(..., 0) 进行保护,以防止 lack_episode 出现负值,确保数据一致性。
| lack_episode = (subscribe.lack_episode or 0) + (total_episode - (subscribe.total_episode or 0)) | |
| lack_episode = max((subscribe.lack_episode or 0) + (total_episode - (subscribe.total_episode or 0)), 0) |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
014d62e to
a2171f4
Compare
背景
订阅的「总集数推算」与「完成判定」目前在主程序内硬编码:总集数恒取 TMDB 季集数
len(seasons[season]),完成判定恒以lack=0收口。缺少像Resource*/Transfer*那样的链式扩展点,外部无法按自身策略修正集数口径或否决一次自动完成。改动
对标既有链式事件体系,新增两个订阅域链式事件(
ChainEventData派生,输入/输出分区,统一cancel/updated/source/reason):SubscribeEpisodesRefresh(subscribe.episodes.refresh)
推算某季总集数时发出,外部可覆盖
total_episode。统一覆盖全部 4 个推算点:创建订阅(同步/异步)、元数据刷新check()、完成前兜底__refresh_total_episode_before_completion;为此抽出公共方法__apply_episodes_refresh(含异步版),并将兜底方法改为实例方法。覆盖值仍受各调用点既有校验(如「只增不减」)约束。SubscribeCompletionCheck(subscribe.completion.check)
在
__finish_subscribe写历史并删除之前发出,外部可否决本次自动完成;被否决时仅跳过收口、不写订阅状态。挂载于唯一收口执行点,覆盖普通订阅与洗版的全部完成路径;命令式手动删除不受影响。兼容性
无监听者或外部未覆盖/未否决时,输出默认值(
updated=False/cancel=False)使主程序行为与改动前等价,属纯增量扩展点。验证
python -m py_compile三处改动文件通过;app.schemas导入,默认cancel/updated均为 False;pylint -E对改动文件零 error。本 PR 为 Claude Code 协作提交。