Skip to content

feat: 切换分集时自动沿用已手动选定的弹幕源 - #2709

Open
LOVE-START wants to merge 1 commit into
Predidit:mainfrom
LOVE-START:feat/danmaku-source-memory
Open

LOVE-START wants to merge 1 commit into
Predidit:mainfrom
LOVE-START:feat/danmaku-source-memory

Conversation

@LOVE-START

@LOVE-START LOVE-START commented Oct 15, 2026 •

Copy link
Copy Markdown

描述

同一部剧集内切换分集时,弹幕源需重新手动选择并等待加载。现在用户手动选定并成功加载弹幕源后会被记住,后续切换分集直接沿用同一弹幕源的对应集。实现上以 BgmBangumiID 为键持久化「弹幕源番剧 ID + 选择时的弹幕源集号 + 选择时正在播放的 Bgm 集号」,用集号之差做偏移换算;加载时优先使用记忆源,未记住、换算后集号非法、该集暂无弹幕或记忆源请求失败时回退到原有自动匹配,保证不会因为记忆失效而完全没有弹幕。

关联的 Issues

无

PR 类型

  • Bug 修复
  • 添加新功能
  • 重构实现
  • 文档或格式
  • 其它

AI 辅助开发

  • 没有使用 AI 辅助
  • AI 辅助开发了部分功能,但是我已检查并理解 AI 所写的代码
  • 基本上都由 AI 实现,但是我非常了解 AI 的代码与写完的产物

AI 辅助模型: glm5.3

提交前检查

  • 我已经填写了 PR 模板中的所有内容
  • 我已经阅读了 贡献指引 ,并遵守指引进行开发
  • 这个 PR 的功能已经经过我的测试,并且我完全理解我(或 AI)做出的改动

附注

  • 已通过 flutter analyze(无告警)与 flutter test 全量用例。
  • 本 PR 与 fix: 弹幕搜索历史支持长按/右键删除记录 #2704 相互独立,修改的代码区域不重叠,二者可分别合入。
  • 受本机网络环境限制,弹弹 play 接口返回 403,尚未完成真机端到端验证,故最后一项检查保持未勾选。

用户在弹幕源面板手动选定弹幕源并成功加载后,以 BgmBangumiID 为键
持久化记录弹幕源番剧 ID、所选弹幕源集号与选择时正在播放的 Bgm 集号;
同一部剧集切换分集时,按集号偏移直接沿用同一弹幕源的对应集,无需
重复手动选择。未记住、换算后集号非法、该集暂无弹幕或记忆源请求失败
时,回退到原有自动匹配逻辑,保证记忆失效时不会完全没有弹幕。
unawaited(DanmakuSourceMemory.remember(
bgmBangumiId: widget.bangumiId,
animeId: animeId,
episodeNumber: danmakuEpisodeNumber,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Remembered episode number is the list position, not the number encoded in the episode ID

danmakuEpisodeNumber comes from _visibleEpisodes, where it is just index + 1 in the DanDanPlay episode list. On replay, DanmakuApi.getDanDanmaku(animeId, sourceEpisode) builds the episode ID as '$animeId${sourceEpisode.padLeft(4, '0')}', so the stored value has to match the suffix of episode.episodeId, not the list index. The two drift apart when a source's numbering doesn't start at 1 (for example, a split-cour season listed as episodes 13–24) or when the list has a leading special/episode 0 entry. In that case the remembered source either can't resolve the episode the user just picked (it silently falls back to auto-match) or, worse, loads danmaku from a different episode of the same source, and the empty-result fallback won't catch that.

Derive the number from the selected episode's ID instead, e.g. pass episode into _rememberSelectedSource and store episode.episodeId % 10000. Only remember it when episode.episodeId ~/ 10000 == animeId, so episode IDs that don't follow this convention are never persisted.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
lib/pages/player/danmaku_source_sheet.dart 250 The remembered source episode number is the list position (index + 1), but getDanDanmaku rebuilds the episode ID from it as animeId + padLeft(4). Sources whose numbering doesn't start at 1, or whose list has a leading special or episode 0, will resolve to the wrong episode or fail to resolve at all. Derive the number from episode.episodeId instead.
Files Reviewed (5 files)
  • lib/modules/danmaku/danmaku_source_memory.dart - 0 issues
  • lib/pages/player/controller/player_danmaku_controller.dart - 0 issues
  • lib/pages/player/danmaku_source_sheet.dart - 1 issue
  • lib/pages/player/player_item.dart - 0 issues
  • lib/services/storage/storage.dart - 0 issues

Fix these issues in Kilo Cloud


Reviewed by claude-opus-5.5 · Input: 270 · Output: 4.9K · Cached: 470.1K

@Predidit

Copy link
Copy Markdown
Owner

想知道这个PR还在你的视野范围内吗,你如何看待 kilo bot 提出的这个可能导致集数混乱的问题

@Predidit

Copy link
Copy Markdown
Owner

以及 kilo bot 没有提过,离线缓存功能似乎绕过了此实现,这符合你的预期吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants