mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-08 00:46:57 +08:00
fix 手动整理Bug
This commit is contained in:
@@ -252,10 +252,10 @@ class DownloadChain(ChainBase):
|
|||||||
# 下载目录
|
# 下载目录
|
||||||
if save_path:
|
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:
|
else:
|
||||||
# 根据媒体信息查询下载目录配置
|
# 根据媒体信息查询下载目录配置
|
||||||
dir_info = self.directoryhelper.get_dir(_media, local=True)
|
dir_info = self.directoryhelper.get_dir(_media)
|
||||||
|
|
||||||
# 拼装子目录
|
# 拼装子目录
|
||||||
if dir_info:
|
if dir_info:
|
||||||
|
|||||||
@@ -385,11 +385,13 @@ class TransferChain(ChainBase):
|
|||||||
# 查询整理目标目录
|
# 查询整理目标目录
|
||||||
if not target_directory:
|
if not target_directory:
|
||||||
if target_path:
|
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:
|
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:
|
else:
|
||||||
target_directory = self.directoryhelper.get_dir(mediainfo)
|
target_directory = self.directoryhelper.get_dir(file_mediainfo)
|
||||||
|
|
||||||
# 执行整理
|
# 执行整理
|
||||||
transferinfo: TransferInfo = self.transfer(fileitem=file_item,
|
transferinfo: TransferInfo = self.transfer(fileitem=file_item,
|
||||||
|
|||||||
+10
-6
@@ -48,15 +48,16 @@ class DirectoryHelper:
|
|||||||
"""
|
"""
|
||||||
return [d for d in self.get_library_dirs() if d.library_storage == "local"]
|
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,
|
def get_dir(self, media: MediaInfo, storage: str = "local",
|
||||||
fileitem: schemas.FileItem = None, local: bool = False) -> Optional[schemas.TransferDirectoryConf]:
|
src_path: Path = None, dest_path: Path = None, fileitem: schemas.FileItem = None
|
||||||
|
) -> Optional[schemas.TransferDirectoryConf]:
|
||||||
"""
|
"""
|
||||||
根据媒体信息获取下载目录、媒体库目录配置
|
根据媒体信息获取下载目录、媒体库目录配置
|
||||||
:param media: 媒体信息
|
:param media: 媒体信息
|
||||||
|
:param storage: 存储类型
|
||||||
:param src_path: 源目录,有值时直接匹配
|
:param src_path: 源目录,有值时直接匹配
|
||||||
:param dest_path: 目标目录,有值时直接匹配
|
:param dest_path: 目标目录,有值时直接匹配
|
||||||
:param fileitem: 文件项,使用文件路径匹配
|
:param fileitem: 文件项,使用文件路径匹配
|
||||||
:param local: 是否本地目录
|
|
||||||
"""
|
"""
|
||||||
# 处理类型
|
# 处理类型
|
||||||
if not media:
|
if not media:
|
||||||
@@ -66,6 +67,12 @@ class DirectoryHelper:
|
|||||||
dirs = self.get_dirs()
|
dirs = self.get_dirs()
|
||||||
# 按照配置顺序查找
|
# 按照配置顺序查找
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
|
# 没有启用整理的目录
|
||||||
|
if not d.monitor_type:
|
||||||
|
continue
|
||||||
|
# 存储类型不匹配
|
||||||
|
if storage and d.storage != storage:
|
||||||
|
continue
|
||||||
# 下载目录
|
# 下载目录
|
||||||
download_path = Path(d.download_path)
|
download_path = Path(d.download_path)
|
||||||
# 媒体库目录
|
# 媒体库目录
|
||||||
@@ -79,9 +86,6 @@ class DirectoryHelper:
|
|||||||
# 有目标目录时,目标目录不匹配媒体库目录
|
# 有目标目录时,目标目录不匹配媒体库目录
|
||||||
if dest_path and not dest_path.is_relative_to(library_path):
|
if dest_path and not dest_path.is_relative_to(library_path):
|
||||||
continue
|
continue
|
||||||
# 本地目录
|
|
||||||
if local and d.storage != "local":
|
|
||||||
continue
|
|
||||||
# 目录类型为全部的,符合条件
|
# 目录类型为全部的,符合条件
|
||||||
if not d.media_type:
|
if not d.media_type:
|
||||||
return d
|
return d
|
||||||
|
|||||||
@@ -357,6 +357,11 @@ class FileManagerModule(_ModuleBase):
|
|||||||
# 整理方式
|
# 整理方式
|
||||||
if not transfer_type:
|
if not transfer_type:
|
||||||
transfer_type = target_directory.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:
|
if scrape is None:
|
||||||
need_scrape = target_directory.scraping
|
need_scrape = target_directory.scraping
|
||||||
@@ -465,6 +470,8 @@ class FileManagerModule(_ModuleBase):
|
|||||||
state = source_oper.link(fileitem, target_file)
|
state = source_oper.link(fileitem, target_file)
|
||||||
elif transfer_type == "softlink":
|
elif transfer_type == "softlink":
|
||||||
state = source_oper.softlink(fileitem, target_file)
|
state = source_oper.softlink(fileitem, target_file)
|
||||||
|
else:
|
||||||
|
return None, f"不支持的整理方式:{transfer_type}"
|
||||||
if state:
|
if state:
|
||||||
return __get_targetitem(target_file), ""
|
return __get_targetitem(target_file), ""
|
||||||
else:
|
else:
|
||||||
@@ -616,18 +623,16 @@ class FileManagerModule(_ModuleBase):
|
|||||||
if not parent_item:
|
if not parent_item:
|
||||||
return False, f"{org_path} 上级目录获取失败"
|
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:
|
if len(file_list) == 0:
|
||||||
logger.debug(f"{parent_item.path} 目录下没有找到字幕文件...")
|
logger.info(f"{parent_item.path} 目录下没有找到字幕文件...")
|
||||||
else:
|
else:
|
||||||
logger.debug("字幕文件清单:" + str(file_list))
|
logger.info(f"字幕文件清单:{[f.name for f in file_list]}")
|
||||||
# 识别文件名
|
# 识别文件名
|
||||||
metainfo = MetaInfoPath(org_path)
|
metainfo = MetaInfoPath(org_path)
|
||||||
for sub_item in file_list:
|
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,
|
sub_file_name = re.sub(_zhtw_sub_re,
|
||||||
".",
|
".",
|
||||||
|
|||||||
+1
-1
@@ -384,7 +384,7 @@ class Monitor(metaclass=Singleton):
|
|||||||
return
|
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:
|
if not dir_info:
|
||||||
logger.warn(f"{event_path.name} 未找到对应的目标目录")
|
logger.warn(f"{event_path.name} 未找到对应的目标目录")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user