From c12e2bdba799d68fb94d0ee6cb39340aa57eb991 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 14 Nov 2024 08:04:52 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=89=8B=E5=8A=A8=E6=95=B4=E7=90=86Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/download.py | 4 ++-- app/chain/transfer.py | 8 +++++--- app/helper/directory.py | 16 ++++++++++------ app/modules/filemanager/__init__.py | 19 ++++++++++++------- app/monitor.py | 2 +- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/app/chain/download.py b/app/chain/download.py index 1f242789..b10bb56b 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -252,10 +252,10 @@ class DownloadChain(ChainBase): # 下载目录 if save_path: # 有自定义下载目录时,尝试匹配目录配置 - dir_info = self.directoryhelper.get_dir(_media, src_path=Path(save_path), local=True) + dir_info = self.directoryhelper.get_dir(_media, src_path=Path(save_path)) else: # 根据媒体信息查询下载目录配置 - dir_info = self.directoryhelper.get_dir(_media, local=True) + dir_info = self.directoryhelper.get_dir(_media) # 拼装子目录 if dir_info: diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 2baad3e7..d21bdde6 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -385,11 +385,13 @@ class TransferChain(ChainBase): # 查询整理目标目录 if not target_directory: if target_path: - target_directory = self.directoryhelper.get_dir(mediainfo, dest_path=target_path) + target_directory = self.directoryhelper.get_dir(file_mediainfo, + storage=target_storage, dest_path=target_path) elif src_match: - target_directory = self.directoryhelper.get_dir(mediainfo, src_path=file_path) + target_directory = self.directoryhelper.get_dir(file_mediainfo, + storage=file_item.storage, src_path=file_path) else: - target_directory = self.directoryhelper.get_dir(mediainfo) + target_directory = self.directoryhelper.get_dir(file_mediainfo) # 执行整理 transferinfo: TransferInfo = self.transfer(fileitem=file_item, diff --git a/app/helper/directory.py b/app/helper/directory.py index 2d59f848..1f9389a7 100644 --- a/app/helper/directory.py +++ b/app/helper/directory.py @@ -48,15 +48,16 @@ class DirectoryHelper: """ return [d for d in self.get_library_dirs() if d.library_storage == "local"] - def get_dir(self, media: MediaInfo, src_path: Path = None, dest_path: Path = None, - fileitem: schemas.FileItem = None, local: bool = False) -> Optional[schemas.TransferDirectoryConf]: + def get_dir(self, media: MediaInfo, storage: str = "local", + src_path: Path = None, dest_path: Path = None, fileitem: schemas.FileItem = None + ) -> Optional[schemas.TransferDirectoryConf]: """ 根据媒体信息获取下载目录、媒体库目录配置 :param media: 媒体信息 + :param storage: 存储类型 :param src_path: 源目录,有值时直接匹配 :param dest_path: 目标目录,有值时直接匹配 :param fileitem: 文件项,使用文件路径匹配 - :param local: 是否本地目录 """ # 处理类型 if not media: @@ -66,6 +67,12 @@ class DirectoryHelper: dirs = self.get_dirs() # 按照配置顺序查找 for d in dirs: + # 没有启用整理的目录 + if not d.monitor_type: + continue + # 存储类型不匹配 + if storage and d.storage != storage: + continue # 下载目录 download_path = Path(d.download_path) # 媒体库目录 @@ -79,9 +86,6 @@ class DirectoryHelper: # 有目标目录时,目标目录不匹配媒体库目录 if dest_path and not dest_path.is_relative_to(library_path): continue - # 本地目录 - if local and d.storage != "local": - continue # 目录类型为全部的,符合条件 if not d.media_type: return d diff --git a/app/modules/filemanager/__init__.py b/app/modules/filemanager/__init__.py index ea551880..e0d98a7b 100644 --- a/app/modules/filemanager/__init__.py +++ b/app/modules/filemanager/__init__.py @@ -357,6 +357,11 @@ class FileManagerModule(_ModuleBase): # 整理方式 if not transfer_type: transfer_type = target_directory.transfer_type + if not transfer_type: + logger.error(f"{target_directory.name} 未设置整理方式") + return TransferInfo(success=False, + fileitem=fileitem, + message=f"{target_directory.name} 未设置整理方式") # 是否需要刮削 if scrape is None: need_scrape = target_directory.scraping @@ -465,6 +470,8 @@ class FileManagerModule(_ModuleBase): state = source_oper.link(fileitem, target_file) elif transfer_type == "softlink": state = source_oper.softlink(fileitem, target_file) + else: + return None, f"不支持的整理方式:{transfer_type}" if state: return __get_targetitem(target_file), "" else: @@ -616,18 +623,16 @@ class FileManagerModule(_ModuleBase): if not parent_item: return False, f"{org_path} 上级目录获取失败" # 字幕文件列表 - file_list: List[FileItem] = storage_oper.list(parent_item) + file_list: List[FileItem] = storage_oper.list(parent_item) or [] + file_list = [f for f in file_list if f.type == "file" and f.extension + and f".{f.extension.lower()}" in settings.RMT_SUBEXT] if len(file_list) == 0: - logger.debug(f"{parent_item.path} 目录下没有找到字幕文件...") + logger.info(f"{parent_item.path} 目录下没有找到字幕文件...") else: - logger.debug("字幕文件清单:" + str(file_list)) + logger.info(f"字幕文件清单:{[f.name for f in file_list]}") # 识别文件名 metainfo = MetaInfoPath(org_path) for sub_item in file_list: - if sub_item.type == "dir" or not sub_item.extension: - continue - if f".{sub_item.extension.lower()}" not in settings.RMT_SUBEXT: - continue # 识别字幕文件名 sub_file_name = re.sub(_zhtw_sub_re, ".", diff --git a/app/monitor.py b/app/monitor.py index e61673c4..8920c405 100644 --- a/app/monitor.py +++ b/app/monitor.py @@ -384,7 +384,7 @@ class Monitor(metaclass=Singleton): return # 查询转移目的目录 - dir_info = self.directoryhelper.get_dir(mediainfo, src_path=event_path) + dir_info = self.directoryhelper.get_dir(mediainfo, storage=storage, src_path=event_path) if not dir_info: logger.warn(f"{event_path.name} 未找到对应的目标目录") return