From 1cbcd2eae728ae2d6c5f06f012d29e32b0e283d2 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 20 Feb 2024 14:45:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=9B=AE=E5=BD=95=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E8=93=9D=E5=85=89=E5=8E=9F=E7=9B=98=E6=95=B4?= =?UTF-8?q?=E7=90=86=20&&=20=E4=B8=8B=E8=BD=BD=E8=AF=86=E5=88=AB=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/dirmonitor/__init__.py | 51 +++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 48de41f..e9cbd63 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "DirMonitor": { "name": "目录监控", "description": "监控目录文件发生变化时实时整理到媒体库。", - "version": "1.5", + "version": "1.6", "icon": "directory.png", "author": "jxxghp", "level": 1 diff --git a/plugins/dirmonitor/__init__.py b/plugins/dirmonitor/__init__.py index 6ad6130..2a4bba4 100644 --- a/plugins/dirmonitor/__init__.py +++ b/plugins/dirmonitor/__init__.py @@ -59,7 +59,7 @@ class DirMonitor(_PluginBase): # 插件图标 plugin_icon = "directory.png" # 插件版本 - plugin_version = "1.5" + plugin_version = "1.6" # 插件作者 plugin_author = "jxxghp" # 作者主页 @@ -339,14 +339,17 @@ class DirMonitor(_PluginBase): return # 判断是不是蓝光目录 + bluray_flag = False if re.search(r"BDMV[/\\]STREAM", event_path, re.IGNORECASE): + bluray_flag = True # 截取BDMV前面的路径 - event_path = event_path[:event_path.find("BDMV")] - file_path = Path(event_path) + blurray_dir = event_path[:event_path.find("BDMV")] + file_path = Path(blurray_dir) + logger.info(f"{event_path} 是蓝光目录,更正文件路径为:{str(file_path)}") # 查询历史记录,已转移的不处理 - if self.transferhis.get_by_src(event_path): - logger.info(f"{event_path} 已整理过") + if self.transferhis.get_by_src(str(file_path)): + logger.info(f"{file_path} 已整理过") return # 元数据 @@ -357,15 +360,25 @@ class DirMonitor(_PluginBase): # 判断文件大小 if self._size and float(self._size) > 0 and file_path.stat().st_size < float(self._size) * 1024 ** 3: - logger.info(f"{event_path} 文件大小小于监控文件大小,不处理") + logger.info(f"{file_path} 文件大小小于监控文件大小,不处理") return # 查询转移目的目录 target: Path = self._dirconf.get(mon_path) # 查询转移方式 transfer_type = self._transferconf.get(mon_path) + # 根据父路径获取下载历史 - download_history = self.downloadhis.get_by_path(Path(event_path).parent) + download_history = None + if bluray_flag: + # 蓝光原盘,按目录名查询 + # FIXME 理论上DownloadHistory表中的path应该是全路径,但实际表中登记的数据只有目录名,暂按目录名查询 + download_history = self.downloadhis.get_by_path(file_path.name) + else: + # 按文件全路径查询 + download_file = self.downloadhis.get_file_by_fullpath(str(file_path)) + if download_file: + download_history = self.downloadhis.get_by_hash(download_file.download_hash) # 识别媒体信息 mediainfo: MediaInfo = self.chain.recognize_media(meta=file_meta, @@ -404,8 +417,10 @@ class DirMonitor(_PluginBase): else: episodes_info = None - # 获取downloadhash - download_hash = self.get_download_hash(src=str(file_path)) + # 获取下载Hash + download_hash = None + if download_history: + download_hash = download_history.download_hash # 转移 transferinfo: TransferInfo = self.chain.transfer(mediainfo=mediainfo, @@ -418,6 +433,7 @@ class DirMonitor(_PluginBase): if not transferinfo: logger.error("文件转移模块运行失败") return + if not transferinfo.success: # 转移失败 logger.warn(f"{file_path.name} 入库失败:{transferinfo.message}") @@ -477,12 +493,12 @@ class DirMonitor(_PluginBase): if media_files: file_exists = False for file in media_files: - if str(event_path) == file.get("path"): + if str(file_path) == file.get("path"): file_exists = True break if not file_exists: media_files.append({ - "path": event_path, + "path": str(file_path), "mediainfo": mediainfo, "file_meta": file_meta, "transferinfo": transferinfo @@ -490,7 +506,7 @@ class DirMonitor(_PluginBase): else: media_files = [ { - "path": event_path, + "path": str(file_path), "mediainfo": mediainfo, "file_meta": file_meta, "transferinfo": transferinfo @@ -504,7 +520,7 @@ class DirMonitor(_PluginBase): media_list = { "files": [ { - "path": event_path, + "path": str(file_path), "mediainfo": mediainfo, "file_meta": file_meta, "transferinfo": transferinfo @@ -599,15 +615,6 @@ class DirMonitor(_PluginBase): del self._medias[medis_title_year_season] continue - def get_download_hash(self, src: str): - """ - 从表中获取download_hash,避免连接下载器 - """ - download_file = self.downloadhis.get_file_by_fullpath(src) - if download_file: - return download_file.download_hash - return None - def get_state(self) -> bool: return self._enabled