This commit is contained in:
thsrite
2023-10-09 09:37:16 +08:00
parent d9aa281ce1
commit 8bbd4dc913

View File

@ -87,6 +87,8 @@ class DirMonitor(_PluginBase):
_exclude_keywords = "" _exclude_keywords = ""
# 存储源目录与目的目录关系 # 存储源目录与目的目录关系
_dirconf: Dict[str, Path] = {} _dirconf: Dict[str, Path] = {}
# 存储源目录转移方式
_transferconf: Dict[str, str] = {}
_medias = {} _medias = {}
# 退出事件 # 退出事件
_event = Event() _event = Event()
@ -98,6 +100,7 @@ class DirMonitor(_PluginBase):
self.tmdbchain = TmdbChain(self.db) self.tmdbchain = TmdbChain(self.db)
# 清空配置 # 清空配置
self._dirconf = {} self._dirconf = {}
self._transferconf = {}
# 读取配置 # 读取配置
if config: if config:
@ -132,12 +135,17 @@ class DirMonitor(_PluginBase):
paths = [mon_path] paths = [mon_path]
else: else:
paths = mon_path.split(":") paths = mon_path.split(":")
target_path = None target_path = None
if len(paths) > 1: if len(paths) > 1:
mon_path = paths[0] mon_path = paths[0]
target_path = Path(paths[1]) target_path = Path(paths[1])
self._dirconf[mon_path] = target_path self._dirconf[mon_path] = target_path
# 自定义转移方式
if len(paths) == 3:
self._transferconf[mon_path] = paths[2]
# 检查媒体库目录是不是下载目录的子目录 # 检查媒体库目录是不是下载目录的子目录
try: try:
if target_path.is_relative_to(Path(mon_path)): if target_path.is_relative_to(Path(mon_path)):
@ -247,6 +255,8 @@ class DirMonitor(_PluginBase):
# 查询转移目的目录 # 查询转移目的目录
target: Path = self._dirconf.get(mon_path) target: Path = self._dirconf.get(mon_path)
# 查询转移方式
transfer_type = self._transferconf.get(mon_path) or self._transfer_type
# 识别媒体信息 # 识别媒体信息
mediainfo: MediaInfo = self.chain.recognize_media(meta=file_meta) mediainfo: MediaInfo = self.chain.recognize_media(meta=file_meta)
@ -260,7 +270,7 @@ class DirMonitor(_PluginBase):
# 新增转移成功历史记录 # 新增转移成功历史记录
self.transferhis.add_fail( self.transferhis.add_fail(
src_path=file_path, src_path=file_path,
mode=self._transfer_type, mode=transfer_type,
meta=file_meta meta=file_meta
) )
return return
@ -289,7 +299,7 @@ class DirMonitor(_PluginBase):
# 转移 # 转移
transferinfo: TransferInfo = self.chain.transfer(mediainfo=mediainfo, transferinfo: TransferInfo = self.chain.transfer(mediainfo=mediainfo,
path=file_path, path=file_path,
transfer_type=self._transfer_type, transfer_type=transfer_type,
target=target, target=target,
meta=file_meta, meta=file_meta,
episodes_info=episodes_info) episodes_info=episodes_info)
@ -303,7 +313,7 @@ class DirMonitor(_PluginBase):
# 新增转移失败历史记录 # 新增转移失败历史记录
self.transferhis.add_fail( self.transferhis.add_fail(
src_path=file_path, src_path=file_path,
mode=self._transfer_type, mode=transfer_type,
download_hash=download_hash, download_hash=download_hash,
meta=file_meta, meta=file_meta,
mediainfo=mediainfo, mediainfo=mediainfo,
@ -320,7 +330,7 @@ class DirMonitor(_PluginBase):
# 新增转移成功历史记录 # 新增转移成功历史记录
self.transferhis.add_success( self.transferhis.add_success(
src_path=file_path, src_path=file_path,
mode=self._transfer_type, mode=transfer_type,
download_hash=download_hash, download_hash=download_hash,
meta=file_meta, meta=file_meta,
mediainfo=mediainfo, mediainfo=mediainfo,
@ -402,7 +412,7 @@ class DirMonitor(_PluginBase):
}) })
# 移动模式删除空目录 # 移动模式删除空目录
if self._transfer_type == "move": if transfer_type == "move":
for file_dir in file_path.parents: for file_dir in file_path.parents:
if len(str(file_dir)) <= len(str(Path(mon_path))): if len(str(file_dir)) <= len(str(Path(mon_path))):
# 重要,删除到监控目录为止 # 重要,删除到监控目录为止
@ -601,9 +611,10 @@ class DirMonitor(_PluginBase):
'model': 'monitor_dirs', 'model': 'monitor_dirs',
'label': '监控目录', 'label': '监控目录',
'rows': 5, 'rows': 5,
'placeholder': '每一行一个目录,支持种配置方式:\n' 'placeholder': '每一行一个目录,支持种配置方式:\n'
'监控目录\n' '监控目录\n'
'监控目录:转移目的目录(需同时在媒体库目录中配置该目的目录)' '监控目录:转移目的目录(需同时在媒体库目录中配置该目的目录)\n'
'监控目录:转移目的目录:转移方式move|copy|link|softlink'
} }
} }
] ]