From 8bbd4dc913564e3fd7e7282c569296840f6cadc0 Mon Sep 17 00:00:00 2001 From: thsrite Date: Mon, 9 Oct 2023 09:37:16 +0800 Subject: [PATCH 1/3] fix #701 --- app/plugins/dirmonitor/__init__.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/plugins/dirmonitor/__init__.py b/app/plugins/dirmonitor/__init__.py index 377b00ec..7c40c923 100644 --- a/app/plugins/dirmonitor/__init__.py +++ b/app/plugins/dirmonitor/__init__.py @@ -87,6 +87,8 @@ class DirMonitor(_PluginBase): _exclude_keywords = "" # 存储源目录与目的目录关系 _dirconf: Dict[str, Path] = {} + # 存储源目录转移方式 + _transferconf: Dict[str, str] = {} _medias = {} # 退出事件 _event = Event() @@ -98,6 +100,7 @@ class DirMonitor(_PluginBase): self.tmdbchain = TmdbChain(self.db) # 清空配置 self._dirconf = {} + self._transferconf = {} # 读取配置 if config: @@ -132,12 +135,17 @@ class DirMonitor(_PluginBase): paths = [mon_path] else: paths = mon_path.split(":") + target_path = None if len(paths) > 1: mon_path = paths[0] target_path = Path(paths[1]) self._dirconf[mon_path] = target_path + # 自定义转移方式 + if len(paths) == 3: + self._transferconf[mon_path] = paths[2] + # 检查媒体库目录是不是下载目录的子目录 try: if target_path.is_relative_to(Path(mon_path)): @@ -247,6 +255,8 @@ class DirMonitor(_PluginBase): # 查询转移目的目录 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) @@ -260,7 +270,7 @@ class DirMonitor(_PluginBase): # 新增转移成功历史记录 self.transferhis.add_fail( src_path=file_path, - mode=self._transfer_type, + mode=transfer_type, meta=file_meta ) return @@ -289,7 +299,7 @@ class DirMonitor(_PluginBase): # 转移 transferinfo: TransferInfo = self.chain.transfer(mediainfo=mediainfo, path=file_path, - transfer_type=self._transfer_type, + transfer_type=transfer_type, target=target, meta=file_meta, episodes_info=episodes_info) @@ -303,7 +313,7 @@ class DirMonitor(_PluginBase): # 新增转移失败历史记录 self.transferhis.add_fail( src_path=file_path, - mode=self._transfer_type, + mode=transfer_type, download_hash=download_hash, meta=file_meta, mediainfo=mediainfo, @@ -320,7 +330,7 @@ class DirMonitor(_PluginBase): # 新增转移成功历史记录 self.transferhis.add_success( src_path=file_path, - mode=self._transfer_type, + mode=transfer_type, download_hash=download_hash, meta=file_meta, 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: if len(str(file_dir)) <= len(str(Path(mon_path))): # 重要,删除到监控目录为止 @@ -601,9 +611,10 @@ class DirMonitor(_PluginBase): 'model': 'monitor_dirs', 'label': '监控目录', 'rows': 5, - 'placeholder': '每一行一个目录,支持两种配置方式:\n' + 'placeholder': '每一行一个目录,支持三种配置方式:\n' '监控目录\n' - '监控目录:转移目的目录(需同时在媒体库目录中配置该目的目录)' + '监控目录:转移目的目录(需同时在媒体库目录中配置该目的目录)\n' + '监控目录:转移目的目录:转移方式(move|copy|link|softlink)' } } ] From 0159b02916b426a6c3cae2bdd5d107c084d7a58c Mon Sep 17 00:00:00 2001 From: thsrite Date: Mon, 9 Oct 2023 09:50:30 +0800 Subject: [PATCH 2/3] fix 8bbd4dc9 --- app/plugins/dirmonitor/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/plugins/dirmonitor/__init__.py b/app/plugins/dirmonitor/__init__.py index 7c40c923..c162e9e8 100644 --- a/app/plugins/dirmonitor/__init__.py +++ b/app/plugins/dirmonitor/__init__.py @@ -136,16 +136,18 @@ class DirMonitor(_PluginBase): else: paths = mon_path.split(":") + # 自定义转移方式 + if mon_path.count("#") == 2: + self._transferconf[mon_path] = mon_path.split("#")[1] + else: + self._transferconf[mon_path] = self._transfer_type + target_path = None if len(paths) > 1: mon_path = paths[0] target_path = Path(paths[1]) self._dirconf[mon_path] = target_path - # 自定义转移方式 - if len(paths) == 3: - self._transferconf[mon_path] = paths[2] - # 检查媒体库目录是不是下载目录的子目录 try: if target_path.is_relative_to(Path(mon_path)): @@ -256,7 +258,7 @@ class DirMonitor(_PluginBase): # 查询转移目的目录 target: Path = self._dirconf.get(mon_path) # 查询转移方式 - transfer_type = self._transferconf.get(mon_path) or self._transfer_type + transfer_type = self._transferconf.get(mon_path) # 识别媒体信息 mediainfo: MediaInfo = self.chain.recognize_media(meta=file_meta) @@ -614,7 +616,7 @@ class DirMonitor(_PluginBase): 'placeholder': '每一行一个目录,支持三种配置方式:\n' '监控目录\n' '监控目录:转移目的目录(需同时在媒体库目录中配置该目的目录)\n' - '监控目录:转移目的目录:转移方式(move|copy|link|softlink)' + '监控目录:转移目的目录#转移方式(move|copy|link|softlink)' } } ] From 6039a9d0d58e1276ff4061e62ebbddd004cf226f Mon Sep 17 00:00:00 2001 From: thsrite Date: Mon, 9 Oct 2023 10:06:04 +0800 Subject: [PATCH 3/3] fix --- app/plugins/dirmonitor/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/plugins/dirmonitor/__init__.py b/app/plugins/dirmonitor/__init__.py index c162e9e8..fff66fbe 100644 --- a/app/plugins/dirmonitor/__init__.py +++ b/app/plugins/dirmonitor/__init__.py @@ -137,7 +137,7 @@ class DirMonitor(_PluginBase): paths = mon_path.split(":") # 自定义转移方式 - if mon_path.count("#") == 2: + if mon_path.count("#") == 1: self._transferconf[mon_path] = mon_path.split("#")[1] else: self._transferconf[mon_path] = self._transfer_type