fix #628
This commit is contained in:
parent
bcb1fc1600
commit
f74ffed3ae
@ -300,7 +300,7 @@ class TransferChain(ChainBase):
|
|||||||
if not transferinfo:
|
if not transferinfo:
|
||||||
logger.error("文件转移模块运行失败")
|
logger.error("文件转移模块运行失败")
|
||||||
return False, "文件转移模块运行失败"
|
return False, "文件转移模块运行失败"
|
||||||
if not transferinfo.target_path:
|
if not transferinfo.success:
|
||||||
# 转移失败
|
# 转移失败
|
||||||
logger.warn(f"{file_path.name} 入库失败:{transferinfo.message}")
|
logger.warn(f"{file_path.name} 入库失败:{transferinfo.message}")
|
||||||
err_msgs.append(f"{file_path.name} {transferinfo.message}")
|
err_msgs.append(f"{file_path.name} {transferinfo.message}")
|
||||||
@ -490,6 +490,7 @@ class TransferChain(ChainBase):
|
|||||||
src_path = Path(history.src)
|
src_path = Path(history.src)
|
||||||
if not src_path.exists():
|
if not src_path.exists():
|
||||||
return False, f"源目录不存在:{src_path}"
|
return False, f"源目录不存在:{src_path}"
|
||||||
|
dest_path = Path(history.dest) if history.dest else None
|
||||||
# 查询媒体信息
|
# 查询媒体信息
|
||||||
mediainfo = self.recognize_media(mtype=mtype, tmdbid=tmdbid)
|
mediainfo = self.recognize_media(mtype=mtype, tmdbid=tmdbid)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
@ -507,6 +508,7 @@ class TransferChain(ChainBase):
|
|||||||
state, errmsg = self.do_transfer(path=src_path,
|
state, errmsg = self.do_transfer(path=src_path,
|
||||||
mediainfo=mediainfo,
|
mediainfo=mediainfo,
|
||||||
download_hash=history.download_hash,
|
download_hash=history.download_hash,
|
||||||
|
target=dest_path,
|
||||||
force=True)
|
force=True)
|
||||||
if not state:
|
if not state:
|
||||||
return False, errmsg
|
return False, errmsg
|
||||||
|
@ -43,9 +43,13 @@ class FileTransferModule(_ModuleBase):
|
|||||||
# 获取目标路径
|
# 获取目标路径
|
||||||
if not target:
|
if not target:
|
||||||
target = self.get_target_path(in_path=path)
|
target = self.get_target_path(in_path=path)
|
||||||
|
else:
|
||||||
|
target = self.get_library_path(target)
|
||||||
if not target:
|
if not target:
|
||||||
logger.error("未找到媒体库目录,无法转移文件")
|
logger.error("未找到媒体库目录,无法转移文件")
|
||||||
return TransferInfo(message="未找到媒体库目录,无法转移文件")
|
return TransferInfo(success=False,
|
||||||
|
path=path,
|
||||||
|
message="未找到媒体库目录,无法转移文件")
|
||||||
# 转移
|
# 转移
|
||||||
return self.transfer_media(in_path=path,
|
return self.transfer_media(in_path=path,
|
||||||
in_meta=meta,
|
in_meta=meta,
|
||||||
@ -316,9 +320,11 @@ class FileTransferModule(_ModuleBase):
|
|||||||
over_flag=over_flag)
|
over_flag=over_flag)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_library_dir(mediainfo: MediaInfo, target_dir: Path) -> Path:
|
def __get_dest_dir(mediainfo: MediaInfo, target_dir: Path) -> Path:
|
||||||
"""
|
"""
|
||||||
根据设置并装媒体库目录
|
根据设置并装媒体库目录
|
||||||
|
:param mediainfo: 媒体信息
|
||||||
|
:target_dir: 媒体库根目录
|
||||||
"""
|
"""
|
||||||
if mediainfo.type == MediaType.MOVIE:
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
# 电影
|
# 电影
|
||||||
@ -355,19 +361,23 @@ class FileTransferModule(_ModuleBase):
|
|||||||
:param in_path: 转移的路径,可能是一个文件也可以是一个目录
|
:param in_path: 转移的路径,可能是一个文件也可以是一个目录
|
||||||
:param in_meta:预识别元数据
|
:param in_meta:预识别元数据
|
||||||
:param mediainfo: 媒体信息
|
:param mediainfo: 媒体信息
|
||||||
:param target_dir: 目的文件夹,非空的转移到该文件夹,为空时则按类型转移到配置文件中的媒体库文件夹
|
:param target_dir: 媒体库根目录
|
||||||
:param transfer_type: 文件转移方式
|
:param transfer_type: 文件转移方式
|
||||||
:return: TransferInfo、错误信息
|
:return: TransferInfo、错误信息
|
||||||
"""
|
"""
|
||||||
# 检查目录路径
|
# 检查目录路径
|
||||||
if not in_path.exists():
|
if not in_path.exists():
|
||||||
return TransferInfo(message=f"{in_path} 路径不存在")
|
return TransferInfo(success=False,
|
||||||
|
path=in_path,
|
||||||
|
message=f"{in_path} 路径不存在")
|
||||||
|
|
||||||
if not target_dir.exists():
|
if not target_dir.exists():
|
||||||
return TransferInfo(message=f"{target_dir} 目标路径不存在")
|
return TransferInfo(success=False,
|
||||||
|
path=in_path,
|
||||||
|
message=f"{target_dir} 目标路径不存在")
|
||||||
|
|
||||||
# 媒体库目录
|
# 媒体库目的目录
|
||||||
target_dir = self.__get_library_dir(mediainfo=mediainfo, target_dir=target_dir)
|
target_dir = self.__get_dest_dir(mediainfo=mediainfo, target_dir=target_dir)
|
||||||
|
|
||||||
# 重命名格式
|
# 重命名格式
|
||||||
rename_format = settings.TV_RENAME_FORMAT \
|
rename_format = settings.TV_RENAME_FORMAT \
|
||||||
@ -393,11 +403,16 @@ class FileTransferModule(_ModuleBase):
|
|||||||
transfer_type=transfer_type)
|
transfer_type=transfer_type)
|
||||||
if retcode != 0:
|
if retcode != 0:
|
||||||
logger.error(f"文件夹 {in_path} 转移失败,错误码:{retcode}")
|
logger.error(f"文件夹 {in_path} 转移失败,错误码:{retcode}")
|
||||||
return TransferInfo(message=f"文件夹 {in_path} 转移失败,错误码:{retcode}")
|
return TransferInfo(success=False,
|
||||||
|
message=f"文件夹 {in_path} 转移失败,错误码:{retcode}",
|
||||||
|
path=in_path,
|
||||||
|
target_path=new_path,
|
||||||
|
is_bluray=bluray_flag)
|
||||||
|
|
||||||
logger.info(f"文件夹 {in_path} 转移成功")
|
logger.info(f"文件夹 {in_path} 转移成功")
|
||||||
# 返回转移后的路径
|
# 返回转移后的路径
|
||||||
return TransferInfo(path=in_path,
|
return TransferInfo(success=True,
|
||||||
|
path=in_path,
|
||||||
target_path=new_path,
|
target_path=new_path,
|
||||||
total_size=new_path.stat().st_size,
|
total_size=new_path.stat().st_size,
|
||||||
is_bluray=bluray_flag)
|
is_bluray=bluray_flag)
|
||||||
@ -440,11 +455,15 @@ class FileTransferModule(_ModuleBase):
|
|||||||
over_flag=overflag)
|
over_flag=overflag)
|
||||||
if retcode != 0:
|
if retcode != 0:
|
||||||
logger.error(f"文件 {in_path} 转移失败,错误码:{retcode}")
|
logger.error(f"文件 {in_path} 转移失败,错误码:{retcode}")
|
||||||
return TransferInfo(message=f"文件 {in_path.name} 转移失败,错误码:{retcode}",
|
return TransferInfo(success=False,
|
||||||
|
message=f"文件 {in_path.name} 转移失败,错误码:{retcode}",
|
||||||
|
path=in_path,
|
||||||
|
target_path=new_file,
|
||||||
fail_list=[str(in_path)])
|
fail_list=[str(in_path)])
|
||||||
|
|
||||||
logger.info(f"文件 {in_path} 转移成功")
|
logger.info(f"文件 {in_path} 转移成功")
|
||||||
return TransferInfo(path=in_path,
|
return TransferInfo(success=True,
|
||||||
|
path=in_path,
|
||||||
target_path=new_file,
|
target_path=new_file,
|
||||||
file_count=1,
|
file_count=1,
|
||||||
total_size=new_file.stat().st_size,
|
total_size=new_file.stat().st_size,
|
||||||
@ -514,6 +533,28 @@ class FileTransferModule(_ModuleBase):
|
|||||||
else:
|
else:
|
||||||
return Path(render_str)
|
return Path(render_str)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_library_path(path: Path):
|
||||||
|
"""
|
||||||
|
根据目录查询其所在的媒体库目录
|
||||||
|
"""
|
||||||
|
if not path:
|
||||||
|
return None
|
||||||
|
if not settings.LIBRARY_PATHS:
|
||||||
|
return None
|
||||||
|
# 目的路径,多路径以,分隔
|
||||||
|
dest_paths = settings.LIBRARY_PATHS
|
||||||
|
if len(dest_paths) == 1:
|
||||||
|
return dest_paths[0]
|
||||||
|
for libpath in dest_paths:
|
||||||
|
try:
|
||||||
|
if path.is_relative_to(libpath):
|
||||||
|
return libpath
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"计算媒体库路径时出错:{e}")
|
||||||
|
continue
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_target_path(in_path: Path = None) -> Optional[Path]:
|
def get_target_path(in_path: Path = None) -> Optional[Path]:
|
||||||
"""
|
"""
|
||||||
@ -533,7 +574,7 @@ class FileTransferModule(_ModuleBase):
|
|||||||
if in_path:
|
if in_path:
|
||||||
for path in dest_paths:
|
for path in dest_paths:
|
||||||
try:
|
try:
|
||||||
relative = Path(in_path).relative_to(path).as_posix()
|
relative = in_path.relative_to(path).as_posix()
|
||||||
if len(relative) > max_length:
|
if len(relative) > max_length:
|
||||||
max_length = len(relative)
|
max_length = len(relative)
|
||||||
target_path = path
|
target_path = path
|
||||||
@ -569,7 +610,7 @@ class FileTransferModule(_ModuleBase):
|
|||||||
if not target_dir:
|
if not target_dir:
|
||||||
continue
|
continue
|
||||||
# 媒体分类路径
|
# 媒体分类路径
|
||||||
target_dir = self.__get_library_dir(mediainfo=mediainfo, target_dir=target_dir)
|
target_dir = self.__get_dest_dir(mediainfo=mediainfo, target_dir=target_dir)
|
||||||
# 重命名格式
|
# 重命名格式
|
||||||
rename_format = settings.TV_RENAME_FORMAT \
|
rename_format = settings.TV_RENAME_FORMAT \
|
||||||
if mediainfo.type == MediaType.TV else settings.MOVIE_RENAME_FORMAT
|
if mediainfo.type == MediaType.TV else settings.MOVIE_RENAME_FORMAT
|
||||||
|
@ -292,7 +292,7 @@ class DirMonitor(_PluginBase):
|
|||||||
if not transferinfo:
|
if not transferinfo:
|
||||||
logger.error("文件转移模块运行失败")
|
logger.error("文件转移模块运行失败")
|
||||||
return
|
return
|
||||||
if not transferinfo.target_path:
|
if not transferinfo.success:
|
||||||
# 转移失败
|
# 转移失败
|
||||||
logger.warn(f"{file_path.name} 入库失败:{transferinfo.message}")
|
logger.warn(f"{file_path.name} 入库失败:{transferinfo.message}")
|
||||||
# 新增转移失败历史记录
|
# 新增转移失败历史记录
|
||||||
|
@ -35,6 +35,8 @@ class TransferInfo(BaseModel):
|
|||||||
"""
|
"""
|
||||||
文件转移结果信息
|
文件转移结果信息
|
||||||
"""
|
"""
|
||||||
|
# 是否成功标志
|
||||||
|
success: bool = True
|
||||||
# 转移⼁路径
|
# 转移⼁路径
|
||||||
path: Optional[Path] = None
|
path: Optional[Path] = None
|
||||||
# 转移后路径
|
# 转移后路径
|
||||||
|
Loading…
x
Reference in New Issue
Block a user