fix(transfer): 修复订阅自定义识别词在整理时失效 (#6018)

This commit is contained in:
Pollo3470
2026-06-29 15:49:02 +08:00
committed by GitHub
parent b646cbb4f6
commit 302d8bbf5c
6 changed files with 210 additions and 30 deletions

View File

@@ -2439,6 +2439,32 @@ class TransferChain(ChainBase, ConfigReloadMixin, metaclass=Singleton):
self.__normalize_dir_path(Path(current_item.path).parent),
)
@staticmethod
def _get_subscribe_custom_words(
history_record: Optional[DownloadHistory],
) -> Optional[List[str]]:
"""
获取整理用自定义识别词:优先使用下载时保存的快照,无快照(历史旧记录)时再按来源实时反查订阅。
快照优先可避免整理阶段因订阅季号漂移、来源解析失败或订阅完成被删导致识别词丢失,从而原样入库到偏移前的季集。
"""
if not history_record:
return None
# 下载时保存的完整订阅识别词快照优先
if history_record.custom_words:
return history_record.custom_words.split("\n")
# 兜底:历史旧记录无快照时,按下载来源实时反查订阅
if not isinstance(history_record.note, dict):
return None
subscribe = SubscribeChain().get_subscribe_by_source(
history_record.note.get("source")
)
return (
subscribe.custom_words.split("\n")
if subscribe and subscribe.custom_words
else None
)
def do_transfer(
self,
fileitem: FileItem,
@@ -2515,24 +2541,6 @@ class TransferChain(ChainBase, ConfigReloadMixin, metaclass=Singleton):
# 汇总错误信息
err_msgs: List[str] = []
def _get_subscribe_custom_words(
history_record: Optional[DownloadHistory],
) -> Optional[List[str]]:
"""
根据下载记录获取订阅自定义识别词。
"""
if not history_record or not isinstance(history_record.note, dict):
return None
# 使用source动态获取订阅
subscribe = SubscribeChain().get_subscribe_by_source(
history_record.note.get("source")
)
return (
subscribe.custom_words.split("\n")
if subscribe and subscribe.custom_words
else None
)
def _build_file_meta(
source_path: Path,
custom_word_list: Optional[List[str]] = None,
@@ -2656,7 +2664,7 @@ class TransferChain(ChainBase, ConfigReloadMixin, metaclass=Singleton):
)
return _build_file_meta(
main_path,
custom_word_list=_get_subscribe_custom_words(main_download_history),
custom_word_list=self._get_subscribe_custom_words(main_download_history),
)
def _append_item(
@@ -2814,7 +2822,7 @@ class TransferChain(ChainBase, ConfigReloadMixin, metaclass=Singleton):
bluray_dir=main_bluray_dir,
download_hash=download_hash,
)
subscribe_custom_words = _get_subscribe_custom_words(
subscribe_custom_words = self._get_subscribe_custom_words(
main_download_history
)
main_meta = _build_file_meta(
@@ -2937,7 +2945,7 @@ class TransferChain(ChainBase, ConfigReloadMixin, metaclass=Singleton):
else:
file_meta = _build_file_meta(
file_path,
custom_word_list=_get_subscribe_custom_words(download_history),
custom_word_list=self._get_subscribe_custom_words(download_history),
)
else:
file_meta = _build_file_meta(file_path)