mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor: unify transfer chain data ports
This commit is contained in:
+10
-10
@@ -23,8 +23,8 @@ from app.chain.media import MediaChain
|
||||
from app.chain.storage import StorageChain
|
||||
from app.chain.subscribe import SubscribeChain
|
||||
from app.application.chain.data import (
|
||||
DownloadHistoryPortProxy as DownloadHistoryOper,
|
||||
TransferHistoryPortProxy as TransferHistoryOper,
|
||||
get_chain_download_history_port,
|
||||
get_chain_transfer_history_port,
|
||||
)
|
||||
from app.application.configuration import (
|
||||
get_chain_runtime_config_snapshot,
|
||||
@@ -417,7 +417,7 @@ class FileFilterMixin:
|
||||
|
||||
@staticmethod
|
||||
def _is_overwrite_declined(task: TransferTask, transferinfo: TransferInfo,
|
||||
transferhis: TransferHistoryOper) -> bool:
|
||||
transferhis: Any) -> bool:
|
||||
"""
|
||||
判断本次未入库是否为「同路径已有成功记录 + 覆盖模式裁定不覆盖」。
|
||||
|
||||
@@ -859,7 +859,7 @@ class HistoryMatchMixin:
|
||||
|
||||
def _resolve_history_from_download_files(
|
||||
self,
|
||||
downloadhis: DownloadHistoryOper,
|
||||
downloadhis: Any,
|
||||
download_files: List[DownloadFiles],
|
||||
file_path: Optional[Path] = None,
|
||||
save_path: Optional[Path] = None,
|
||||
@@ -889,7 +889,7 @@ class HistoryMatchMixin:
|
||||
|
||||
def _resolve_download_history(
|
||||
self,
|
||||
downloadhis: DownloadHistoryOper,
|
||||
downloadhis: Any,
|
||||
file_path: Path,
|
||||
bluray_dir: bool = False,
|
||||
download_hash: Optional[str] = None,
|
||||
@@ -1148,7 +1148,7 @@ class ManualHistoryMixin:
|
||||
def _get_manual_transfer_history(
|
||||
self,
|
||||
fileitem: FileItem,
|
||||
transfer_history_oper: TransferHistoryOper,
|
||||
transfer_history_oper: Any,
|
||||
include_move_dest: bool = False,
|
||||
) -> Optional[TransferHistory]:
|
||||
"""查询文件源路径历史,并兼容从成功移动后的目标现址重新整理。"""
|
||||
@@ -1178,7 +1178,7 @@ class ManualHistoryMixin:
|
||||
:param fileitems: 待查询的文件或目录项
|
||||
:return: 去重后的成功整理记录
|
||||
"""
|
||||
transfer_history_oper = TransferHistoryOper()
|
||||
transfer_history_oper = get_chain_transfer_history_port()
|
||||
histories: Dict[int, TransferHistory] = {}
|
||||
for fileitem in fileitems or []:
|
||||
if not fileitem or not fileitem.path:
|
||||
@@ -1212,7 +1212,7 @@ class ManualHistoryMixin:
|
||||
@staticmethod
|
||||
def _delete_manual_transfer_history(
|
||||
history: TransferHistory,
|
||||
transfer_history_oper: TransferHistoryOper,
|
||||
transfer_history_oper: Any,
|
||||
) -> Tuple[bool, str]:
|
||||
"""删除手动重整历史;非成功移动记录同时清理可能存在的旧目标。"""
|
||||
if (
|
||||
@@ -1385,7 +1385,7 @@ class FailedRetryMixin:
|
||||
)
|
||||
return
|
||||
|
||||
history = TransferHistoryOper().get(history_id)
|
||||
history = get_chain_transfer_history_port().get(history_id)
|
||||
if not history:
|
||||
self.post_message(
|
||||
Message(
|
||||
@@ -1478,7 +1478,7 @@ class FailedRetryMixin:
|
||||
:param media_id: 数据源原生 ID,必须与 media_source 成对提供
|
||||
"""
|
||||
# 查询历史记录
|
||||
history: TransferHistory = TransferHistoryOper().get(logid)
|
||||
history: TransferHistory = get_chain_transfer_history_port().get(logid)
|
||||
if not history:
|
||||
logger.error(f"整理记录不存在,ID:{logid}")
|
||||
return False, "整理记录不存在"
|
||||
|
||||
+11
-11
@@ -23,9 +23,9 @@ from app.domain.meta.metabase import MetaBase
|
||||
from app.domain.meta.metamusic import MetaMusic
|
||||
from app.domain.metainfo import MetaInfoPath
|
||||
from app.application.chain.data import (
|
||||
DownloadHistoryPortProxy as DownloadHistoryOper,
|
||||
TransferPendingPortProxy as TransferPendingOper,
|
||||
TransferHistoryPortProxy as TransferHistoryOper,
|
||||
get_chain_download_history_port,
|
||||
get_chain_transfer_history_port,
|
||||
get_chain_transfer_pending_port,
|
||||
)
|
||||
DownloadHistory = Any
|
||||
from app.application.configuration import get_configured_system_config
|
||||
@@ -142,7 +142,7 @@ class TransferChain(FileFilterMixin, ScrapeBatchMixin, EpisodeFormatMixin, Histo
|
||||
# 整理失败通知聚合器
|
||||
self.failure_notification_aggregator = TransferFailureNotificationAggregator()
|
||||
# 待整理文件落盘登记,用于进程重启后回放内存队列里未完成的任务
|
||||
self._pendingoper = TransferPendingOper()
|
||||
self._pendingoper = get_chain_transfer_pending_port()
|
||||
# 转移成功的文件清单
|
||||
self._success_target_files: Dict[Tuple, List[str]] = {}
|
||||
# 批次级刮削缓冲,避免同一批多文件入库重复触发目录刮削
|
||||
@@ -419,7 +419,7 @@ class TransferChain(FileFilterMixin, ScrapeBatchMixin, EpisodeFormatMixin, Histo
|
||||
username=task.username,
|
||||
)
|
||||
|
||||
transferhis = TransferHistoryOper()
|
||||
transferhis = get_chain_transfer_history_port()
|
||||
target_dir_path = self.__get_transfer_target_dir_path(transferinfo)
|
||||
job_id = self.jobview.get_job_id(task)
|
||||
|
||||
@@ -1265,7 +1265,7 @@ class TransferChain(FileFilterMixin, ScrapeBatchMixin, EpisodeFormatMixin, Histo
|
||||
"""
|
||||
try:
|
||||
# 识别
|
||||
transferhis = TransferHistoryOper()
|
||||
transferhis = get_chain_transfer_history_port()
|
||||
# 显式标注联合:下面既会赋回音乐识别结果(MusicInfo),也会赋回影视识别
|
||||
# 结果(MediaInfo),不标注时会被推断成其中一种,另一种就成了假错误
|
||||
mediainfo: Optional[Union[MediaInfo, MusicInfo]] = task.mediainfo
|
||||
@@ -1647,7 +1647,7 @@ class TransferChain(FileFilterMixin, ScrapeBatchMixin, EpisodeFormatMixin, Histo
|
||||
continue
|
||||
|
||||
# 查询下载记录识别情况
|
||||
downloadhis: DownloadHistory = DownloadHistoryOper().get_by_hash(
|
||||
downloadhis: DownloadHistory = get_chain_download_history_port().get_by_hash(
|
||||
torrent.hash
|
||||
)
|
||||
# 下载记录中的媒体类型作为整理类型来源,无下载记录时留空由文件后缀兜底
|
||||
@@ -2265,7 +2265,7 @@ class TransferChain(FileFilterMixin, ScrapeBatchMixin, EpisodeFormatMixin, Histo
|
||||
def _build_main_meta(
|
||||
main_fileitem: FileItem,
|
||||
main_bluray_dir: bool,
|
||||
download_history_oper: DownloadHistoryOper,
|
||||
download_history_oper: Any,
|
||||
) -> Optional[MetaBase]:
|
||||
"""
|
||||
构建主视频元数据。
|
||||
@@ -2357,7 +2357,7 @@ class TransferChain(FileFilterMixin, ScrapeBatchMixin, EpisodeFormatMixin, Histo
|
||||
if not items:
|
||||
return [], {}
|
||||
|
||||
download_history_oper = DownloadHistoryOper()
|
||||
download_history_oper = get_chain_download_history_port()
|
||||
inherited_map: Dict[Tuple[str, str], MetaBase] = {}
|
||||
main_items_by_dir, extra_items_by_dir = _build_directory_index(items)
|
||||
main_items = [
|
||||
@@ -2557,7 +2557,7 @@ class TransferChain(FileFilterMixin, ScrapeBatchMixin, EpisodeFormatMixin, Histo
|
||||
# 成功但源文件已变化放行交 overwrite_mode 决断);手动整理可清理失败记录,
|
||||
# 或按用户确认清理成功记录。
|
||||
if (not force or reorganize) and not preview:
|
||||
transfer_history_oper = TransferHistoryOper()
|
||||
transfer_history_oper = get_chain_transfer_history_port()
|
||||
transferd = self._get_manual_transfer_history(
|
||||
fileitem=file_item,
|
||||
transfer_history_oper=transfer_history_oper,
|
||||
@@ -2627,7 +2627,7 @@ class TransferChain(FileFilterMixin, ScrapeBatchMixin, EpisodeFormatMixin, Histo
|
||||
continue
|
||||
|
||||
# 提前获取下载历史,以便获取自定义识别词
|
||||
downloadhis = DownloadHistoryOper()
|
||||
downloadhis = get_chain_download_history_port()
|
||||
download_history = self._resolve_download_history(
|
||||
downloadhis=downloadhis,
|
||||
file_path=file_path,
|
||||
|
||||
Reference in New Issue
Block a user